24 #define DEBUG_TYPE "instcombine" 30 "Unexpected FCmp predicate!");
70 "Unexpected FCmp predicate!");
99 if (!OldLHS->hasOneUse() && !OldRHS->
hasOneUse())
104 if (!OldLHS->hasOneUse())
141 if ((AddRHS & (AndRHSV - 1)).isNullValue()) {
146 if ((AddRHS & AndRHSV).isNullValue()) {
151 Value *NewAnd = Builder.CreateAnd(X, AndRHS);
153 return BinaryOperator::CreateXor(NewAnd, AndRHS);
167 bool isSigned,
bool Inside) {
169 "Lo is not <= Hi in range emission code!");
188 return Builder.CreateICmp(Pred, VMinusLo, HiMinusLo);
240 bool IsBPow2 = (BCst && !BCst->isZero() && BCst->getValue().isPowerOf2());
241 unsigned MaskVal = 0;
242 if (CCst && CCst->isZero()) {
332 Value *L11, *L12, *L21, *L22;
335 L21 = L22 = L1 =
nullptr;
360 if (R11 == L11 || R11 == L12 || R11 == L21 || R11 == L22) {
363 }
else if (R12 == L11 || R12 == L12 || R12 == L21 || R12 == L22) {
380 if (R11 == L11 || R11 == L12 || R11 == L21 || R11 == L22) {
385 }
else if (R12 == L11 || R12 == L12 || R12 == L21 || R12 == L22) {
404 if (R11 == L11 || R11 == L12 || R11 == L21 || R11 == L22) {
409 }
else if (R12 == L11 || R12 == L12 || R12 == L21 || R12 == L22) {
424 }
else if (L12 == A) {
427 }
else if (L21 == A) {
430 }
else if (L22 == A) {
517 return Builder.
CreateICmp(NewCC, NewAnd, NewMaskedValue);
524 return (C1->
getValue() & C2->getValue()) == C2->getValue();
533 if (!IsSubSetOrEqual(BCst, DCst) && !IsSuperSetOrEqual(BCst, DCst))
545 if (IsSubSetOrEqual(BCst, DCst))
556 if (IsSuperSetOrEqual(BCst, DCst))
561 assert(IsSubSetOrEqual(BCst, DCst) &&
"Precondition due to above code");
578 unsigned LHSMask,
unsigned RHSMask,
581 "Expected equality predicates for masked type of icmps.");
593 LHS, RHS, IsAnd, A, B, C, D, E,
594 PredL, PredR, Builder)) {
597 }
else if ((LHSMask & BMask_Mixed) && (RHSMask & Mask_NotAllZeros)) {
599 RHS, LHS, IsAnd, A, D, E, B, C,
600 PredR, PredL, Builder)) {
611 Value *A =
nullptr, *
B =
nullptr, *
C =
nullptr, *
D =
nullptr, *
E =
nullptr;
618 "Expected equality predicates for masked type of icmps.");
619 unsigned LHSMask = MaskPair->first;
620 unsigned RHSMask = MaskPair->second;
621 unsigned Mask = LHSMask & RHSMask;
626 LHS, RHS, IsAnd, A,
B,
C,
D,
E, PredL, PredR, LHSMask, RHSMask,
660 return Builder.
CreateICmp(NewCC, NewAnd, Zero);
667 return Builder.
CreateICmp(NewCC, NewAnd, NewOr);
697 else if (NewMask == DCst->
getValue())
710 else if (NewMask == DCst->
getValue())
745 return Builder.
CreateICmp(NewCC, NewAnd, NewOr2);
792 default:
return nullptr;
803 return Builder.CreateICmp(NewPred, Input, RangeEnd);
814 const APInt *C1, *C2;
832 APInt Xor = *C1 ^ *C2;
849 if (*C1 == *C2 - 1) {
877 if (!LHSC || !RHSC || !LHSC->
isZero() || !RHSC->isZero())
883 if (A == D || B == D)
892 Value *Masked = Builder.CreateAnd(A, Mask);
894 return Builder.CreateICmp(NewPred, Masked, Mask);
937 auto tryToMatchSignedTruncationCheck = [](
ICmpInst *ICmp,
Value *&
X,
938 APInt &SignBitMask) ->
bool {
940 const APInt *I01, *I1;
955 if (tryToMatchSignedTruncationCheck(ICmp1, X1, HighestBit))
957 else if (tryToMatchSignedTruncationCheck(ICmp0, X1, HighestBit))
962 assert(HighestBit.
isPowerOf2() &&
"expected to be power of two (non-zero)");
966 APInt &UnsetBitsMask) ->
bool {
970 Pred,
X, UnsetBitsMask,
978 UnsetBitsMask = *
Mask;
987 if (!tryToDecompose(OtherICmp, X0, UnsetBitsMask))
1005 APInt SignBitsMask = ~(HighestBit - 1U);
1012 if (!UnsetBitsMask.
isSubsetOf(SignBitsMask)) {
1013 APInt OtherHighestBit = (~UnsetBitsMask) + 1U;
1022 CxtI.
getName() +
".simplified");
1030 if (
Value *V = foldAndOrOfICmpsOfAndWithPow2(LHS, RHS,
true, CxtI))
1054 if (
Value *V = simplifyRangeCheck(LHS, RHS,
false))
1058 if (
Value *V = simplifyRangeCheck(RHS, LHS,
false))
1074 if (LHSC == RHSC && PredL == PredR) {
1080 Value *NewOr = Builder.CreateOr(LHS0, RHS0);
1081 return Builder.CreateICmp(PredL, NewOr, LHSC);
1091 ConstantInt *AndC, *SmallC =
nullptr, *BigC =
nullptr;
1105 if (SmallC && BigC) {
1111 if ((Low & AndC->
getValue()).isNullValue() &&
1112 (Low & BigC->getValue()).isNullValue()) {
1113 Value *NewAnd = Builder.CreateAnd(V, Low | AndC->
getValue());
1116 return Builder.CreateICmp(PredL, NewAnd, NewVal);
1141 ShouldSwap = LHSC->
getValue().
sgt(RHSC->getValue());
1143 ShouldSwap = LHSC->
getValue().
ugt(RHSC->getValue());
1157 assert(LHSC != RHSC &&
"Compares not folded above?");
1167 if (LHSC ==
SubOne(RHSC))
1168 return Builder.CreateICmpULT(LHS0, LHSC);
1170 return insertRangeTest(LHS0, LHSC->
getValue() + 1, RHSC->getValue(),
1174 if (LHSC ==
SubOne(RHSC))
1175 return Builder.CreateICmpSLT(LHS0, LHSC);
1187 if (RHSC ==
AddOne(LHSC))
1188 return Builder.CreateICmp(PredL, LHS0, RHSC);
1191 return insertRangeTest(LHS0, LHSC->
getValue() + 1, RHSC->getValue(),
1200 if (RHSC ==
AddOne(LHSC))
1201 return Builder.CreateICmp(PredL, LHS0, RHSC);
1204 return insertRangeTest(LHS0, LHSC->
getValue() + 1, RHSC->getValue(),
true,
1218 if (LHS0 == RHS1 && RHS0 == LHS1) {
1238 if (LHS0 == RHS0 && LHS1 == RHS1) {
1241 unsigned NewPred = IsAnd ? FCmpCodeL & FCmpCodeR : FCmpCodeL | FCmpCodeR;
1256 return Builder.CreateFCmp(PredL, LHS0, RHS0);
1268 assert((Opcode == Instruction::And || Opcode == Instruction::Or) &&
1269 "Trying to match De Morgan's Laws with something other than and/or");
1272 Opcode = (Opcode == Instruction::And) ? Instruction::Or : Instruction::And;
1286 bool InstCombiner::shouldOptimizeCast(
CastInst *CI) {
1295 if (
const auto *PrecedingCI = dyn_cast<CastInst>(CastSrc))
1296 if (isEliminableCastPair(PrecedingCI, CI))
1321 if (ZextTruncC == C) {
1324 return new ZExtInst(NewOp, DestTy);
1331 if (SextTruncC == C) {
1334 return new SExtInst(NewOp, DestTy);
1375 if (shouldOptimizeCast(Cast0) && shouldOptimizeCast(Cast1)) {
1376 Value *NewOp = Builder.CreateBinOp(LogicOpc, Cast0Src, Cast1Src,
1382 if (LogicOpc == Instruction::Xor)
1389 if (ICmp0 && ICmp1) {
1390 Value *Res = LogicOpc == Instruction::And ? foldAndOfICmps(ICmp0, ICmp1, I)
1391 : foldOrOfICmps(ICmp0, ICmp1, I);
1402 if (
Value *R = foldLogicOfFCmps(FCmp0, FCmp1, LogicOpc == Instruction::And))
1420 return BinaryOperator::CreateXor(A, B);
1426 if (Op0->hasOneUse() || Op1->
hasOneUse())
1444 if (Op0->hasOneUse() || Op1->
hasOneUse())
1455 return BinaryOperator::CreateXor(A, B);
1463 if (
auto *ScalarC = dyn_cast<ConstantInt>(C))
1464 return ScalarC->getZExtValue() < BitWidth;
1469 for (
unsigned i = 0; i != NumElts; ++i) {
1473 if (isa<UndefValue>(Elt))
1476 if (!CI || CI->getZExtValue() >= BitWidth)
1508 if (!isa<VectorType>(Ty) && !shouldChangeType(Ty, X->
getType()))
1515 if (Opc == Instruction::LShr || Opc == Instruction::Shl)
1522 Value *NewBO = Opc == Instruction::Sub ? Builder.CreateBinOp(Opc, NewC, X)
1523 : Builder.CreateBinOp(Opc, X, NewC);
1524 return new ZExtInst(Builder.CreateAnd(NewBO, X), Ty);
1532 SQ.getWithInstruction(&I)))
1533 return replaceInstUsesWith(I, V);
1535 if (SimplifyAssociativeOrCommutative(I))
1543 if (SimplifyDemandedInstructionBits(I))
1551 if (
Value *V = SimplifyUsingDistributiveLaws(I))
1552 return replaceInstUsesWith(I, V);
1555 return replaceInstUsesWith(I, V);
1573 Value *And = Builder.CreateAnd(X, Op1);
1575 return BinaryOperator::CreateXor(And, NewC);
1586 APInt Together = *C & *OrC;
1597 APInt NotAndMask(~(*C));
1602 Value *NewRHS = Builder.CreateAnd(Y, Op1, Y->
getName() +
".masked");
1608 Value *NewLHS = Builder.CreateAnd(X, Op1, X->
getName() +
".masked");
1615 if (
ConstantInt *AndRHS = dyn_cast<ConstantInt>(Op1)) {
1622 switch (Op0I->getOpcode()) {
1625 case Instruction::Xor:
1626 case Instruction::Or:
1627 case Instruction::Mul:
1629 case Instruction::Sub:
1636 Value *Op0LHS = Op0I->getOperand(0);
1637 if (isa<ZExtInst>(Op0LHS))
1638 BinOp = Builder.CreateBinOp(Op0I->getOpcode(),
X, TruncC1);
1640 BinOp = Builder.CreateBinOp(Op0I->getOpcode(), TruncC1,
X);
1642 auto *And = Builder.CreateAnd(BinOp, TruncC2);
1648 if (
ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1)))
1649 if (
Instruction *Res = OptAndOp(Op0I, Op0CI, AndRHS, I))
1662 Value *NewCast = Builder.CreateTrunc(X, I.
getType(),
"and.shrunk");
1665 return BinaryOperator::CreateAnd(NewCast, C3);
1673 if (
Instruction *FoldedLogic = foldBinOpIntoSelectOrPhi(I))
1683 return BinaryOperator::CreateAnd(Op0, Builder.CreateNot(B));
1686 return BinaryOperator::CreateAnd(Op1, Builder.CreateNot(B));
1692 return BinaryOperator::CreateAnd(Op0, Builder.CreateNot(C));
1698 return BinaryOperator::CreateAnd(Op1, Builder.CreateNot(C));
1706 return BinaryOperator::CreateAnd(A, B);
1714 return BinaryOperator::CreateAnd(A, B);
1721 if (
Value *Res = foldAndOfICmps(LHS, RHS, I))
1722 return replaceInstUsesWith(I, Res);
1728 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
1729 if (
Value *Res = foldAndOfICmps(LHS, Cmp, I))
1730 return replaceInstUsesWith(I, Builder.CreateAnd(Res, Y));
1731 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
1732 if (
Value *Res = foldAndOfICmps(LHS, Cmp, I))
1733 return replaceInstUsesWith(I, Builder.CreateAnd(Res, X));
1736 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
1737 if (
Value *Res = foldAndOfICmps(Cmp, RHS, I))
1738 return replaceInstUsesWith(I, Builder.CreateAnd(Res, Y));
1739 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
1740 if (
Value *Res = foldAndOfICmps(Cmp, RHS, I))
1741 return replaceInstUsesWith(I, Builder.CreateAnd(Res, X));
1747 if (
Value *Res = foldLogicOfFCmps(LHS, RHS,
true))
1748 return replaceInstUsesWith(I, Res);
1750 if (
Instruction *CastedAnd = foldCastedBitwiseLogic(I))
1766 assert(Or.
getOpcode() == Instruction::Or &&
"bswap requires an 'or'");
1771 Op0 =
Ext->getOperand(0);
1774 Op1 =
Ext->getOperand(0);
1799 if (!OrOfOrs && !OrOfShifts && !OrOfAnds && !OrOfAndAndSh)
1808 for (
auto *Inst : Insts)
1824 Value *ShVal, *ShAmt0, *ShAmt1;
1829 auto ShiftOpcode0 = cast<BinaryOperator>(Or0)->
getOpcode();
1830 auto ShiftOpcode1 = cast<BinaryOperator>(Or1)->
getOpcode();
1831 if (ShiftOpcode0 == ShiftOpcode1)
1836 auto matchShiftAmount = [](
Value *L,
Value *R,
unsigned Width) ->
Value * {
1840 unsigned Mask = Width - 1;
1848 Value *ShAmt = matchShiftAmount(ShAmt0, ShAmt1, Width);
1849 bool SubIsOnLHS =
false;
1851 ShAmt = matchShiftAmount(ShAmt1, ShAmt0, Width);
1857 bool IsFshl = (!SubIsOnLHS && ShiftOpcode0 == BinaryOperator::Shl) ||
1858 (SubIsOnLHS && ShiftOpcode1 == BinaryOperator::Shl);
1867 for (
unsigned i = 0; i != NumElts; ++i) {
1870 if (!EltC1 || !EltC2)
1934 return Builder.CreateXor(Cond, AConst);
1948 if (
Value *Cond = getSelectCondition(A, B)) {
1952 Value *BitcastC = Builder.CreateBitCast(C, A->
getType());
1953 Value *BitcastD = Builder.CreateBitCast(D, A->
getType());
1954 Value *
Select = Builder.CreateSelect(Cond, BitcastC, BitcastD);
1955 return Builder.CreateBitCast(Select, OrigType);
1966 if (
Value *V = foldAndOrOfICmpsOfAndWithPow2(LHS, RHS,
false, CxtI))
1987 LHSC->
getType() == RHSC->getType() &&
1988 LHSC->
getValue() == (RHSC->getValue())) {
1993 Value *LAddOpnd, *RAddOpnd;
2001 if (LAddOpnd == RAddOpnd && DiffC.
isPowerOf2()) {
2012 APInt LowRangeDiff = RRangeLow ^ LRangeLow;
2013 APInt HighRangeDiff = RRangeHigh ^ LRangeHigh;
2014 APInt RangeDiff = LRangeLow.
sgt(RRangeLow) ? LRangeLow - RRangeLow
2015 : RRangeLow - LRangeLow;
2017 if (LowRangeDiff.
isPowerOf2() && LowRangeDiff == HighRangeDiff &&
2021 Value *NewAnd = Builder.CreateAnd(LAddOpnd, MaskC);
2022 Value *NewAdd = Builder.CreateAdd(NewAnd, MaxAddC);
2023 return Builder.CreateICmp(LHS->
getPredicate(), NewAdd, LHSC);
2052 Value *A =
nullptr, *B =
nullptr;
2070 return Builder.CreateICmp(
2076 if (
Value *V = simplifyRangeCheck(LHS, RHS,
true))
2080 if (
Value *V = simplifyRangeCheck(RHS, LHS,
true))
2090 if (LHSC == RHSC && PredL == PredR) {
2093 Value *NewOr = Builder.CreateOr(LHS0, RHS0);
2094 return Builder.CreateICmp(PredL, NewOr, LHSC);
2104 return Builder.CreateICmpULE(LHS0, LHSC);
2127 ShouldSwap = LHSC->
getValue().
sgt(RHSC->getValue());
2129 ShouldSwap = LHSC->
getValue().
ugt(RHSC->getValue());
2143 assert(LHSC != RHSC &&
"Compares not folded above?");
2167 assert(!RHSC->isMaxValue(
false) &&
"Missed icmp simplification");
2168 return insertRangeTest(LHS0, LHSC->
getValue(), RHSC->getValue() + 1,
2179 assert(!RHSC->isMaxValue(
true) &&
"Missed icmp simplification");
2180 return insertRangeTest(LHS0, LHSC->
getValue(), RHSC->getValue() + 1,
true,
2193 SQ.getWithInstruction(&I)))
2194 return replaceInstUsesWith(I, V);
2196 if (SimplifyAssociativeOrCommutative(I))
2204 if (SimplifyDemandedInstructionBits(I))
2212 if (
Value *V = SimplifyUsingDistributiveLaws(I))
2213 return replaceInstUsesWith(I, V);
2216 return replaceInstUsesWith(I, V);
2218 if (
Instruction *FoldedLogic = foldBinOpIntoSelectOrPhi(I))
2233 Value *Or = Builder.CreateOr(X, Y);
2245 Value *V1 =
nullptr, *
V2 =
nullptr;
2246 if ((C1->
getValue() & C2->getValue()).isNullValue()) {
2254 return BinaryOperator::CreateAnd(A,
2255 Builder.getInt(C1->
getValue()|C2->getValue()));
2262 return BinaryOperator::CreateAnd(B,
2263 Builder.getInt(C1->
getValue()|C2->getValue()));
2271 (C4->getValue() & ~C2->getValue()).isNullValue()) {
2273 return BinaryOperator::CreateAnd(
V2,
2274 Builder.getInt(C1->
getValue()|C2->getValue()));
2278 if (C1->
getValue() == ~C2->getValue()) {
2283 return BinaryOperator::CreateOr(Builder.CreateAnd(X, C1),
B);
2286 return BinaryOperator::CreateOr(Builder.CreateAnd(X, C2), A);
2290 return BinaryOperator::CreateXor(Builder.CreateAnd(X, C1),
B);
2293 return BinaryOperator::CreateXor(Builder.CreateAnd(X, C2), A);
2300 if (Op0->
hasOneUse() || Op1->hasOneUse()) {
2302 if (
Value *V = matchSelectFromAndOr(A, C, B, D))
2303 return replaceInstUsesWith(I, V);
2304 if (
Value *V = matchSelectFromAndOr(A, C, D, B))
2305 return replaceInstUsesWith(I, V);
2306 if (
Value *V = matchSelectFromAndOr(C, A, B, D))
2307 return replaceInstUsesWith(I, V);
2308 if (
Value *V = matchSelectFromAndOr(C, A, D, B))
2309 return replaceInstUsesWith(I, V);
2310 if (
Value *V = matchSelectFromAndOr(B, D, A, C))
2311 return replaceInstUsesWith(I, V);
2312 if (
Value *V = matchSelectFromAndOr(B, D, C, A))
2313 return replaceInstUsesWith(I, V);
2314 if (
Value *V = matchSelectFromAndOr(D, B, A, C))
2315 return replaceInstUsesWith(I, V);
2316 if (
Value *V = matchSelectFromAndOr(D, B, C, A))
2317 return replaceInstUsesWith(I, V);
2324 return BinaryOperator::CreateOr(Op0, C);
2329 return BinaryOperator::CreateOr(Op1, C);
2333 return BinaryOperator::CreateOr(Op1, Builder.CreateAnd(A, C));
2339 bool SwappedForXor =
false;
2342 SwappedForXor =
true;
2349 if (Op0 == A || Op0 == B)
2350 return BinaryOperator::CreateOr(A, B);
2354 return BinaryOperator::CreateOr(A, B);
2357 Value *Not = Builder.CreateNot(B, B->
getName() +
".not");
2358 return BinaryOperator::CreateOr(Not, Op0);
2361 Value *Not = Builder.CreateNot(A, A->
getName() +
".not");
2362 return BinaryOperator::CreateOr(Not, Op0);
2370 if ((Op0 == B->getOperand(0) || Op0 == B->getOperand(1)) &&
2371 Op1->hasOneUse() && (B->getOpcode() == Instruction::Or ||
2372 B->getOpcode() == Instruction::Xor)) {
2373 Value *NotOp = Op0 == B->getOperand(0) ? B->getOperand(1) :
2375 Value *Not = Builder.CreateNot(NotOp, NotOp->
getName() +
".not");
2376 return BinaryOperator::CreateOr(Not, Op0);
2386 if (
Value *Res = foldOrOfICmps(LHS, RHS, I))
2387 return replaceInstUsesWith(I, Res);
2393 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
2394 if (
Value *Res = foldOrOfICmps(LHS, Cmp, I))
2395 return replaceInstUsesWith(I, Builder.CreateOr(Res, Y));
2396 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
2397 if (
Value *Res = foldOrOfICmps(LHS, Cmp, I))
2398 return replaceInstUsesWith(I, Builder.CreateOr(Res, X));
2401 if (
auto *Cmp = dyn_cast<ICmpInst>(X))
2402 if (
Value *Res = foldOrOfICmps(Cmp, RHS, I))
2403 return replaceInstUsesWith(I, Builder.CreateOr(Res, Y));
2404 if (
auto *Cmp = dyn_cast<ICmpInst>(Y))
2405 if (
Value *Res = foldOrOfICmps(Cmp, RHS, I))
2406 return replaceInstUsesWith(I, Builder.CreateOr(Res, X));
2412 if (
Value *Res = foldLogicOfFCmps(LHS, RHS,
false))
2413 return replaceInstUsesWith(I, Res);
2415 if (
Instruction *CastedOr = foldCastedBitwiseLogic(I))
2432 if (Op0->
hasOneUse() && !isa<ConstantInt>(Op1) &&
2434 Value *Inner = Builder.CreateOr(A, Op1);
2436 return BinaryOperator::CreateOr(Inner, CI);
2443 Value *X =
nullptr, *Y =
nullptr;
2444 if (Op0->
hasOneUse() && Op1->hasOneUse() &&
2447 Value *orTrue = Builder.CreateOr(A, C);
2448 Value *orFalse = Builder.CreateOr(B, D);
2501 if (!Op0->hasOneUse() && !Op1->
hasOneUse())
2549 return Builder.CreateICmpSLT(Builder.CreateXor(LHS0, RHS0), Zero);
2558 return Builder.CreateICmpSGT(Builder.CreateXor(LHS0, RHS0), MinusOne);
2573 if (OrICmp == LHS && AndICmp == RHS && RHS->
hasOneUse()) {
2576 return Builder.CreateAnd(LHS, RHS);
2578 if (OrICmp == RHS && AndICmp == LHS && LHS->
hasOneUse()) {
2581 return Builder.CreateAnd(LHS, RHS);
2618 return BinaryOperator::CreateXor(NewA, X);
2627 return BinaryOperator::CreateOr(LHS, RHS);
2656 return BinaryOperator::CreateXor(NotX, Y, I.
getName() +
".demorgan");
2664 SQ.getWithInstruction(&I)))
2665 return replaceInstUsesWith(I, V);
2667 if (SimplifyAssociativeOrCommutative(I))
2677 if (
Value *V = SimplifyUsingDistributiveLaws(I))
2678 return replaceInstUsesWith(I, V);
2682 if (SimplifyDemandedInstructionBits(I))
2686 return replaceInstUsesWith(I, V);
2697 return BinaryOperator::CreateOr(Op0, Op1);
2707 Value *NotY = Builder.CreateNot(Y, Y->
getName() +
".not");
2708 return BinaryOperator::CreateOr(X, NotY);
2713 Value *NotY = Builder.CreateNot(Y, Y->
getName() +
".not");
2714 return BinaryOperator::CreateAnd(X, NotY);
2723 if (NotVal->
getOpcode() == Instruction::And ||
2724 NotVal->
getOpcode() == Instruction::Or) {
2734 if (NotVal->
getOpcode() == Instruction::And)
2735 return BinaryOperator::CreateOr(NotX, NotY);
2736 return BinaryOperator::CreateAnd(NotX, NotY);
2742 if (isa<Constant>(X) || NotVal->
hasOneUse())
2747 return BinaryOperator::CreateAShr(X, Y);
2790 return replaceInstUsesWith(I, Op0);
2801 return BinaryOperator::CreateSub(NewC, X);
2813 Worklist.Add(cast<Instruction>(Op0));
2821 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(Op1)) {
2823 if (
ConstantInt *Op0CI = dyn_cast<ConstantInt>(Op0I->getOperand(1))) {
2824 if (Op0I->getOpcode() == Instruction::LShr) {
2829 if (Op0I->hasOneUse() &&
2836 FoldConst ^= C3->getValue();
2840 cast<Instruction>(Opnd0)->setDebugLoc(I.
getDebugLoc());
2843 return BinaryOperator::CreateXor(Opnd0, FoldVal);
2850 if (
Instruction *FoldedLogic = foldBinOpIntoSelectOrPhi(I))
2856 return BinaryOperator::CreateAnd(X, Builder.CreateNot(Op0));
2860 return BinaryOperator::CreateAnd(X, Builder.CreateNot(Op1));
2865 return BinaryOperator::CreateAnd(Op0, Builder.CreateNot(X));
2873 return BinaryOperator::CreateAnd(Op1, Builder.CreateNot(X));
2879 return BinaryOperator::CreateXor(
2880 Builder.CreateAnd(Builder.CreateNot(A),
C), B);
2885 return BinaryOperator::CreateXor(
2886 Builder.CreateAnd(Builder.CreateNot(B),
C), A);
2891 return BinaryOperator::CreateOr(A, B);
2895 return BinaryOperator::CreateOr(A, B);
2903 if (
auto *LHS = dyn_cast<ICmpInst>(I.
getOperand(0)))
2904 if (
auto *RHS = dyn_cast<ICmpInst>(I.
getOperand(1)))
2905 if (
Value *V = foldXorOfICmps(LHS, RHS))
2906 return replaceInstUsesWith(I, V);
2908 if (
Instruction *CastedXor = foldCastedBitwiseLogic(I))
2929 auto *
Add = cast<BinaryOperator>(Op0);
2930 Value *Neg = Builder.CreateNeg(A,
"",
Add->hasNoUnsignedWrap(),
2931 Add->hasNoSignedWrap());
2954 Value *NotY = Builder.CreateNot(RHS);
2962 Value *NotX = Builder.CreateNot(LHS);
2971 Value *NotLHS = Builder.CreateNot(LHS);
2972 Value *NotRHS = Builder.CreateNot(RHS);
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
Constant * getPredForICmpCode(unsigned Code, bool Sign, Type *OpTy, CmpInst::Predicate &Pred)
This is the complement of getICmpCode.
cst_pred_ty< is_nonnegative > m_NonNegative()
Match an integer or vector of nonnegative values.
static ConstantInt * getFalse(LLVMContext &Context)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
Type * getSrcTy() const
Return the source type, as a convenience.
static bool IsFreeToInvert(Value *V, bool WillInvertAllUses)
Return true if the specified value is free to invert (apply ~ to).
class_match< CmpInst > m_Cmp()
Matches any compare instruction and ignore it.
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...
Instruction * visitXor(BinaryOperator &I)
Value * CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
static Value * foldSignedTruncationCheck(ICmpInst *ICmp0, ICmpInst *ICmp1, Instruction &CxtI, InstCombiner::BuilderTy &Builder)
General pattern: X & Y.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
Instruction * visitOr(BinaryOperator &I)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
This class represents lattice values for constants.
BinaryOps getOpcode() const
BinaryOp_match< LHS, RHS, Instruction::Xor, true > m_c_Xor(const LHS &L, const RHS &R)
Matches an Xor with LHS and RHS in either order.
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
bool decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate &Pred, Value *&X, APInt &Mask, bool LookThroughTrunc=true)
Decompose an icmp into the form ((X & Mask) pred 0) if possible.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static unsigned getFCmpCode(FCmpInst::Predicate CC)
Similar to getICmpCode but for FCmpInst.
This class represents zero extension of integer types.
unsigned getICmpCode(const ICmpInst *ICI, bool InvertPred=false)
Encode a icmp predicate into a three bit mask.
BinaryOp_match< LHS, RHS, Instruction::Mul > m_Mul(const LHS &L, const RHS &R)
static bool areInverseVectorBitmasks(Constant *C1, Constant *C2)
If all elements of two constant vectors are 0/-1 and inverses, return true.
APInt zext(unsigned width) const
Zero extend to a new width.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
class_match< Constant > m_Constant()
Match an arbitrary Constant and ignore it.
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
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)
1 1 1 0 True if unordered or not equal
bool sgt(const APInt &RHS) const
Signed greather than comparison.
MaskedICmpType
Classify (icmp eq (A & B), C) and (icmp ne (A & B), C) as matching patterns that can be simplified...
static Value * SimplifyBSwap(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
Transform BITWISE_OP(BSWAP(A),BSWAP(B)) or BITWISE_OP(BSWAP(A), Constant) to BSWAP(BITWISE_OP(A, B))
This class represents a sign extension of integer types.
bool isVectorTy() const
True if this is an instance of VectorType.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
static bool isBitwiseLogicOp(unsigned Opcode)
Determine if the Opcode is and/or/xor.
Value * SimplifyOrInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an Or, fold the result or return null.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
Value * CreateNot(Value *V, const Twine &Name="")
1 0 0 1 True if unordered or equal
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
bool match(Val *V, const Pattern &P)
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)
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, bool UseInstrInfo=true)
Return true if the given value is known to have exactly one bit set when defined. ...
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
This is the base class for all instructions that perform data casts.
static Value * getNewICmpValue(unsigned Code, bool Sign, Value *LHS, Value *RHS, InstCombiner::BuilderTy &Builder)
This is the complement of getICmpCode, which turns an opcode and two operands into either a constant ...
APInt shl(unsigned shiftAmt) const
Left-shift function.
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
bool isIntegerTy() const
True if this is an instance of IntegerType.
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 MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if 'V & Mask' is known to be zero.
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Value * foldLogOpOfMaskedICmps_NotAllZeros_BMask_Mixed(ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, Value *A, Value *B, Value *C, Value *D, Value *E, ICmpInst::Predicate PredL, ICmpInst::Predicate PredR, llvm::InstCombiner::BuilderTy &Builder)
Try to fold (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E) into a single (icmp(A & X) ==/!= Y)...
static Value * peekThroughBitcast(Value *V, bool OneUseOnly=false)
Return the source operand of a potentially bitcasted value while optionally checking if it has one us...
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Type * getType() const
All values are typed, get the type of this value.
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.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
static Value * foldAndOrOfEqualityCmpsWithConstants(ICmpInst *LHS, ICmpInst *RHS, bool JoinedByAnd, InstCombiner::BuilderTy &Builder)
const APInt & getValue() const
Return the constant as an APInt value reference.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
cstfp_pred_ty< is_pos_zero_fp > m_PosZeroFP()
Match a floating-point positive zero.
bool isMinusOne() const
This function will return true iff every bit in this constant is set to true.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
void takeName(Value *V)
Transfer the name from V to this value.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
static BinaryOperator * CreateAdd(Value *S1, Value *S2, const Twine &Name, Instruction *InsertBefore, Value *FlagsOp)
Value * getOperand(unsigned i) const
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="")
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Value * CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", MDNode *FPMathTag=nullptr)
OneUse_match< T > m_OneUse(const T &SubPattern)
static Optional< std::pair< unsigned, unsigned > > getMaskedTypeForICmpPair(Value *&A, Value *&B, Value *&C, Value *&D, Value *&E, ICmpInst *LHS, ICmpInst *RHS, ICmpInst::Predicate &PredL, ICmpInst::Predicate &PredR)
Handle (icmp(A & B) ==/!= C) &/| (icmp(A & D) ==/!= E).
unsigned ComputeNumSignBits(const Value *Op, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return the number of times the sign bit of the register is replicated into the other bits...
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
static Instruction * foldOrToXor(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
bool isAllOnesValue() const
Determine if all bits are set.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
bool hasNUses(unsigned N) const
Return true if this Value has exactly N users.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
static unsigned getMaskedICmpType(Value *A, Value *B, Value *C, ICmpInst::Predicate Pred)
Return the set of patterns (from MaskedICmpType) that (icmp SCC (A & B), C) satisfies.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
static Instruction * matchRotate(Instruction &Or)
Transform UB-safe variants of bitwise rotate to the funnel shift intrinsic.
static bool canNarrowShiftAmt(Constant *C, unsigned BitWidth)
Return true if a constant shift amount is always less than the specified bit-width.
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 ult(const APInt &RHS) const
Unsigned less than comparison.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
static Constant * getAnd(Constant *C1, Constant *C2)
bool isOneValue() const
Determine if this is a value of 1.
cst_pred_ty< is_all_ones > m_AllOnes()
Match an integer or vector with all bits set.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
0 1 1 1 True if ordered (no nans)
class_match< BinaryOperator > m_BinOp()
Match an arbitrary binary operation and ignore it.
static unsigned conjugateICmpMask(unsigned Mask)
Convert an analysis of a masked ICmp into its equivalent if all boolean operations had the opposite s...
bool isIntN(unsigned N) const
Check if this APInt has an N-bits unsigned integer value.
CmpInst::Predicate getInverseMinMaxPred(SelectPatternFlavor SPF)
Return the canonical inverse comparison predicate for the specified minimum/maximum flavor...
static Constant * getNot(Constant *C)
static Constant * getAllOnesValue(Type *Ty)
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 ...
static Instruction * matchDeMorgansLaws(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
Match De Morgan's Laws: (~A & ~B) == (~(A | B)) (~A | ~B) == (~(A & B))
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.
deferredval_ty< Value > m_Deferred(Value *const &V)
A commutative-friendly version of m_Specific().
APInt lshr(unsigned shiftAmt) const
Logical right-shift function.
Instruction * visitAnd(BinaryOperator &I)
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
CastClass_match< OpTy, Instruction::SExt > m_SExt(const OpTy &Op)
Matches SExt.
static Value * foldLogOpOfMaskedICmpsAsymmetric(ICmpInst *LHS, ICmpInst *RHS, bool IsAnd, Value *A, Value *B, Value *C, Value *D, Value *E, ICmpInst::Predicate PredL, ICmpInst::Predicate PredR, unsigned LHSMask, unsigned RHSMask, llvm::InstCombiner::BuilderTy &Builder)
Try to fold (icmp(A & B) ==/!= 0) &/| (icmp(A & D) ==/!= E) into a single (icmp(A & X) ==/!= Y), where the left-hand ...
0 0 1 0 True if ordered and greater than
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
This is the shared class of boolean and integer constants.
SelectPatternFlavor Flavor
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
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
SelectPatternFlavor
Specific patterns of select instructions we can match.
LLVM_NODISCARD T pop_back_val()
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
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.
Predicate getSignedPredicate() const
For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
Type * getDestTy() const
Return the destination type, as a convenience.
static ConstantInt * getTrue(LLVMContext &Context)
void setPredicate(Predicate P)
Set the predicate for this instruction to the specified value.
void setOperand(unsigned i, Value *Val)
BinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub > m_Neg(const ValTy &V)
Matches a 'Neg' as 'sub 0, V'.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
unsigned getVectorNumElements() const
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Class for arbitrary precision integers.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
static Instruction * sinkNotIntoXor(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
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.
void removeFromParent()
This method unlinks 'this' from the containing basic block, but does not delete it.
static Instruction * foldAndToXor(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
Value * SimplifyAndInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an And, fold the result or return null.
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)...
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 ...
bool ugt(const APInt &RHS) const
Unsigned greather than comparison.
Predicate getPredicate() const
Return the predicate for this instruction.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
static bool isMinOrMax(SelectPatternFlavor SPF)
When implementing this min/max pattern as fcmp; select, does the fcmp have to be ordered?
unsigned greater or equal
StringRef getName() const
Return a constant reference to the value's name.
bool isEquality() const
Return true if this predicate is either EQ or NE.
static Constant * getOr(Constant *C1, Constant *C2)
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
0 1 1 0 True if ordered and operands are unequal
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Value * SimplifyXorInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an Xor, fold the result or return null.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
1 0 1 0 True if unordered or greater than
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
bool isMinValue() const
Determine if this is the smallest unsigned value.
Value * SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
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.
match_combine_and< LTy, RTy > m_CombineAnd(const LTy &L, const RTy &R)
Combine two pattern matchers matching L && R.
static Instruction * visitMaskedMerge(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
If we have a masked merge, in the canonical form of: (assuming that A only has one use...
bool hasOneUse() const
Return true if there is exactly one user of this value.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
bool isNonNegative() const
Returns true if this value is known to be non-negative.
Value * simplifyRangeCheck(ICmpInst *Cmp0, ICmpInst *Cmp1, bool Inverted)
Try to fold a signed range checked with lower bound 0 to an unsigned icmp.
bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction *> &InsertedInsts)
Try to match a bswap or bitreverse idiom.
specific_intval m_SpecificInt(uint64_t V)
Match a specific integer value or vector with all elements equal to the value.
0 0 1 1 True if ordered and greater than or equal
static Instruction * foldLogicCastConstant(BinaryOperator &Logic, CastInst *Cast, InstCombiner::BuilderTy &Builder)
Fold {and,or,xor} (cast X), C.
static Constant * SubOne(Constant *C)
Subtract one from a Constant.
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 Instruction * foldXorToXor(BinaryOperator &I, InstCombiner::BuilderTy &Builder)
A ^ B can be specified using other logic ops in a variety of patterns.
BinaryOp_match< ValTy, cst_pred_ty< is_all_ones >, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
bool isNullValue() const
Determine if all bits are clear.
0 0 0 0 Always false (always folded)
CmpClass_match< LHS, RHS, ICmpInst, ICmpInst::Predicate > m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R)
static Constant * getXor(Constant *C1, Constant *C2)