llvm.org GIT mirror llvm / 679d718
Introduce a new ReplaceCallWith method, which simplifies a lot of code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35710 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 12 years ago
1 changed file(s) with 86 addition(s) and 186 deletion(s). Raw diff Collapse all Expand all
125125 /// @brief Get the name of the library call being optimized
126126 const char *getFunctionName() const { return FunctionName; }
127127
128 bool ReplaceCallWith(CallInst *CI, Value *V) {
129 if (!CI->use_empty())
130 CI->replaceAllUsesWith(V);
131 CI->eraseFromParent();
132 return true;
133 }
134
128135 /// @brief Called by SimplifyLibCalls to update the occurrences statistic.
129136 void succeeded() {
130137 #ifndef NDEBUG
486493 return false;
487494
488495 // Handle the simple, do-nothing case
489 if (SrcLength == 0) {
490 CI->replaceAllUsesWith(Dst);
491 CI->eraseFromParent();
492 return true;
493 }
496 if (SrcLength == 0)
497 return ReplaceCallWith(CI, Dst);
494498
495499 // We need to find the end of the destination string. That's where the
496500 // memory is to be moved to. We just generate a call to strlen (further
512516 };
513517 new CallInst(SLC.get_memcpy(), Vals, 4, "", CI);
514518
515 // Finally, substitute the first operand of the strcat call for the
516 // strcat call itself since strcat returns its first operand; and,
517 // kill the strcat CallInst.
518 CI->replaceAllUsesWith(Dst);
519 CI->eraseFromParent();
520 return true;
519 return ReplaceCallWith(CI, Dst);
521520 }
522521 } StrCatOptimizer;
523522
557556 CI->getOperand(2),
558557 ConstantInt::get(SLC.getIntPtrType(), StrLength+1)
559558 };
560 CI->replaceAllUsesWith(new CallInst(SLC.get_memchr(), Args, 3,
561 CI->getName(), CI));
562 CI->eraseFromParent();
563 return true;
559 return ReplaceCallWith(CI, new CallInst(SLC.get_memchr(), Args, 3,
560 CI->getName(), CI));
564561 }
565562
566563 // Get the character we're looking for
569566 if (StrLength == 0) {
570567 // If the length of the string is zero, and we are searching for zero,
571568 // return the input pointer.
572 if (CharValue == 0) {
573 CI->replaceAllUsesWith(CI->getOperand(1));
574 } else {
575 // Otherwise, char wasn't found.
576 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
577 }
578 CI->eraseFromParent();
579 return true;
569 if (CharValue == 0)
570 return ReplaceCallWith(CI, CI->getOperand(1));
571 // Otherwise, char wasn't found.
572 return ReplaceCallWith(CI, Constant::getNullValue(CI->getType()));
580573 }
581574
582575 // Compute the offset
587580 // Did we find our match?
588581 if (C->getSExtValue() == CharValue)
589582 break;
590 if (C->isZero()) {
591 // We found the end of the string. strchr returns null.
592 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
593 CI->eraseFromParent();
594 return true;
595 }
583 if (C->isZero()) // We found the end of the string. strchr returns null.
584 return ReplaceCallWith(CI, Constant::getNullValue(CI->getType()));
596585 }
597586 ++i;
598587 }
603592 Value *GEP = new GetElementPtrInst(CI->getOperand(1), Idx,
604593 CI->getOperand(1)->getName() +
605594 ".strchr", CI);
606 CI->replaceAllUsesWith(GEP);
607 CI->eraseFromParent();
608 return true;
595 return ReplaceCallWith(CI, GEP);
609596 }
610597 } StrChrOptimizer;
611598
633620 // because the call is a no-op.
634621 Value *Str1P = CI->getOperand(1);
635622 Value *Str2P = CI->getOperand(2);
636 if (Str1P == Str2P) {
637 // strcmp(x,x) -> 0
638 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 0));
639 CI->eraseFromParent();
640 return true;
641 }
623 if (Str1P == Str2P) // strcmp(x,x) -> 0
624 return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 0));
642625
643626 uint64_t Str1Len, Str1StartIdx;
644627 ConstantArray *A1;
647630 // strcmp("", x) -> *x
648631 Value *V = new LoadInst(Str2P, CI->getName()+".load", CI);
649632 V = new ZExtInst(V, CI->getType(), CI->getName()+".int", CI);
650 CI->replaceAllUsesWith(V);
651 CI->eraseFromParent();
652 return true;
633 return ReplaceCallWith(CI, V);
653634 }
654635
655636 uint64_t Str2Len, Str2StartIdx;
659640 // strcmp(x,"") -> *x
660641 Value *V = new LoadInst(Str1P, CI->getName()+".load", CI);
661642 V = new ZExtInst(V, CI->getType(), CI->getName()+".int", CI);
662 CI->replaceAllUsesWith(V);
663 CI->eraseFromParent();
664 return true;
643 return ReplaceCallWith(CI, V);
665644 }
666645
667646 if (Str1IsCst && Str2IsCst && A1->isCString() && A2->isCString()) {
669648 std::string S1 = A1->getAsString();
670649 std::string S2 = A2->getAsString();
671650 int R = strcmp(S1.c_str()+Str1StartIdx, S2.c_str()+Str2StartIdx);
672 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), R));
673 CI->eraseFromParent();
674 return true;
651 return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), R));
675652 }
676653 return false;
677654 }
703680 // because the call is a no-op.
704681 Value *Str1P = CI->getOperand(1);
705682 Value *Str2P = CI->getOperand(2);
706 if (Str1P == Str2P) {
707 // strncmp(x,x) -> 0
708 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 0));
709 CI->eraseFromParent();
710 return true;
711 }
683 if (Str1P == Str2P) // strncmp(x,x) -> 0
684 return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 0));
712685
713686 // Check the length argument, if it is Constant zero then the strings are
714687 // considered equal.
720693
721694 if (Length == 0) {
722695 // strncmp(x,y,0) -> 0
723 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), 0));
724 CI->eraseFromParent();
725 return true;
696 return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 0));
726697 }
727698
728699 uint64_t Str1Len, Str1StartIdx;
732703 // strncmp("", x) -> *x
733704 Value *V = new LoadInst(Str2P, CI->getName()+".load", CI);
734705 V = new ZExtInst(V, CI->getType(), CI->getName()+".int", CI);
735 CI->replaceAllUsesWith(V);
736 CI->eraseFromParent();
737 return true;
706 return ReplaceCallWith(CI, V);
738707 }
739708
740709 uint64_t Str2Len, Str2StartIdx;
744713 // strncmp(x,"") -> *x
745714 Value *V = new LoadInst(Str1P, CI->getName()+".load", CI);
746715 V = new ZExtInst(V, CI->getType(), CI->getName()+".int", CI);
747 CI->replaceAllUsesWith(V);
748 CI->eraseFromParent();
749 return true;
716 return ReplaceCallWith(CI, V);
750717 }
751718
752719 if (Str1IsCst && Str2IsCst && A1->isCString() &&
755722 std::string S1 = A1->getAsString();
756723 std::string S2 = A2->getAsString();
757724 int R = strncmp(S1.c_str()+Str1StartIdx, S2.c_str()+Str2StartIdx, Length);
758 CI->replaceAllUsesWith(ConstantInt::get(CI->getType(), R));
759 CI->eraseFromParent();
760 return true;
725 return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), R));
761726 }
762727 return false;
763728 }
794759 Value *Src = CI->getOperand(2);
795760 if (Dst == Src) {
796761 // strcpy(x, x) -> x
797 CI->replaceAllUsesWith(Dst);
798 CI->eraseFromParent();
799 return true;
762 return ReplaceCallWith(CI, Dst);
800763 }
801764
802765 // Get the length of the constant string referenced by the Src operand.
809772 // doing a store of 0 at the first byte of the destination
810773 if (SrcLen == 0) {
811774 new StoreInst(ConstantInt::get(Type::Int8Ty, 0), Dst, CI);
812 CI->replaceAllUsesWith(Dst);
813 CI->eraseFromParent();
814 return true;
775 return ReplaceCallWith(CI, Dst);
815776 }
816777
817778 // We have enough information to now generate the memcpy call to
823784 };
824785 new CallInst(SLC.get_memcpy(), MemcpyOps, 4, "", CI);
825786
826 CI->replaceAllUsesWith(Dst);
827 CI->eraseFromParent();
828 return true;
787 return ReplaceCallWith(CI, Dst);
829788 }
830789 } StrCpyOptimizer;
831790
839798
840799 /// @brief Make sure that the "strlen" function has the right prototype
841800 virtual bool ValidateCalledFunction(const Function *F, SimplifyLibCalls &SLC){
842 if (f->getReturnType() == SLC.getTargetData()->getIntPtrType())
843 if (f->arg_size() == 1)
844 if (Function::const_arg_iterator AI = f->arg_begin())
801 if (F->getReturnType() == SLC.getTargetData()->getIntPtrType())
802 if (F->arg_size() == 1)
803 if (Function::const_arg_iterator AI = F->arg_begin())
845804 if (AI->getType() == PointerType::get(Type::Int8Ty))
846805 return true;
847806 return false;
891850
892851 // strlen("xyz") -> 3 (for example)
893852 const Type *Ty = SLC.getTargetData()->getIntPtrType();
894 ci->replaceAllUsesWith(ConstantInt::get(Ty, len));
895
896 ci->eraseFromParent();
897 return true;
853 return ReplaceCallWith(ci, ConstantInt::get(Ty, len));
898854 }
899855 } StrLenOptimizer;
900856
948904 // If the two operands are the same, return zero.
949905 if (LHS == RHS) {
950906 // memcmp(s,s,x) -> 0
951 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
952 CI->eraseFromParent();
953 return true;
907 return ReplaceCallWith(CI, Constant::getNullValue(CI->getType()));
954908 }
955909
956910 // Make sure we have a constant length.
962916 switch (Len) {
963917 case 0:
964918 // memcmp(s1,s2,0) -> 0
965 CI->replaceAllUsesWith(Constant::getNullValue(CI->getType()));
966 CI->eraseFromParent();
967 return true;
919 return ReplaceCallWith(CI, Constant::getNullValue(CI->getType()));
968920 case 1: {
969921 // memcmp(S1,S2,1) -> *(ubyte*)S1 - *(ubyte*)S2
970922 const Type *UCharPtr = PointerType::get(Type::Int8Ty);
978930 if (RV->getType() != CI->getType())
979931 RV = CastInst::createIntegerCast(RV, CI->getType(), false,
980932 RV->getName(), CI);
981 CI->replaceAllUsesWith(RV);
982 CI->eraseFromParent();
983 return true;
933 return ReplaceCallWith(CI, RV);
984934 }
985935 case 2:
986936 if (IsOnlyUsedInEqualsZeroComparison(CI)) {
1007957 if (Or->getType() != CI->getType())
1008958 Or = CastInst::createIntegerCast(Or, CI->getType(), false /*ZExt*/,
1009959 Or->getName(), CI);
1010 CI->replaceAllUsesWith(Or);
1011 CI->eraseFromParent();
1012 return true;
960 return ReplaceCallWith(CI, Or);
1013961 }
1014962 break;
1015963 default:
10631011 Value* dest = ci->getOperand(1);
10641012 Value* src = ci->getOperand(2);
10651013 const Type* castType = 0;
1066 switch (len)
1067 {
1014 switch (len) {
10681015 case 0:
1069 // memcpy(d,s,0,a) -> noop
1070 ci->eraseFromParent();
1071 return true;
1016 // memcpy(d,s,0,a) -> d
1017 return ReplaceCallWith(ci, 0);
10721018 case 1: castType = Type::Int8Ty; break;
10731019 case 2: castType = Type::Int16Ty; break;
10741020 case 4: castType = Type::Int32Ty; break;
10841030 dest, PointerType::get(castType),dest->getName()+".cast", ci);
10851031 LoadInst* LI = new LoadInst(SrcCast,SrcCast->getName()+".val",ci);
10861032 new StoreInst(LI, DestCast, ci);
1087 ci->eraseFromParent();
1088 return true;
1033 return ReplaceCallWith(ci, 0);
10891034 }
10901035 };
10911036
11411086 // If the length is zero, this is a no-op
11421087 if (len == 0) {
11431088 // memset(d,c,0,a) -> noop
1144 ci->eraseFromParent();
1145 return true;
1089 return ReplaceCallWith(ci, 0);
11461090 }
11471091
11481092 // If the length is larger than the alignment, we can't optimize
11931137 CastInst* DestCast = new BitCastInst(dest, PointerType::get(castType),
11941138 dest->getName()+".cast", ci);
11951139 new StoreInst(ConstantInt::get(castType,fill_value),DestCast, ci);
1196 ci->eraseFromParent();
1197 return true;
1140 return ReplaceCallWith(ci, 0);
11981141 }
11991142 };
12001143
12251168 Value* expn = ci->getOperand(2);
12261169 if (ConstantFP *Op1 = dyn_cast(base)) {
12271170 double Op1V = Op1->getValue();
1228 if (Op1V == 1.0) {
1229 // pow(1.0,x) -> 1.0
1230 ci->replaceAllUsesWith(ConstantFP::get(Ty,1.0));
1231 ci->eraseFromParent();
1232 return true;
1233 }
1171 if (Op1V == 1.0) // pow(1.0,x) -> 1.0
1172 return ReplaceCallWith(ci, ConstantFP::get(Ty, 1.0));
12341173 } else if (ConstantFP* Op2 = dyn_cast(expn)) {
12351174 double Op2V = Op2->getValue();
12361175 if (Op2V == 0.0) {
12371176 // pow(x,0.0) -> 1.0
1238 ci->replaceAllUsesWith(ConstantFP::get(Ty,1.0));
1239 ci->eraseFromParent();
1240 return true;
1177 return ReplaceCallWith(ci, ConstantFP::get(Ty,1.0));
12411178 } else if (Op2V == 0.5) {
12421179 // pow(x,0.5) -> sqrt(x)
12431180 CallInst* sqrt_inst = new CallInst(SLC.get_sqrt(), base,
12441181 ci->getName()+".pow",ci);
1245 ci->replaceAllUsesWith(sqrt_inst);
1246 ci->eraseFromParent();
1247 return true;
1182 return ReplaceCallWith(ci, sqrt_inst);
12481183 } else if (Op2V == 1.0) {
12491184 // pow(x,1.0) -> x
1250 ci->replaceAllUsesWith(base);
1251 ci->eraseFromParent();
1252 return true;
1185 return ReplaceCallWith(ci, base);
12531186 } else if (Op2V == -1.0) {
12541187 // pow(x,-1.0) -> 1.0/x
1255 BinaryOperator* div_inst= BinaryOperator::createFDiv(
1256 ConstantFP::get(Ty,1.0), base, ci->getName()+".pow", ci);
1257 ci->replaceAllUsesWith(div_inst);
1258 ci->eraseFromParent();
1259 return true;
1188 Value *div_inst =
1189 BinaryOperator::createFDiv(ConstantFP::get(Ty, 1.0), base,
1190 ci->getName()+".pow", ci);
1191 return ReplaceCallWith(ci, div_inst);
12601192 }
12611193 }
12621194 return false; // opt failed
13181250 std::vector args;
13191251 new CallInst(SLC.get_puts(), CastToCStr(ci->getOperand(2), *ci),
13201252 ci->getName(), ci);
1321 ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty, len));
1322 break;
1253 return ReplaceCallWith(ci, ConstantInt::get(Type::Int32Ty, len));
13231254 }
13241255 case 'c':
13251256 {
13301261 CastInst *Char = CastInst::createSExtOrBitCast(
13311262 ci->getOperand(2), Type::Int32Ty, CI->getName()+".int", ci);
13321263 new CallInst(SLC.get_putchar(), Char, "", ci);
1333 ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty, 1));
1334 break;
1264 return ReplaceCallWith(ci, ConstantInt::get(Type::Int32Ty, 1));
13351265 }
13361266 default:
13371267 return false;
13381268 }
1339 ci->eraseFromParent();
1340 return true;
1269 return false;
13411270 }
13421271 } PrintfOptimizer;
13431272
14021331 ci->getOperand(1)
14031332 };
14041333 new CallInst(SLC.get_fwrite(FILEptr_type), args, 4, ci->getName(), ci);
1405 ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,len));
1406 ci->eraseFromParent();
1407 return true;
1334 return ReplaceCallWith(ci, ConstantInt::get(Type::Int32Ty,len));
14081335 }
14091336
14101337 // The remaining optimizations require the format string to be length 2
14201347 // Get the second character and switch on its value
14211348 ConstantInt* CI = dyn_cast(CA->getOperand(1));
14221349 switch (CI->getZExtValue()) {
1423 case 's':
1424 {
1350 case 's': {
14251351 uint64_t len, StartIdx;
14261352 ConstantArray* CA = 0;
14271353 if (GetConstantStringInfo(ci->getOperand(3), CA, len, StartIdx)) {
14341360 ci->getOperand(1)
14351361 };
14361362 new CallInst(SLC.get_fwrite(FILEptr_type), args, 4,ci->getName(), ci);
1437 ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty, len));
1438 } else {
1439 // fprintf(file,"%s",str) -> fputs(str,file)
1440 const Type* FILEptr_type = ci->getOperand(1)->getType();
1441 new CallInst(SLC.get_fputs(FILEptr_type),
1442 CastToCStr(ci->getOperand(3), *ci),
1443 ci->getOperand(1), ci->getName(),ci);
1444 ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,len));
1363 return ReplaceCallWith(ci, ConstantInt::get(Type::Int32Ty, len));
14451364 }
1446 break;
1365 // fprintf(file,"%s",str) -> fputs(str,file)
1366 const Type* FILEptr_type = ci->getOperand(1)->getType();
1367 new CallInst(SLC.get_fputs(FILEptr_type),
1368 CastToCStr(ci->getOperand(3), *ci),
1369 ci->getOperand(1), ci->getName(),ci);
1370 return ReplaceCallWith(ci, ConstantInt::get(Type::Int32Ty,len));
14471371 }
1448 case 'c':
1449 {
1372 case 'c': {
14501373 // fprintf(file,"%c",c) -> fputc(c,file)
14511374 const Type* FILEptr_type = ci->getOperand(1)->getType();
14521375 CastInst* cast = CastInst::createSExtOrBitCast(
14531376 ci->getOperand(3), Type::Int32Ty, CI->getName()+".int", ci);
14541377 new CallInst(SLC.get_fputc(FILEptr_type), cast,ci->getOperand(1),"",ci);
1455 ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,1));
1456 break;
1378 return ReplaceCallWith(ci, ConstantInt::get(Type::Int32Ty,1));
14571379 }
14581380 default:
14591381 return false;
14601382 }
1461 ci->eraseFromParent();
1462 return true;
14631383 }
14641384 } FPrintFOptimizer;
14651385
14961416 if (len == 0) {
14971417 // If the length is 0, we just need to store a null byte
14981418 new StoreInst(ConstantInt::get(Type::Int8Ty,0),ci->getOperand(1),ci);
1499 ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,0));
1500 ci->eraseFromParent();
1501 return true;
1419 return ReplaceCallWith(ci, ConstantInt::get(Type::Int32Ty,0));
15021420 }
15031421
15041422 // Make sure there's no % in the constant array
15231441 ConstantInt::get(Type::Int32Ty, 1)
15241442 };
15251443 new CallInst(SLC.get_memcpy(), args, 4, "", ci);
1526 ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,len));
1527 ci->eraseFromParent();
1528 return true;
1444 return ReplaceCallWith(ci, ConstantInt::get(Type::Int32Ty,len));
15291445 }
15301446
15311447 // The remaining optimizations require the format string to be length 2
15671483 Len->getName(), ci);
15681484 ci->replaceAllUsesWith(Len);
15691485 }
1570 ci->eraseFromParent();
1571 return true;
1486 return ReplaceCallWith(ci, 0);
15721487 }
15731488 case 'c': {
15741489 // sprintf(dest,"%c",chr) -> store chr, dest
15791494 ConstantInt::get(Type::Int32Ty,1),ci->getOperand(1)->getName()+".end",
15801495 ci);
15811496 new StoreInst(ConstantInt::get(Type::Int8Ty,0),gep,ci);
1582 ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,1));
1583 ci->eraseFromParent();
1584 return true;
1497 return ReplaceCallWith(ci, ConstantInt::get(Type::Int32Ty, 1));
15851498 }
15861499 }
15871500 return false;
16471560 break;
16481561 }
16491562 }
1650 ci->eraseFromParent();
1651 return true; // success
1563 return ReplaceCallWith(ci, 0); // Known to have no uses (see above).
16521564 }
16531565 } PutsOptimizer;
16541566
16711583 if (ConstantInt* CI = dyn_cast(ci->getOperand(1))) {
16721584 // isdigit(c) -> 0 or 1, if 'c' is constant
16731585 uint64_t val = CI->getZExtValue();
1674 if (val >= '0' && val <='9')
1675 ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,1));
1586 if (val >= '0' && val <= '9')
1587 return ReplaceCallWith(ci, ConstantInt::get(Type::Int32Ty, 1));
16761588 else
1677 ci->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty,0));
1678 ci->eraseFromParent();
1679 return true;
1589 return ReplaceCallWith(ci, ConstantInt::get(Type::Int32Ty, 0));
16801590 }
16811591
16821592 // isdigit(c) -> (unsigned)c - '0' <= 9
16901600 ci->getOperand(1)->getName()+".cmp",ci);
16911601 CastInst* c2 = new ZExtInst(setcond_inst, Type::Int32Ty,
16921602 ci->getOperand(1)->getName()+".isdigit", ci);
1693 ci->replaceAllUsesWith(c2);
1694 ci->eraseFromParent();
1695 return true;
1603 return ReplaceCallWith(ci, c2);
16961604 }
16971605 } isdigitOptimizer;
16981606
17151623 V->getName()+".isascii", CI);
17161624 if (Cmp->getType() != CI->getType())
17171625 Cmp = new BitCastInst(Cmp, CI->getType(), Cmp->getName(), CI);
1718 CI->replaceAllUsesWith(Cmp);
1719 CI->eraseFromParent();
1720 return true;
1626 return ReplaceCallWith(CI, Cmp);
17211627 }
17221628 } isasciiOptimizer;
17231629
17411647 /// @brief Perform the toascii optimization.
17421648 virtual bool OptimizeCall(CallInst *ci, SimplifyLibCalls &SLC) {
17431649 // toascii(c) -> (c & 0x7f)
1744 Value* chr = ci->getOperand(1);
1745 BinaryOperator* and_inst = BinaryOperator::createAnd(chr,
1650 Value *chr = ci->getOperand(1);
1651 Value *and_inst = BinaryOperator::createAnd(chr,
17461652 ConstantInt::get(chr->getType(),0x7F),ci->getName()+".toascii",ci);
1747 ci->replaceAllUsesWith(and_inst);
1748 ci->eraseFromParent();
1749 return true;
1653 return ReplaceCallWith(ci, and_inst);
17501654 }
17511655 } ToAsciiOptimizer;
17521656
17871691 val >>= 1;
17881692 }
17891693 }
1790 TheCall->replaceAllUsesWith(ConstantInt::get(Type::Int32Ty, result));
1791 TheCall->eraseFromParent();
1792 return true;
1694 return ReplaceCallWith(TheCall, ConstantInt::get(Type::Int32Ty, result));
17931695 }
17941696
17951697 // ffs(x) -> x == 0 ? 0 : llvm.cttz(x)+1
18251727 TheCall);
18261728 V2 = new SelectInst(Cond, ConstantInt::get(Type::Int32Ty, 0), V2,
18271729 TheCall->getName(), TheCall);
1828 TheCall->replaceAllUsesWith(V2);
1829 TheCall->eraseFromParent();
1830 return true;
1730 return ReplaceCallWith(TheCall, V2);
18311731 }
18321732 } FFSOptimizer;
18331733
18731773 /// no precision loss.
18741774 static bool ShrinkFunctionToFloatVersion(CallInst *CI, SimplifyLibCalls &SLC,
18751775 Constant *(SimplifyLibCalls::*FP)()){
1876 if (CastInst *Cast = dyn_casttInst>(CI->getOperand(1)))
1776 if (FPExtInst *Cast = dyn_casttInst>(CI->getOperand(1)))
18771777 if (Cast->getOperand(0)->getType() == Type::FloatTy) {
18781778 Value *New = new CallInst((SLC.*FP)(), Cast->getOperand(0),
18791779 CI->getName(), CI);