22 using namespace PatternMatch;
24 #define DEBUG_TYPE "instcombine"
45 "Unexpected FCmp predicate!");
85 "Unexpected FCmp predicate!");
114 bool IsBswapLHS = (IntrLHS && IntrLHS->getIntrinsicID() == Intrinsic::bswap);
115 bool IsBswapRHS = (IntrRHS && IntrRHS->getIntrinsicID() == Intrinsic::bswap);
117 if (!IsBswapLHS && !IsBswapRHS)
120 if (!IsBswapLHS && !ConstLHS)
123 if (!IsBswapRHS && !ConstRHS)
128 Value *NewLHS = IsBswapLHS ? IntrLHS->getOperand(0) :
131 Value *NewRHS = IsBswapRHS ? IntrRHS->getOperand(0) :
132 Builder->getInt(ConstRHS->getValue().byteSwap());
134 Value *BinOp = Builder->CreateBinOp(I.
getOpcode(), NewLHS, NewRHS);
136 return Builder->CreateCall(F, BinOp);
155 Value *
And = Builder->CreateAnd(X, AndRHS);
157 return BinaryOperator::CreateXor(And, Together);
162 if (Together != OpRHS) {
164 Value *
Or = Builder->CreateOr(X, Together);
166 return BinaryOperator::CreateAnd(Or, AndRHS);
170 if (TogetherCI && !TogetherCI->
isZero()){
175 Value *And = Builder->CreateAnd(X, Together);
177 return BinaryOperator::CreateOr(And, OpRHS);
197 if ((AddRHS & (AndRHSV-1)) == 0) {
202 if ((AddRHS & AndRHSV) == 0) {
207 Value *NewAnd = Builder->CreateAnd(X, AndRHS);
209 return BinaryOperator::CreateXor(NewAnd, AndRHS);
216 case Instruction::Shl: {
227 return replaceInstUsesWith(TheAnd, Op);
235 case Instruction::LShr: {
247 return replaceInstUsesWith(TheAnd, Op);
255 case Instruction::AShr:
268 ShVal = Builder->CreateLShr(ShVal, OpRHS, Op->
getName());
269 return BinaryOperator::CreateAnd(ShVal, AndRHS, TheAnd.
getName());
281 bool isSigned,
bool Inside) {
283 "Lo is not <= Hi in range emission code!");
302 return Builder->CreateICmp(Pred, VMinusLo, HiMinusLo);
315 MB = BitWidth - ((V - 1) ^ V).countLeadingZeros();
335 !isa<ConstantInt>(LHSI->
getOperand(1)))
return nullptr;
340 default:
return nullptr;
372 return Builder->CreateSub(LHSI->
getOperand(0), RHS,
"fold");
373 return Builder->CreateAdd(LHSI->
getOperand(0), RHS,
"fold");
421 bool icmp_abit = (ACst && !ACst->
isZero() &&
423 bool icmp_bbit = (BCst && !BCst->isZero() &&
424 BCst->getValue().isPowerOf2());
426 if (CCst && CCst->isZero()) {
456 }
else if (ACst && CCst &&
471 }
else if (BCst && CCst &&
520 Value *L11,*L12,*L21,*L22;
523 L21 = L22 = L1 =
nullptr;
554 if (R11 == L11 || R11 == L12 || R11 == L21 || R11 == L22) {
556 }
else if (R12 == L11 || R12 == L12 || R12 == L21 || R12 == L22) {
561 E =
R2; R1 =
nullptr; ok =
true;
570 if (R11 == L11 || R11 == L12 || R11 == L21 || R11 == L22) {
571 A = R11; D = R12; E =
R2; ok =
true;
572 }
else if (R12 == L11 || R12 == L12 || R12 == L21 || R12 == L22) {
573 A = R12; D = R11; E =
R2; ok =
true;
588 if (R11 == L11 || R11 == L12 || R11 == L21 || R11 == L22) {
589 A = R11; D = R12; E = R1; ok =
true;
590 }
else if (R12 == L11 || R12 == L12 || R12 == L21 || R12 == L22) {
591 A = R12; D = R11; E = R1; ok =
true;
601 }
else if (L12 == A) {
603 }
else if (L21 == A) {
605 }
else if (L22 == A) {
611 return LeftType & RightType;
618 Value *
A =
nullptr, *
B =
nullptr, *C =
nullptr, *
D =
nullptr, *
E =
nullptr;
622 if (Mask == 0)
return nullptr;
624 "foldLogOpOfMaskedICmpsHelper must return an equality predicate.");
654 return Builder->
CreateICmp(NewCC, NewAnd, Zero);
661 return Builder->
CreateICmp(NewCC, NewAnd, NewOr);
668 return Builder->
CreateICmp(NewCC, NewAnd2, A);
675 if (!BCst)
return nullptr;
677 if (!DCst)
return nullptr;
689 else if (NewMask == DCst->
getValue())
701 else if (NewMask == DCst->
getValue())
716 if (!CCst)
return nullptr;
718 if (!ECst)
return nullptr;
731 return Builder->
CreateICmp(NewCC, NewAnd, NewOr2);
777 default:
return nullptr;
781 bool IsNegative, IsNotNegative;
789 return Builder->CreateICmp(NewPred, Input, RangeEnd);
815 if (
Value *V = simplifyRangeCheck(LHS, RHS,
false))
819 if (
Value *V = simplifyRangeCheck(RHS, LHS,
false))
826 if (!LHSCst || !RHSCst)
return nullptr;
828 if (LHSCst == RHSCst && LHSCC == RHSCC) {
834 Value *NewOr = Builder->CreateOr(Val, Val2);
835 return Builder->CreateICmp(LHSCC, NewOr, LHSCst);
845 ConstantInt *AndCst, *SmallCst =
nullptr, *BigCst =
nullptr;
859 if (SmallCst && BigCst) {
865 if ((Low & AndCst->
getValue()) == 0 && (Low & BigCst->getValue()) == 0) {
866 Value *NewAnd = Builder->CreateAnd(V, Low | AndCst->
getValue());
869 return Builder->CreateICmp(LHSCC, NewAnd, NewVal);
876 if (Val != Val2)
return nullptr;
894 ShouldSwap = LHSCst->
getValue().
sgt(RHSCst->getValue());
896 ShouldSwap = LHSCst->
getValue().
ugt(RHSCst->getValue());
910 assert(LHSCst != RHSCst &&
"Compares not folded above?");
926 if (LHSCst ==
SubOne(RHSCst))
927 return Builder->CreateICmpULT(Val, LHSCst);
929 return insertRangeTest(Val, LHSCst->
getValue() + 1, RHSCst->getValue(),
933 if (LHSCst ==
SubOne(RHSCst))
934 return Builder->CreateICmpSLT(Val, LHSCst);
945 if (LHSCst ==
SubOne(RHSCst)){
990 if (RHSCst ==
AddOne(LHSCst))
991 return Builder->CreateICmp(LHSCC, Val, RHSCst);
994 return insertRangeTest(Val, LHSCst->
getValue() + 1, RHSCst->getValue(),
1009 if (RHSCst ==
AddOne(LHSCst))
1010 return Builder->CreateICmp(LHSCC, Val, RHSCst);
1013 return insertRangeTest(Val, LHSCst->
getValue() + 1, RHSCst->getValue(),
1031 if (Op0LHS == Op1RHS && Op0RHS == Op1LHS) {
1046 if (Op0LHS == Op1LHS && Op0RHS == Op1RHS)
1060 if (LHSC->getValueAPF().isNaN() || RHSC->getValueAPF().isNaN())
1061 return Builder->getFalse();
1067 if (isa<ConstantAggregateZero>(LHS->
getOperand(1)) &&
1068 isa<ConstantAggregateZero>(RHS->
getOperand(1)))
1083 "Trying to match De Morgan's Laws with something other than and/or");
1104 bool InstCombiner::shouldOptimizeCast(
CastInst *CI) {
1113 if (
const auto *PrecedingCI = dyn_cast<CastInst>(CastSrc))
1114 if (isEliminableCastPair(PrecedingCI, CI))
1119 if (CI->
getOpcode() == Instruction::SExt &&
1154 if (ZextTruncC == C) {
1157 return new ZExtInst(NewOp, DestTy);
1198 if (shouldOptimizeCast(Cast0) && shouldOptimizeCast(Cast1)) {
1199 Value *NewOp = Builder->CreateBinOp(LogicOpc, Cast0Src, Cast1Src,
1212 if (ICmp0 && ICmp1) {
1214 : FoldOrOfICmps(ICmp0, ICmp1, &I);
1224 if (FCmp0 && FCmp1) {
1226 : FoldOrOfFCmps(FCmp0, FCmp1);
1265 bool Changed = SimplifyAssociativeOrCommutative(I);
1268 if (
Value *V = SimplifyVectorOp(I))
1269 return replaceInstUsesWith(I, V);
1272 return replaceInstUsesWith(I, V);
1275 if (
Value *V = SimplifyUsingDistributiveLaws(I))
1276 return replaceInstUsesWith(I, V);
1280 if (SimplifyDemandedInstructionBits(I))
1283 if (
Value *V = SimplifyBSwap(I))
1284 return replaceInstUsesWith(I, V);
1286 if (
ConstantInt *AndRHS = dyn_cast<ConstantInt>(Op1)) {
1291 Value *Op0LHS = Op0I->getOperand(0);
1292 Value *Op0RHS = Op0I->getOperand(1);
1293 switch (Op0I->getOpcode()) {
1298 if (!Op0I->hasOneUse())
break;
1300 APInt NotAndRHS(~AndRHSMask);
1303 Value *NewRHS = Builder->CreateAnd(Op0RHS, AndRHS,
1307 if (!isa<Constant>(Op0RHS) &&
1310 Value *NewLHS = Builder->CreateAnd(Op0LHS, AndRHS,
1321 if (
Value *V = FoldLogicalPlusAnd(Op0LHS, Op0RHS, AndRHS,
false, I))
1322 return BinaryOperator::CreateAnd(V, AndRHS);
1323 if (
Value *V = FoldLogicalPlusAnd(Op0RHS, Op0LHS, AndRHS,
false, I))
1324 return BinaryOperator::CreateAnd(V, AndRHS);
1327 case Instruction::Sub:
1331 if (
Value *V = FoldLogicalPlusAnd(Op0LHS, Op0RHS, AndRHS,
true, I))
1332 return BinaryOperator::CreateAnd(V, AndRHS);
1336 return BinaryOperator::CreateAnd(Op0RHS, AndRHS);
1340 if (Op0I->hasOneUse() && !
match(Op0LHS,
m_Zero())) {
1346 Value *NewNeg = Builder->CreateNeg(Op0RHS);
1347 return BinaryOperator::CreateAnd(NewNeg, AndRHS);
1352 case Instruction::Shl:
1353 case Instruction::LShr:
1356 if (AndRHSMask == 1 && Op0LHS == AndRHS) {
1364 if (
ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1)))
1365 if (
Instruction *Res = OptAndOp(Op0I, Op0CI, AndRHS, I))
1378 Value *NewCast = Builder->CreateTrunc(X, I.
getType(),
"and.shrunk");
1381 return BinaryOperator::CreateAnd(NewCast, C3);
1385 if (
Instruction *FoldedLogic = foldOpWithConstantIntoOperand(I))
1393 Value *
A =
nullptr, *
B =
nullptr, *C =
nullptr, *
D =
nullptr;
1397 ((A == C &&
B ==
D) || (A ==
D &&
B == C)))
1398 return BinaryOperator::CreateXor(A,
B);
1403 ((A == C &&
B ==
D) || (A ==
D &&
B == C)))
1404 return BinaryOperator::CreateXor(A,
B);
1408 Value *tmpOp0 = Op0;
1409 Value *tmpOp1 = Op1;
1411 if (A == Op1 ||
B == Op1 ) {
1426 if (A == tmpOp0 && !isa<Constant>(A))
1427 return BinaryOperator::CreateAnd(A, Builder->CreateNot(
B));
1434 return BinaryOperator::CreateAnd(A, Op1);
1437 return BinaryOperator::CreateAnd(A, Op0);
1442 if (Op1->hasOneUse() || cast<BinaryOperator>(Op1)->hasOneUse())
1443 return BinaryOperator::CreateAnd(Op0, Builder->CreateNot(C));
1448 if (Op0->
hasOneUse() || cast<BinaryOperator>(Op0)->hasOneUse())
1449 return BinaryOperator::CreateAnd(Op1, Builder->CreateNot(C));
1454 return BinaryOperator::CreateAnd(A,
B);
1460 return BinaryOperator::CreateAnd(A,
B);
1467 if (
Value *Res = FoldAndOfICmps(LHS, RHS))
1468 return replaceInstUsesWith(I, Res);
1474 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
1475 if (
Value *Res = FoldAndOfICmps(LHS, Cmp))
1476 return replaceInstUsesWith(I, Builder->CreateAnd(Res, Y));
1477 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
1478 if (
Value *Res = FoldAndOfICmps(LHS, Cmp))
1479 return replaceInstUsesWith(I, Builder->CreateAnd(Res, X));
1482 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
1483 if (
Value *Res = FoldAndOfICmps(Cmp, RHS))
1484 return replaceInstUsesWith(I, Builder->CreateAnd(Res, Y));
1485 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
1486 if (
Value *Res = FoldAndOfICmps(Cmp, RHS))
1487 return replaceInstUsesWith(I, Builder->CreateAnd(Res, X));
1494 if (
Value *Res = FoldAndOfFCmps(LHS, RHS))
1495 return replaceInstUsesWith(I, Res);
1497 if (
Instruction *CastedAnd = foldCastedBitwiseLogic(I))
1503 return Changed ? &I :
nullptr;
1513 Op0 =
Ext->getOperand(0);
1516 Op1 =
Ext->getOperand(0);
1530 if (!OrOfOrs && !OrOfShifts && !OrOfAnds)
1539 for (
auto *Inst : Insts)
1547 for (
unsigned i = 0;
i != NumElts; ++
i) {
1550 if (!EltC1 || !EltC2)
1649 Value *Mask =
nullptr;
1650 Value *Masked =
nullptr;
1651 if (LAnd->
getOperand(0) == RAnd->getOperand(0) &&
1656 Mask = Builder->CreateOr(LAnd->
getOperand(1), RAnd->getOperand(1));
1658 }
else if (LAnd->
getOperand(1) == RAnd->getOperand(1) &&
1663 Mask = Builder->CreateOr(LAnd->
getOperand(0), RAnd->getOperand(0));
1684 LHSCC == RHSCC && LHSCst && RHSCst && LHS->
hasOneUse() &&
1686 LHSCst->
getValue() == (RHSCst->getValue())) {
1691 Value *LAddOpnd, *RAddOpnd;
1699 if (LAddOpnd == RAddOpnd && DiffCst.
isPowerOf2()) {
1702 MaxAddCst = RAddCst;
1704 MaxAddCst = LAddCst;
1710 APInt LowRangeDiff = RRangeLow ^ LRangeLow;
1711 APInt HighRangeDiff = RRangeHigh ^ LRangeHigh;
1712 APInt RangeDiff = LRangeLow.
sgt(RRangeLow) ? LRangeLow - RRangeLow
1713 : RRangeLow - LRangeLow;
1715 if (LowRangeDiff.
isPowerOf2() && LowRangeDiff == HighRangeDiff &&
1719 Value *NewAnd = Builder->CreateAnd(LAddOpnd, MaskCst);
1720 Value *NewAdd = Builder->CreateAdd(NewAnd, MaxAddCst);
1721 return (Builder->CreateICmp(LHS->
getPredicate(), NewAdd, LHSCst));
1750 Value *
A =
nullptr, *
B =
nullptr;
1768 return Builder->CreateICmp(
1774 if (
Value *V = simplifyRangeCheck(LHS, RHS,
true))
1778 if (
Value *V = simplifyRangeCheck(RHS, LHS,
true))
1782 if (!LHSCst || !RHSCst)
return nullptr;
1784 if (LHSCst == RHSCst && LHSCC == RHSCC) {
1787 Value *NewOr = Builder->CreateOr(Val, Val2);
1788 return Builder->CreateICmp(LHSCC, NewOr, LHSCst);
1798 return Builder->CreateICmpULE(Val, LHSCst);
1803 if (Val != Val2)
return nullptr;
1821 ShouldSwap = LHSCst->
getValue().
sgt(RHSCst->getValue());
1823 ShouldSwap = LHSCst->
getValue().
ugt(RHSCst->getValue());
1837 assert(LHSCst != RHSCst &&
"Compares not folded above?");
1852 Value *Cst = Builder->getInt(Xor);
1858 if (LHSCst ==
SubOne(RHSCst)) {
1863 return Builder->CreateICmpULT(Add, AddCST);
1886 return Builder->getTrue();
1896 if (RHSCst->isMaxValue(
false))
1898 return insertRangeTest(Val, LHSCst->
getValue(), RHSCst->getValue() + 1,
1917 if (RHSCst->isMaxValue(
true))
1919 return insertRangeTest(Val, LHSCst->
getValue(), RHSCst->getValue() + 1,
1940 return Builder->getTrue();
1955 return Builder->getTrue();
1971 if (Op0LHS == Op1RHS && Op0RHS == Op1LHS) {
1984 if (Op0LHS == Op1LHS && Op0RHS == Op1RHS)
1995 if (LHSC->getValueAPF().isNaN() || RHSC->getValueAPF().isNaN())
1996 return Builder->getTrue();
2005 if (isa<ConstantAggregateZero>(LHS->
getOperand(1)) &&
2006 isa<ConstantAggregateZero>(RHS->
getOperand(1)))
2027 if (!CI1)
return nullptr;
2029 Value *V1 =
nullptr;
2036 if (V1 == A || V1 == B) {
2037 Value *NewOp = Builder->CreateAnd((V1 == A) ? B : A, CI1);
2038 return BinaryOperator::CreateOr(NewOp, V1);
2059 Value *V1 =
nullptr;
2068 if (V1 == A || V1 == B) {
2069 Value *NewOp = Builder->CreateAnd(V1 == A ? B : A, CI1);
2070 return BinaryOperator::CreateXor(NewOp, V1);
2080 bool Changed = SimplifyAssociativeOrCommutative(I);
2083 if (
Value *V = SimplifyVectorOp(I))
2084 return replaceInstUsesWith(I, V);
2087 return replaceInstUsesWith(I, V);
2090 if (
Value *V = SimplifyUsingDistributiveLaws(I))
2091 return replaceInstUsesWith(I, V);
2095 if (SimplifyDemandedInstructionBits(I))
2098 if (
Value *V = SimplifyBSwap(I))
2099 return replaceInstUsesWith(I, V);
2101 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
2106 (RHS->getValue() & C1->
getValue()) != 0 &&
2108 Value *Or = Builder->CreateOr(X, RHS);
2110 return BinaryOperator::CreateAnd(Or,
2111 Builder->getInt(RHS->getValue() | C1->
getValue()));
2117 Value *Or = Builder->CreateOr(X, RHS);
2119 return BinaryOperator::CreateXor(Or,
2120 Builder->getInt(C1->
getValue() & ~RHS->getValue()));
2123 if (
Instruction *FoldedLogic = foldOpWithConstantIntoOperand(I))
2131 Value *
A =
nullptr, *
B =
nullptr;
2138 Value *NOr = Builder->CreateOr(A, Op1);
2140 return BinaryOperator::CreateXor(NOr, C1);
2144 if (Op1->hasOneUse() &&
2147 Value *NOr = Builder->CreateOr(A, Op0);
2149 return BinaryOperator::CreateXor(NOr, C1);
2155 return BinaryOperator::CreateOr(A,
B);
2160 return BinaryOperator::CreateOr(Builder->CreateNot(A),
B);
2166 return BinaryOperator::CreateXor(A,
B);
2173 return BinaryOperator::CreateXor(A,
B);
2176 Value *C =
nullptr, *
D =
nullptr;
2179 Value *V1 =
nullptr, *
V2 =
nullptr;
2183 if ((C1->
getValue() & C2->getValue()) == 0) {
2191 return BinaryOperator::CreateAnd(A,
2192 Builder->getInt(C1->
getValue()|C2->getValue()));
2199 return BinaryOperator::CreateAnd(
B,
2200 Builder->getInt(C1->
getValue()|C2->getValue()));
2208 (C4->getValue() & ~C2->getValue()) == 0) {
2210 return BinaryOperator::CreateAnd(
V2,
2211 Builder->getInt(C1->
getValue()|C2->getValue()));
2219 if (Op0->
hasOneUse() || Op1->hasOneUse()) {
2222 return replaceInstUsesWith(I, V);
2224 return replaceInstUsesWith(I, V);
2226 return replaceInstUsesWith(I, V);
2228 return replaceInstUsesWith(I, V);
2230 return replaceInstUsesWith(I, V);
2232 return replaceInstUsesWith(I, V);
2234 return replaceInstUsesWith(I, V);
2236 return replaceInstUsesWith(I, V);
2242 return BinaryOperator::CreateXor(A,
D);
2246 return BinaryOperator::CreateXor(C,
D);
2250 return BinaryOperator::CreateXor(A,
B);
2254 return BinaryOperator::CreateXor(C,
B);
2260 if (Ret)
return Ret;
2266 if (Ret)
return Ret;
2272 if (Ret)
return Ret;
2278 if (Ret)
return Ret;
2285 if (Op1->hasOneUse() || cast<BinaryOperator>(Op1)->hasOneUse())
2286 return BinaryOperator::CreateOr(Op0, C);
2291 if (Op0->
hasOneUse() || cast<BinaryOperator>(Op0)->hasOneUse())
2292 return BinaryOperator::CreateOr(Op1, C);
2296 return BinaryOperator::CreateOr(Op1, Builder->CreateAnd(A, C));
2302 bool SwappedForXor =
false;
2305 SwappedForXor =
true;
2312 if (Op0 == A || Op0 ==
B)
2313 return BinaryOperator::CreateOr(A,
B);
2317 return BinaryOperator::CreateOr(A,
B);
2320 Value *
Not = Builder->CreateNot(
B,
B->getName()+
".not");
2321 return BinaryOperator::CreateOr(Not, Op0);
2325 return BinaryOperator::CreateOr(Not, Op0);
2333 if ((Op0 ==
B->getOperand(0) || Op0 ==
B->getOperand(1)) &&
2336 Value *NotOp = Op0 ==
B->getOperand(0) ?
B->getOperand(1) :
2339 return BinaryOperator::CreateOr(Not, Op0);
2351 return BinaryOperator::CreateXor(Builder->CreateNot(A),
B);
2360 if (
Value *Res = FoldOrOfICmps(LHS, RHS, &I))
2361 return replaceInstUsesWith(I, Res);
2367 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
2368 if (
Value *Res = FoldOrOfICmps(LHS, Cmp, &I))
2369 return replaceInstUsesWith(I, Builder->CreateOr(Res, Y));
2370 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
2371 if (
Value *Res = FoldOrOfICmps(LHS, Cmp, &I))
2372 return replaceInstUsesWith(I, Builder->CreateOr(Res, X));
2375 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
2376 if (
Value *Res = FoldOrOfICmps(Cmp, RHS, &I))
2377 return replaceInstUsesWith(I, Builder->CreateOr(Res, Y));
2378 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
2379 if (
Value *Res = FoldOrOfICmps(Cmp, RHS, &I))
2380 return replaceInstUsesWith(I, Builder->CreateOr(Res, X));
2387 if (
Value *Res = FoldOrOfFCmps(LHS, RHS))
2388 return replaceInstUsesWith(I, Res);
2390 if (
Instruction *CastedOr = foldCastedBitwiseLogic(I))
2406 if (Op0->
hasOneUse() && !isa<ConstantInt>(Op1) &&
2408 Value *Inner = Builder->CreateOr(A, Op1);
2410 return BinaryOperator::CreateOr(Inner, C1);
2417 Value *X =
nullptr, *
Y =
nullptr;
2418 if (Op0->
hasOneUse() && Op1->hasOneUse() &&
2421 Value *orTrue = Builder->CreateOr(A, C);
2422 Value *orFalse = Builder->CreateOr(
B,
D);
2427 return Changed ? &I :
nullptr;
2434 bool Changed = SimplifyAssociativeOrCommutative(I);
2437 if (
Value *V = SimplifyVectorOp(I))
2438 return replaceInstUsesWith(I, V);
2441 return replaceInstUsesWith(I, V);
2444 if (
Value *V = SimplifyUsingDistributiveLaws(I))
2445 return replaceInstUsesWith(I, V);
2449 if (SimplifyDemandedInstructionBits(I))
2452 if (
Value *V = SimplifyBSwap(I))
2453 return replaceInstUsesWith(I, V);
2463 Op0I->swapOperands();
2466 Builder->CreateNot(Op0I->getOperand(1),
2467 Op0I->getOperand(1)->getName()+
".not");
2469 return BinaryOperator::CreateOr(Op0NotVal, NotY);
2470 return BinaryOperator::CreateAnd(Op0NotVal, NotY);
2476 Op0I->getOperand(0)->hasOneUse()) &&
2478 Op0I->getOperand(1)->hasOneUse())) {
2480 Builder->CreateNot(Op0I->getOperand(0),
"notlhs");
2482 Builder->CreateNot(Op0I->getOperand(1),
"notrhs");
2484 return BinaryOperator::CreateOr(NotX, NotY);
2485 return BinaryOperator::CreateAnd(NotX, NotY);
2488 }
else if (Op0I->getOpcode() == Instruction::AShr) {
2491 return BinaryOperator::CreateAShr(Op0NotVal, Op0I->getOperand(1));
2496 if (
Constant *RHS = dyn_cast<Constant>(Op1)) {
2497 if (RHS->isAllOnesValue() && Op0->
hasOneUse())
2499 if (
CmpInst *CI = dyn_cast<CmpInst>(Op0))
2501 CI->getInversePredicate(),
2505 if (
ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
2507 if (
CastInst *Op0C = dyn_cast<CastInst>(Op0)) {
2508 if (
CmpInst *CI = dyn_cast<CmpInst>(Op0C->getOperand(0))) {
2509 if (CI->
hasOneUse() && Op0C->hasOneUse()) {
2511 if ((Opcode == Instruction::ZExt || Opcode == Instruction::SExt) &&
2513 Op0C->getDestTy()))) {
2514 CI->setPredicate(CI->getInversePredicate());
2523 if (Op0I->getOpcode() == Instruction::Sub && RHS->isAllOnesValue())
2524 if (
Constant *Op0I0C = dyn_cast<Constant>(Op0I->getOperand(0))) {
2531 if (
ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1))) {
2534 if (RHS->isAllOnesValue()) {
2536 return BinaryOperator::CreateSub(
2540 }
else if (RHS->getValue().isSignBit()) {
2542 Constant *C = Builder->getInt(RHS->getValue() + Op0CI->getValue());
2561 }
else if (Op0I->getOpcode() == Instruction::LShr) {
2566 if (Op0I->hasOneUse() &&
2573 FoldConst ^= C3->getValue();
2577 cast<Instruction>(Opnd0)->setDebugLoc(I.
getDebugLoc());
2580 return BinaryOperator::CreateXor(Opnd0, FoldVal);
2586 if (
Instruction *FoldedLogic = foldOpWithConstantIntoOperand(I))
2598 }
else if (B == Op0) {
2623 return BinaryOperator::CreateAnd(A, Builder->CreateNot(Op1));
2629 !isa<ConstantInt>(Op1)) {
2630 return BinaryOperator::CreateAnd(Builder->CreateNot(A), Op1);
2640 if ((A == C && B == D) || (A == D && B ==
C))
2641 return BinaryOperator::CreateXor(A, B);
2646 if ((A == C && B == D) || (A == D && B == C))
2647 return BinaryOperator::CreateXor(A, B);
2653 return BinaryOperator::CreateXor(A, B);
2658 return BinaryOperator::CreateXor(A, B);
2664 return BinaryOperator::CreateXor(A, B);
2669 return BinaryOperator::CreateXor(A, B);
2675 return BinaryOperator::CreateXor(
2676 Builder->CreateAnd(Builder->CreateNot(A),
B), C);
2678 return BinaryOperator::CreateXor(
2679 Builder->CreateAnd(Builder->CreateNot(B),
A), C);
2685 return BinaryOperator::CreateXor(
2686 Builder->CreateAnd(Builder->CreateNot(A),
B), C);
2688 return BinaryOperator::CreateXor(
2689 Builder->CreateAnd(Builder->CreateNot(B),
A), C);
2694 return BinaryOperator::CreateOr(A, B);
2698 return BinaryOperator::CreateOr(A, B);
2712 if (LHS->getOperand(0) == RHS->getOperand(1) &&
2713 LHS->getOperand(1) == RHS->getOperand(0))
2714 LHS->swapOperands();
2715 if (LHS->getOperand(0) == RHS->getOperand(0) &&
2716 LHS->getOperand(1) == RHS->getOperand(1)) {
2717 Value *Op0 = LHS->getOperand(0), *Op1 = LHS->getOperand(1);
2719 bool isSigned = LHS->isSigned() || RHS->isSigned();
2720 return replaceInstUsesWith(I,
2726 if (
Instruction *CastedXor = foldCastedBitwiseLogic(I))
2729 return Changed ? &I :
nullptr;
Value * FoldOrOfICmps(ICmpInst *LHS, ICmpInst *RHS, Instruction *CxtI)
Fold (icmp)|(icmp) if possible.
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
static ConstantInt * getFalse(LLVMContext &Context)
Value * FoldAndOfICmps(ICmpInst *LHS, ICmpInst *RHS)
Fold (icmp)&(icmp) if possible.
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given value is known to have exactly one bit set when defined. ...
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
This class is the base class for the comparison instructions.
static bool IsFreeToInvert(Value *V, bool WillInvertAllUses)
Return true if the specified value is free to invert (apply ~ to).
Instruction * visitXor(BinaryOperator &I)
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
Instruction * visitOr(BinaryOperator &I)
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
bool decomposeBitTestICmp(const ICmpInst *I, CmpInst::Predicate &Pred, Value *&X, Value *&Y, Value *&Z)
Decompose an icmp into the form ((X & Y) pred Z) if possible.
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
match_zero m_Zero()
Match an arbitrary zero/null constant.
static unsigned getFCmpCode(FCmpInst::Predicate CC)
Similar to getICmpCode but for FCmpInst.
This class represents zero extension of integer types.
unsigned getNumOperands() const
static Value * foldLogOpOfMaskedICmps(ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, llvm::InstCombiner::BuilderTy *Builder)
Try to fold (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) into a single (icmp(A & X) ==/!= Y)...
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Xor >, BinaryOp_match< RHS, LHS, Instruction::Xor > > m_c_Xor(const LHS &L, const RHS &R)
Matches an Xor with LHS and RHS in either order.
unsigned getICmpCode(const ICmpInst *ICI, bool InvertPred=false)
Encode a icmp predicate into a three bit mask.
static bool areInverseVectorBitmasks(Constant *C1, Constant *C2)
If all elements of two constant vectors are 0/-1 and inverses, return true.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
bool isSigned() const
Determine if this instruction is using a signed comparison.
0 1 0 0 True if ordered and less than
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
static Value * getFCmpValue(unsigned Code, Value *LHS, Value *RHS, InstCombiner::BuilderTy *Builder)
This is the complement of getFCmpCode, which turns an opcode and two operands into either a FCmp inst...
1 1 1 0 True if unordered or not equal
static CastInst * CreateBitOrPointerCast(Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a BitCast, a PtrToInt, or an IntToPTr cast instruction.
MaskedICmpType
enum for classifying (icmp eq (A & B), C) and (icmp ne (A & B), C) One of A and B is considered the m...
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
static Constant * getTrue(Type *Ty)
For a boolean type, or a vector of boolean type, return true, or a vector with every element true...
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::And >, BinaryOp_match< RHS, LHS, Instruction::And > > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getName() const
Return a constant reference to the value's name.
bool swapOperands()
Exchange the two operands to this instruction.
APInt Not(const APInt &APIVal)
Bitwise complement function.
1 0 0 1 True if unordered or equal
bool match(Val *V, const Pattern &P)
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Or >, BinaryOp_match< RHS, LHS, Instruction::Or > > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
This is the base class for all instructions that perform data casts.
const APInt & getValue() const
Return the constant as an APInt value reference.
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static Constant * AddOne(Constant *C)
Add one to a Constant.
0 1 0 1 True if ordered and less than or equal
bool isShiftedMask(unsigned numBits, const APInt &APIVal)
Return true if the argument APInt value contains a sequence of ones with the remainder zero...
Instruction * FoldOrWithConstants(BinaryOperator &I, Value *Op, Value *A, Value *B, Value *C)
This helper function folds:
not_match< LHS > m_Not(const LHS &L)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
static unsigned foldLogOpOfMaskedICmpsHelper(Value *&A, Value *&B, Value *&C, Value *&D, Value *&E, ICmpInst *LHS, ICmpInst *RHS, ICmpInst::Predicate &LHSCC, ICmpInst::Predicate &RHSCC)
Handle (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) Return the set of pattern classes (from Masked...
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
static Instruction * foldLogicCastConstant(BinaryOperator &Logic, CastInst *Cast, InstCombiner::BuilderTy *Builder)
Fold {and,or,xor} (cast X), C.
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
This instruction compares its operands according to the predicate given to the constructor.
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
bool sgt(const APInt &RHS) const
Signed greather than comparison.
static CmpInst * Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2, const Twine &Name="", Instruction *InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
unsigned getActiveBits() const
Compute the number of active bits in the value.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
SelectClass_match< Cond, LHS, RHS > m_Select(const Cond &C, const LHS &L, const RHS &R)
void takeName(Value *V)
Transfer the name from V to this value.
Type * getScalarType() const LLVM_READONLY
If this is a vector type, return the element type, otherwise return 'this'.
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
static const Value * getNotArgument(const Value *BinOp)
bool ult(const APInt &RHS) const
Unsigned less than comparison.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
Value * SimplifyOrInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for an Or, fold the result or return null.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
OneUse_match< T > m_OneUse(const T &SubPattern)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
static Value * getSelectCondition(Value *A, Value *B, InstCombiner::BuilderTy &Builder)
We have an expression of the form (A & C) | (B & D).
The instances of the Type class are immutable: once they are created, they are never changed...
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
bool isVectorTy() const
True if this is an instance of VectorType.
bool isEquality() const
Return true if this predicate is either EQ or NE.
CastClass_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
This is an important base class in LLVM.
Value * FoldAndOfFCmps(FCmpInst *LHS, FCmpInst *RHS)
Optimize (fcmp)&(fcmp).
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if 'V & Mask' is known to be zero.
static Constant * getAnd(Constant *C1, Constant *C2)
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
ConstantFP - Floating Point Values [float, double].
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set to true.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
static bool isNot(const Value *V)
Class to represent integer types.
Type * getSrcTy() const
Return the source type, as a convenience.
unsigned countPopulation() const
Count the number of bits set.
static unsigned conjugateICmpMask(unsigned Mask)
Convert an analysis of a masked ICmp into its equivalent if all boolean operations had the opposite s...
Predicate getPredicate() const
Return the predicate for this instruction.
static Constant * getNot(Constant *C)
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
1 1 1 1 Always true (always folded)
void swapOperands()
Exchange the two operands to this instruction in such a way that it does not modify the semantics of ...
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
1 1 0 1 True if unordered, less than, or equal
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static Instruction * foldBoolSextMaskToSelect(BinaryOperator &I)
Instruction * visitAnd(BinaryOperator &I)
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
0 0 1 0 True if ordered and greater than
BinaryOps getOpcode() const
This is the shared class of boolean and integer constants.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
1 1 0 0 True if unordered or less than
Type * getType() const
All values are typed, get the type of this value.
BinOp2_match< LHS, RHS, Instruction::LShr, Instruction::Shl > m_LogicalShift(const LHS &L, const RHS &R)
Matches LShr or Shl.
Type * getDestTy() const
Return the destination type, as a convenience.
LLVM_NODISCARD T pop_back_val()
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
bool PredicatesFoldable(CmpInst::Predicate p1, CmpInst::Predicate p2)
Return true if both predicates match sign or if at least one of them is an equality comparison (which...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
void setOperand(unsigned i, Value *Val)
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Class for arbitrary precision integers.
bool isIntegerTy() const
True if this is an instance of IntegerType.
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
unsigned getVectorNumElements() const
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
bool isMinValue() const
Determine if this is the smallest unsigned value.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
bool isAllOnesValue() const
Determine if all bits are set.
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
void ComputeSignBit(const Value *V, bool &KnownZero, bool &KnownOne, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Determine whether the sign bit is known to be zero or one.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
Value * SimplifyAndInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for an And, fold the result or return null.
Value * getICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS, CmpInst::Predicate &NewICmpPred)
This is the complement of getICmpCode, which turns an opcode and two operands into either a constant ...
unsigned greater or equal
static Value * dyn_castNotVal(Value *V)
static Constant * getOr(Constant *C1, Constant *C2)
bool hasOneUse() const
Return true if there is exactly one user of this value.
0 1 1 0 True if ordered and operands are unequal
bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction * > &InsertedInsts)
Try and match a bswap or bitreverse idiom.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
1 0 1 0 True if unordered or greater than
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
OtherOps getOpcode() const
Get the opcode casted to the right type.
Value * SimplifyXorInst(Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for an Xor, fold the result or return null.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME)
Returns true iff Val consists of one contiguous run of 1s with any number of 0s on either side...
0 0 0 1 True if ordered and equal
LLVM Value Representation.
This file provides internal interfaces used to implement the InstCombine.
1 0 1 1 True if unordered, greater than, or equal
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static Value * getNewICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS, InstCombiner::BuilderTy *Builder)
This is the complement of getICmpCode, which turns an opcode and two operands into either a constant ...
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
APInt zext(unsigned width) const
Zero extend to a new width.
Value * simplifyRangeCheck(ICmpInst *Cmp0, ICmpInst *Cmp1, bool Inverted)
Try to fold a signed range checked with lower bound 0 to an unsigned icmp.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
bool isBitwiseLogicOp() const
Return true if this is and/or/xor.
0 0 1 1 True if ordered and greater than or equal
static Value * matchSelectFromAndOr(Value *A, Value *C, Value *B, Value *D, InstCombiner::BuilderTy &Builder)
We have an expression of the form (A & C) | (B & D).
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
static Instruction * matchDeMorgansLaws(BinaryOperator &I, InstCombiner::BuilderTy *Builder)
Match De Morgan's Laws: (~A & ~B) == (~(A | B)) (~A | ~B) == (~(A & B))
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
Instruction * FoldXorWithConstants(BinaryOperator &I, Value *Op, Value *A, Value *B, Value *C)
This helper function folds:
static Constant * SubOne(Constant *C)
Subtract one from a Constant.
static unsigned getTypeOfMaskedICmp(Value *A, Value *B, Value *C, ICmpInst::Predicate SCC)
Return the set of pattern classes (from MaskedICmpType) that (icmp SCC (A & B), C) satisfies...
0 0 0 0 Always false (always folded)
A wrapper class for inspecting calls to intrinsic functions.
static Constant * getXor(Constant *C1, Constant *C2)
Value * FoldOrOfFCmps(FCmpInst *LHS, FCmpInst *RHS)
Optimize (fcmp)|(fcmp).