Lines Matching refs:CI

57   /// performed.  If it returns CI, then it transformed the call and CI is to be
58 /// deleted. If it returns something else, replace CI with the new value and
59 /// delete CI.
60 virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B)
67 Value *optimizeCall(CallInst *CI, const DataLayout *DL,
70 Caller = CI->getParent()->getParent();
74 if (CI->getCalledFunction())
75 Context = &CI->getCalledFunction()->getContext();
78 if (!ignoreCallingConv() && CI->getCallingConv() != llvm::CallingConv::C)
81 return callOptimizer(CI->getCalledFunction(), CI, B);
117 static bool callHasFloatingPointArgument(const CallInst *CI) {
118 for (CallInst::const_op_iterator it = CI->op_begin(), e = CI->op_end();
152 CallInst *CI;
156 if (CI->getArgOperand(SizeCIOp) == CI->getArgOperand(SizeArgOp))
159 dyn_cast<ConstantInt>(CI->getArgOperand(SizeCIOp))) {
163 uint64_t Len = GetStringLength(CI->getArgOperand(SizeArgOp));
170 CI->getArgOperand(SizeArgOp)))
178 Value *callOptimizer(Function *Callee, CallInst *CI,
180 this->CI = CI;
182 LLVMContext &Context = CI->getParent()->getContext();
193 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
194 CI->getArgOperand(2), 1);
195 return CI->getArgOperand(0);
202 Value *callOptimizer(Function *Callee, CallInst *CI,
204 this->CI = CI;
206 LLVMContext &Context = CI->getParent()->getContext();
217 B.CreateMemMove(CI->getArgOperand(0), CI->getArgOperand(1),
218 CI->getArgOperand(2), 1);
219 return CI->getArgOperand(0);
226 Value *callOptimizer(Function *Callee, CallInst *CI,
228 this->CI = CI;
230 LLVMContext &Context = CI->getParent()->getContext();
241 Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(),
243 B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
244 return CI->getArgOperand(0);
251 Value *callOptimizer(Function *Callee, CallInst *CI,
253 this->CI = CI;
256 LLVMContext &Context = CI->getParent()->getContext();
266 Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1);
289 CI->getArgOperand(2), B, DL, TLI);
297 Value *callOptimizer(Function *Callee, CallInst *CI,
299 this->CI = CI;
302 LLVMContext &Context = CI->getParent()->getContext();
312 Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1);
339 if (!EmitMemCpyChk(Dst, Src, LenV, CI->getArgOperand(2), B, DL, TLI))
348 Value *callOptimizer(Function *Callee, CallInst *CI,
350 this->CI = CI;
353 LLVMContext &Context = CI->getParent()->getContext();
364 Value *Ret = EmitStrNCpy(CI->getArgOperand(0), CI->getArgOperand(1),
365 CI->getArgOperand(2), B, DL, TLI,
378 Value *callOptimizer(Function *Callee, CallInst *CI,
389 Value *Dst = CI->getArgOperand(0);
390 Value *Src = CI->getArgOperand(1);
429 Value *callOptimizer(Function *Callee, CallInst *CI,
441 Value *Dst = CI->getArgOperand(0);
442 Value *Src = CI->getArgOperand(1);
446 if (ConstantInt *LengthArg = dyn_cast<ConstantInt>(CI->getArgOperand(2)))
474 Value *callOptimizer(Function *Callee, CallInst *CI,
484 Value *SrcStr = CI->getArgOperand(0);
488 ConstantInt *CharC = dyn_cast<ConstantInt>(CI->getArgOperand(1));
497 return EmitMemChr(SrcStr, CI->getArgOperand(1), // include nul.
516 return Constant::getNullValue(CI->getType());
524 Value *callOptimizer(Function *Callee, CallInst *CI,
534 Value *SrcStr = CI->getArgOperand(0);
535 ConstantInt *CharC = dyn_cast<ConstantInt>(CI->getArgOperand(1));
553 return Constant::getNullValue(CI->getType());
561 Value *callOptimizer(Function *Callee, CallInst *CI,
571 Value *Str1P = CI->getArgOperand(0), *Str2P = CI->getArgOperand(1);
573 return ConstantInt::get(CI->getType(), 0);
581 return ConstantInt::get(CI->getType(), Str1.compare(Str2));
585 CI->getType()));
588 return B.CreateZExt(B.CreateLoad(Str1P, "strcmpload"), CI->getType());
607 Value *callOptimizer(Function *Callee, CallInst *CI,
618 Value *Str1P = CI->getArgOperand(0), *Str2P = CI->getArgOperand(1);
620 return ConstantInt::get(CI->getType(), 0);
624 if (ConstantInt *LengthArg = dyn_cast<ConstantInt>(CI->getArgOperand(2)))
630 return ConstantInt::get(CI->getType(), 0);
633 return EmitMemCmp(Str1P, Str2P, CI->getArgOperand(2), B, DL, TLI);
643 return ConstantInt::get(CI->getType(), SubStr1.compare(SubStr2));
648 CI->getType()));
651 return B.CreateZExt(B.CreateLoad(Str1P, "strcmpload"), CI->getType());
658 Value *callOptimizer(Function *Callee, CallInst *CI,
668 Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1);
688 Value *callOptimizer(Function *Callee, CallInst *CI,
701 Value *Dst = CI->getArgOperand(0), *Src = CI->getArgOperand(1);
725 Value *callOptimizer(Function *Callee, CallInst *CI,
734 Value *Dst = CI->getArgOperand(0);
735 Value *Src = CI->getArgOperand(1);
736 Value *LenOp = CI->getArgOperand(2);
774 Value *callOptimizer(Function *Callee, CallInst *CI,
782 Value *Src = CI->getArgOperand(0);
786 return ConstantInt::get(CI->getType(), Len-1);
797 ConstantInt::get(CI->getType(), LenTrue-1),
798 ConstantInt::get(CI->getType(), LenFalse-1));
804 if (isOnlyUsedInZeroEqualityComparison(CI))
805 return B.CreateZExt(B.CreateLoad(Src, "strlenfirst"), CI->getType());
812 Value *callOptimizer(Function *Callee, CallInst *CI,
822 bool HasS1 = getConstantStringInfo(CI->getArgOperand(0), S1);
823 bool HasS2 = getConstantStringInfo(CI->getArgOperand(1), S2);
828 return Constant::getNullValue(CI->getType());
834 return Constant::getNullValue(CI->getType());
836 return B.CreateGEP(CI->getArgOperand(0), B.getInt64(I), "strpbrk");
841 return EmitStrChr(CI->getArgOperand(0), S2[0], B, DL, TLI);
848 Value *callOptimizer(Function *Callee, CallInst *CI,
856 Value *EndPtr = CI->getArgOperand(1);
860 CI->addAttribute(1, Attribute::NoCapture);
868 Value *callOptimizer(Function *Callee, CallInst *CI,
878 bool HasS1 = getConstantStringInfo(CI->getArgOperand(0), S1);
879 bool HasS2 = getConstantStringInfo(CI->getArgOperand(1), S2);
884 return Constant::getNullValue(CI->getType());
890 return ConstantInt::get(CI->getType(), Pos);
898 Value *callOptimizer(Function *Callee, CallInst *CI,
908 bool HasS1 = getConstantStringInfo(CI->getArgOperand(0), S1);
909 bool HasS2 = getConstantStringInfo(CI->getArgOperand(1), S2);
913 return Constant::getNullValue(CI->getType());
919 return ConstantInt::get(CI->getType(), Pos);
924 return EmitStrLen(CI->getArgOperand(0), B, DL, TLI);
931 Value *callOptimizer(Function *Callee, CallInst *CI,
941 if (CI->getArgOperand(0) == CI->getArgOperand(1))
942 return B.CreateBitCast(CI->getArgOperand(0), CI->getType());
945 if (DL && isOnlyUsedInEqualityComparison(CI, CI->getArgOperand(0))) {
946 Value *StrLen = EmitStrLen(CI->getArgOperand(1), B, DL, TLI);
949 Value *StrNCmp = EmitStrNCmp(CI->getArgOperand(0), CI->getArgOperand(1),
953 for (auto UI = CI->user_begin(), UE = CI->user_end(); UI != UE;) {
960 return CI;
965 bool HasStr1 = getConstantStringInfo(CI->getArgOperand(0), SearchStr);
966 bool HasStr2 = getConstantStringInfo(CI->getArgOperand(1), ToFindStr);
970 return B.CreateBitCast(CI->getArgOperand(0), CI->getType());
977 return Constant::getNullValue(CI->getType());
980 Value *Result = CastToCStr(CI->getArgOperand(0), B);
982 return B.CreateBitCast(Result, CI->getType());
987 Value *StrChr= EmitStrChr(CI->getArgOperand(0), ToFindStr[0], B, DL, TLI);
988 return StrChr ? B.CreateBitCast(StrChr, CI->getType()) : nullptr;
995 Value *callOptimizer(Function *Callee, CallInst *CI,
1003 Value *LHS = CI->getArgOperand(0), *RHS = CI->getArgOperand(1);
1006 return Constant::getNullValue(CI->getType());
1009 ConstantInt *LenC = dyn_cast<ConstantInt>(CI->getArgOperand(2));
1014 return Constant::getNullValue(CI->getType());
1019 CI->getType(), "lhsv");
1021 CI->getType(), "rhsv");
1040 return ConstantInt::get(CI->getType(), Ret);
1048 Value *callOptimizer(Function *Callee, CallInst *CI,
1061 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
1062 CI->getArgOperand(2), 1);
1063 return CI->getArgOperand(0);
1068 Value *callOptimizer(Function *Callee, CallInst *CI,
1081 B.CreateMemMove(CI->getArgOperand(0), CI->getArgOperand(1),
1082 CI->getArgOperand(2), 1);
1083 return CI->getArgOperand(0);
1088 Value *callOptimizer(Function *Callee, CallInst *CI,
1101 Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), false);
1102 B.CreateMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), 1);
1103 return CI->getArgOperand(0);
1117 Value *callOptimizer(Function *Callee, CallInst *CI,
1126 for (User *U : CI->users()) {
1134 FPExtInst *Cast = dyn_cast<FPExtInst>(CI->getArgOperand(0));
1149 Value *callOptimizer(Function *Callee, CallInst *CI,
1162 for (User *U : CI->users()) {
1171 FPExtInst *Cast1 = dyn_cast<FPExtInst>(CI->getArgOperand(0));
1172 FPExtInst *Cast2 = dyn_cast<FPExtInst>(CI->getArgOperand(1));
1197 Value *callOptimizer(Function *Callee, CallInst *CI,
1203 Ret = UnsafeUnaryDoubleFP.callOptimizer(Callee, CI, B);
1214 Value *Op1 = CI->getArgOperand(0);
1225 Value *callOptimizer(Function *Callee, CallInst *CI,
1231 Ret = UnsafeUnaryDoubleFP.callOptimizer(Callee, CI, B);
1242 Value *Op1 = CI->getArgOperand(0), *Op2 = CI->getArgOperand(1);
1264 return ConstantFP::get(CI->getType(), 1.0);
1276 Value *Inf = ConstantFP::getInfinity(CI->getType());
1277 Value *NegInf = ConstantFP::getInfinity(CI->getType(), true);
1292 return B.CreateFDiv(ConstantFP::get(CI->getType(), 1.0),
1300 Value *callOptimizer(Function *Callee, CallInst *CI,
1306 Ret = UnsafeUnaryDoubleFP.callOptimizer(Callee, CI, B);
1316 Value *Op = CI->getArgOperand(0);
1344 CallInst *CI = B.CreateCall2(Callee, One, LdExpArg);
1346 CI->setCallingConv(F->getCallingConv());
1348 return CI;
1358 Value *callOptimizer(Function *Callee, CallInst *CI,
1362 if (!isTrigLibCall(CI))
1365 Value *Arg = CI->getArgOperand(0);
1376 classifyArgUse(U, CI->getParent(), IsFloat, SinCalls, CosCalls,
1384 insertSinCosCall(B, CI->getCalledFunction(), Arg, IsFloat, Sin, Cos,
1394 bool isTrigLibCall(CallInst *CI) {
1395 Function *Callee = CI->getCalledFunction();
1400 bool AttributesSafe = CI->hasFnAttr(Attribute::NoUnwind) &&
1401 CI->hasFnAttr(Attribute::ReadNone);
1414 CallInst *CI = dyn_cast<CallInst>(Val);
1416 if (!CI)
1419 Function *Callee = CI->getCalledFunction();
1423 !isTrigLibCall(CI))
1428 SinCalls.push_back(CI);
1430 CosCalls.push_back(CI);
1432 SinCosCalls.push_back(CI);
1435 SinCalls.push_back(CI);
1437 CosCalls.push_back(CI);
1439 SinCosCalls.push_back(CI);
1509 Value *callOptimizer(Function *Callee, CallInst *CI,
1519 Value *Op = CI->getArgOperand(0);
1522 if (ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
1523 if (CI->isZero()) // ffs(0) -> 0.
1526 return B.getInt32(CI->getValue().countTrailingZeros() + 1);
1544 Value *callOptimizer(Function *Callee, CallInst *CI,
1553 Value *Op = CI->getArgOperand(0);
1562 Value *callOptimizer(Function *Callee, CallInst *CI,
1571 Value *Op = CI->getArgOperand(0);
1574 return B.CreateZExt(Op, CI->getType());
1579 Value *callOptimizer(Function *Callee, CallInst *CI,
1588 Value *Op = CI->getArgOperand(0);
1590 return B.CreateZExt(Op, CI->getType());
1595 Value *callOptimizer(Function *Callee, CallInst *CI,
1604 return B.CreateAnd(CI->getArgOperand(0),
1605 ConstantInt::get(CI->getType(),0x7F));
1616 Value *callOptimizer(Function *Callee, CallInst *CI,
1627 if (!CI->hasFnAttr(Attribute::Cold) && isReportingError(Callee, CI)) {
1628 CI->addAttribute(AttributeSet::FunctionIndex, Attribute::Cold);
1635 bool isReportingError(Function *Callee, CallInst *CI) {
1648 if (StreamArg >= (int) CI->getNumArgOperands())
1650 LoadInst *LI = dyn_cast<LoadInst>(CI->getArgOperand(StreamArg));
1663 Value *optimizeFixedFormatString(Function *Callee, CallInst *CI,
1667 if (!getConstantStringInfo(CI->getArgOperand(0), FormatStr))
1672 return CI->use_empty() ? (Value*)CI :
1673 ConstantInt::get(CI->getType(), 0);
1678 if (!CI->use_empty())
1684 if (CI->use_empty() || !Res) return Res;
1685 return B.CreateIntCast(Res, CI->getType(), true);
1696 return (CI->use_empty() || !NewCI) ?
1698 ConstantInt::get(CI->getType(), FormatStr.size()+1);
1703 if (FormatStr == "%c" && CI->getNumArgOperands() > 1 &&
1704 CI->getArgOperand(1)->getType()->isIntegerTy()) {
1705 Value *Res = EmitPutChar(CI->getArgOperand(1), B, DL, TLI);
1707 if (CI->use_empty() || !Res) return Res;
1708 return B.CreateIntCast(Res, CI->getType(), true);
1712 if (FormatStr == "%s\n" && CI->getNumArgOperands() > 1 &&
1713 CI->getArgOperand(1)->getType()->isPointerTy()) {
1714 return EmitPutS(CI->getArgOperand(1), B, DL, TLI);
1719 Value *callOptimizer(Function *Callee, CallInst *CI,
1728 if (Value *V = optimizeFixedFormatString(Callee, CI, B)) {
1734 if (TLI->has(LibFunc::iprintf) && !callHasFloatingPointArgument(CI)) {
1738 CallInst *New = cast<CallInst>(CI->clone());
1748 Value *OptimizeFixedFormatString(Function *Callee, CallInst *CI,
1752 if (!getConstantStringInfo(CI->getArgOperand(1), FormatStr))
1756 if (CI->getNumArgOperands() == 2) {
1767 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(1),
1770 return ConstantInt::get(CI->getType(), FormatStr.size());
1776 CI->getNumArgOperands() < 3)
1782 if (!CI->getArgOperand(2)->getType()->isIntegerTy()) return nullptr;
1783 Value *V = B.CreateTrunc(CI->getArgOperand(2), B.getInt8Ty(), "char");
1784 Value *Ptr = CastToCStr(CI->getArgOperand(0), B);
1789 return ConstantInt::get(CI->getType(), 1);
1797 if (!CI->getArgOperand(2)->getType()->isPointerTy()) return nullptr;
1799 Value *Len = EmitStrLen(CI->getArgOperand(2), B, DL, TLI);
1805 B.CreateMemCpy(CI->getArgOperand(0), CI->getArgOperand(2), IncLen, 1);
1808 return B.CreateIntCast(Len, CI->getType(), false);
1813 Value *callOptimizer(Function *Callee, CallInst *CI,
1822 if (Value *V = OptimizeFixedFormatString(Callee, CI, B)) {
1828 if (TLI->has(LibFunc::siprintf) && !callHasFloatingPointArgument(CI)) {
1832 CallInst *New = cast<CallInst>(CI->clone());
1842 Value *optimizeFixedFormatString(Function *Callee, CallInst *CI,
1845 (void) ER.callOptimizer(Callee, CI, B);
1849 if (!getConstantStringInfo(CI->getArgOperand(1), FormatStr))
1855 if (!CI->use_empty())
1859 if (CI->getNumArgOperands() == 2) {
1867 return EmitFWrite(CI->getArgOperand(1),
1870 CI->getArgOperand(0), B, DL, TLI);
1876 CI->getNumArgOperands() < 3)
1882 if (!CI->getArgOperand(2)->getType()->isIntegerTy()) return nullptr;
1883 return EmitFPutC(CI->getArgOperand(2), CI->getArgOperand(0), B, DL, TLI);
1888 if (!CI->getArgOperand(2)->getType()->isPointerTy())
1890 return EmitFPutS(CI->getArgOperand(2), CI->getArgOperand(0), B, DL, TLI);
1895 Value *callOptimizer(Function *Callee, CallInst *CI,
1904 if (Value *V = optimizeFixedFormatString(Callee, CI, B)) {
1910 if (TLI->has(LibFunc::fiprintf) && !callHasFloatingPointArgument(CI)) {
1914 CallInst *New = cast<CallInst>(CI->clone());
1924 Value *callOptimizer(Function *Callee, CallInst *CI,
1927 (void) ER.callOptimizer(Callee, CI, B);
1939 ConstantInt *SizeC = dyn_cast<ConstantInt>(CI->getArgOperand(1));
1940 ConstantInt *CountC = dyn_cast<ConstantInt>(CI->getArgOperand(2));
1946 return ConstantInt::get(CI->getType(), 0);
1950 if (Bytes == 1 && CI->use_empty()) { // fwrite(S,1,1,F) -> fputc(S[0],F)
1951 Value *Char = B.CreateLoad(CastToCStr(CI->getArgOperand(0), B), "char");
1952 Value *NewCI = EmitFPutC(Char, CI->getArgOperand(3), B, DL, TLI);
1953 return NewCI ? ConstantInt::get(CI->getType(), 1) : nullptr;
1961 Value *callOptimizer(Function *Callee, CallInst *CI,
1964 (void) ER.callOptimizer(Callee, CI, B);
1973 !CI->use_empty())
1977 uint64_t Len = GetStringLength(CI->getArgOperand(0));
1980 return EmitFWrite(CI->getArgOperand(0),
1982 CI->getArgOperand(1), B, DL, TLI);
1987 Value *callOptimizer(Function *Callee, CallInst *CI,
1998 if (!getConstantStringInfo(CI->getArgOperand(0), Str))
2001 if (Str.empty() && CI->use_empty()) {
2004 if (CI->use_empty() || !Res) return Res;
2005 return B.CreateIntCast(Res, CI->getType(), true);
2037 Value *optimizeCall(CallInst *CI);
2038 LibCallOptimization *lookupOptimization(CallInst *CI);
2106 LibCallOptimization *LibCallSimplifierImpl::lookupOptimization(CallInst *CI) {
2108 Function *Callee = CI->getCalledFunction();
2112 if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(CI)) {
2286 Value *LibCallSimplifierImpl::optimizeCall(CallInst *CI) {
2287 LibCallOptimization *LCO = lookupOptimization(CI);
2289 IRBuilder<> Builder(CI);
2290 return LCO->optimizeCall(CI, DL, TLI, LCS, Builder);
2305 Value *LibCallSimplifier::optimizeCall(CallInst *CI) {
2306 if (CI->isNoBuiltin()) return nullptr;
2307 return Impl->optimizeCall(CI);