51#define DEBUG_TYPE "instcombine"
89 bool IsAbsorbingValue =
false;
101 IsAbsorbingValue =
true;
114 if (IsAbsorbingValue) {
129 if (!FPO->hasNoSignedZeros() &&
157 const APInt *SelTC, *SelFC;
166 const APInt &TC = *SelTC;
167 const APInt &FC = *SelFC;
168 if (!TC.
isZero() && !FC.isZero()) {
180 Constant *TCC = ConstantInt::get(SelType, TC);
181 Constant *FCC = ConstantInt::get(SelType, FC);
182 Constant *MaskC = ConstantInt::get(SelType, AndMask);
183 for (
auto Opc : {Instruction::Or, Instruction::Xor, Instruction::Add,
188 V = Builder.CreateAnd(
V, MaskC);
189 return Builder.CreateBinOp(
Opc, TCC,
V);
203 unsigned ValZeros = ValC.
logBase2();
204 unsigned AndZeros = AndMask.
logBase2();
205 bool ShouldNotVal = !TC.
isZero();
206 bool NeedShift = ValZeros != AndZeros;
213 if (CreateAnd + ShouldNotVal + NeedShift + NeedZExtTrunc >
219 V = Builder.CreateAnd(
V, ConstantInt::get(
V->getType(), AndMask));
223 if (ValZeros > AndZeros) {
224 V = Builder.CreateZExtOrTrunc(
V, SelType);
225 V = Builder.CreateShl(
V, ValZeros - AndZeros);
226 }
else if (ValZeros < AndZeros) {
227 V = Builder.CreateLShr(
V, AndZeros - ValZeros);
228 V = Builder.CreateZExtOrTrunc(
V, SelType);
230 V = Builder.CreateZExtOrTrunc(
V, SelType);
236 V = Builder.CreateXor(
V, ValC);
252 switch (
I->getOpcode()) {
253 case Instruction::Add:
254 case Instruction::FAdd:
255 case Instruction::Mul:
256 case Instruction::FMul:
257 case Instruction::And:
258 case Instruction::Or:
259 case Instruction::Xor:
261 case Instruction::Sub:
262 case Instruction::FSub:
263 case Instruction::FDiv:
264 case Instruction::Shl:
265 case Instruction::LShr:
266 case Instruction::AShr:
288 CondVTy->getElementCount() !=
300 if (TI->
getOpcode() != Instruction::BitCast &&
313 SI.getName() +
".v", &
SI);
318 Value *OtherOpT, *OtherOpF;
321 bool Swapped =
false) ->
Value * {
322 assert(!(Commute && Swapped) &&
323 "Commute and Swapped can't set at the same time");
328 MatchIsOpZero =
true;
333 MatchIsOpZero =
false;
338 if (!Commute && !Swapped)
347 MatchIsOpZero =
true;
352 MatchIsOpZero =
false;
368 FMF |=
SI.getFastMathFlags();
372 NewSelI->setFastMathFlags(FMF);
373 Instruction *NewFNeg = UnaryOperator::CreateFNeg(NewSel);
384 if (
TII && FII &&
TII->getIntrinsicID() == FII->getIntrinsicID()) {
386 if (
Value *MatchOp = getCommonOp(TI, FI,
true)) {
388 Builder.CreateSelect(
Cond, OtherOpT, OtherOpF,
"minmaxop", &
SI);
398 if (
TII->getIntrinsicID() == Intrinsic::ldexp) {
399 Value *LdexpVal0 =
TII->getArgOperand(0);
400 Value *LdexpExp0 =
TII->getArgOperand(1);
401 Value *LdexpVal1 = FII->getArgOperand(0);
402 Value *LdexpExp1 = FII->getArgOperand(1);
410 Cond, LdexpVal0, LdexpVal1,
"",
413 Cond, LdexpExp0, LdexpExp1,
"",
417 TII->getType(), Intrinsic::ldexp, {SelectVal, SelectExp}, FMF);
423 auto CreateCmpSel = [&](std::optional<CmpPredicate>
P,
432 SI.getName() +
".v", &
SI);
486 if (BO->getOpcode() == Instruction::SDiv ||
487 BO->getOpcode() == Instruction::SRem || MatchIsOpZero)
493 SI.getName() +
".v", &
SI);
494 Value *Op0 = MatchIsOpZero ? MatchOp : NewSI;
495 Value *Op1 = MatchIsOpZero ? NewSI : MatchOp;
504 Type *ElementType = TGEP->getSourceElementType();
506 ElementType, Op0, Op1, TGEP->getNoWrapFlags() & FGEP->getNoWrapFlags());
519 case Intrinsic::copysign:
538 std::optional<unsigned> DiffArgNo;
539 for (
unsigned I = 0,
E =
TII->arg_size();
I !=
E; ++
I) {
552 Value *TV =
TII->getArgOperand(*DiffArgNo);
555 if (
SI.getCondition()->getType()->isVectorTy() &&
567 Builder.CreateSelect(
SI.getCondition(), TV, FV,
SI.getName() +
".v", &
SI);
569 NewCall->copyIRFlags(
TII);
570 NewCall->andIRFlags(FII);
584 LHSIntrinsic->getIntrinsicID() != RHSIntrinsic->getIntrinsicID() ||
585 !LHSIntrinsic->hasOneUse() || !RHSIntrinsic->hasOneUse())
591 case Intrinsic::cttz:
592 case Intrinsic::ctlz: {
596 Value *TV = LHSIntrinsic->getArgOperand(0);
597 Value *FV = RHSIntrinsic->getArgOperand(0);
601 Value *NewCall =
Builder.CreateBinaryIntrinsic(IID, NewSel, NewPoisonFlag);
633 unsigned OpToFold = 0;
634 if ((SFO & 1) && FalseVal == TVI->getOperand(0))
636 else if ((SFO & 2) && FalseVal == TVI->getOperand(1))
644 FMF = FPO->getFastMathFlags();
646 TVI->getOpcode(), TVI->getType(),
true, FMF.
noSignedZeros());
647 Value *OOp = TVI->getOperand(2 - OpToFold);
653 (!OOpIsAPInt || !
isSelect01(
C->getUniqueInteger(), *OOpC)))
667 Value *NewSel =
Builder.CreateSelect(
SI.getCondition(), Swapped ?
C : OOp,
668 Swapped ? OOp :
C,
"", &
SI);
679 bool CanInferFiniteOperandsFromResult =
680 TVI->getOpcode() == Instruction::FAdd ||
681 TVI->getOpcode() == Instruction::FSub ||
682 TVI->getOpcode() == Instruction::FMul;
684 (CanInferFiniteOperandsFromResult &&
703 if (
Instruction *R = TryFoldSelectIntoOp(
SI, TrueVal, FalseVal,
false))
706 if (
Instruction *R = TryFoldSelectIntoOp(
SI, FalseVal, TrueVal,
true))
716 Value *CmpLHS = Cmp->getOperand(0);
717 Value *CmpRHS = Cmp->getOperand(1);
740 Builder.CreateBinaryIntrinsic(Intrinsic::smin, CmpRHS, CmpLHS);
741 return Builder.CreateNSWSub(CmpLHS,
SMin);
754 Value *CmpLHS = Cmp->getOperand(0);
755 Value *CmpRHS = Cmp->getOperand(1);
765 if (CmpRHS == TVal) {
778 return Builder.CreateBinaryIntrinsic(Intrinsic::smax, TVal, FVal);
784 return Builder.CreateBinaryIntrinsic(Intrinsic::smin, TVal, FVal);
790 return Builder.CreateBinaryIntrinsic(Intrinsic::umax, TVal, FVal);
800 return Builder.CreateBinaryIntrinsic(Intrinsic::umin, TVal, FVal);
819 unsigned NumReplaced = 1 +
Cond->hasOneUse();
821 Y = ConstantInt::get(
X->getType(), 1);
848 if (!
match(
A, TValPattern)) {
850 if (!
match(
A, TValPattern))
854 bool HasShift =
A !=
X;
856 NumReplaced += 1 + (HasShift &&
A->hasOneUse());
863 Constant *One = ConstantInt::get(SelType, 1);
864 Value *MaskB = HasShift ? Builder.CreateShl(One, Z) : One;
865 Value *FullMask = Builder.CreateOr(
Y, MaskB);
866 Value *MaskedX = Builder.CreateAnd(
X, FullMask);
867 Value *ICmpNeZero = Builder.CreateIsNotNull(MaskedX);
868 return new ZExtInst(ICmpNeZero, SelType);
897 C1->countLeadingZeros() !=
static_cast<unsigned>(C2->
getZExtValue()))
904 FI->setHasNoSignedWrap(
false);
905 FI->setHasNoUnsignedWrap(
false);
943 return Builder.CreateAShr(
X,
Y, IC->
getName(), IsExact);
971 const APInt &AndMask,
bool CreateAnd,
974 if (!TrueVal->getType()->isIntOrIntVectorTy())
977 unsigned C1Log = AndMask.
logBase2();
998 if (IdentityC ==
nullptr || !IdentityC->isNullValue())
1003 bool NeedShift = C1Log != C2Log;
1004 bool NeedZExtTrunc =
Y->getType()->getScalarSizeInBits() !=
1005 V->getType()->getScalarSizeInBits();
1012 if ((NeedShift + NeedXor + NeedZExtTrunc + CreateAnd) >
1018 V = Builder.CreateAnd(
V, ConstantInt::get(
V->getType(), AndMask));
1021 if (C2Log > C1Log) {
1022 V = Builder.CreateZExtOrTrunc(
V,
Y->getType());
1023 V = Builder.CreateShl(
V, C2Log - C1Log);
1024 }
else if (C1Log > C2Log) {
1025 V = Builder.CreateLShr(
V, C1Log - C2Log);
1026 V = Builder.CreateZExtOrTrunc(
V,
Y->getType());
1028 V = Builder.CreateZExtOrTrunc(
V,
Y->getType());
1031 V = Builder.CreateXor(
V, *C2);
1033 auto *Res = Builder.CreateBinOp(BinOp->
getOpcode(),
Y,
V);
1035 BO->copyIRFlags(BinOp);
1054 Constant *OrC = ConstantInt::get(Ty, *
C);
1055 Value *NewSel = Builder.CreateSelect(
Cond,
Zero, OrC,
"masksel", &Sel);
1056 return BinaryOperator::CreateOr(
T, NewSel);
1063 Constant *OrC = ConstantInt::get(Ty, *
C);
1064 Value *NewSel = Builder.CreateSelect(
Cond, OrC,
Zero,
"masksel", &Sel);
1065 return BinaryOperator::CreateOr(
F, NewSel);
1086 auto *CondVal =
SI.getCondition();
1087 auto *TrueVal =
SI.getTrueValue();
1088 auto *FalseVal =
SI.getFalseValue();
1138 FalseValI->getOperand(0) ==
Y
1140 : (FalseValI->getOperand(1) ==
Y ? 1 : 2),
1150 const Value *FalseVal,
1170 return Builder.CreateBinaryIntrinsic(Intrinsic::usub_sat,
A,
1171 ConstantInt::get(
A->getType(), 1));
1185 "Unexpected isUnsigned predicate!");
1191 bool IsNegative =
false;
1204 if (IsNegative && !TrueVal->hasOneUse() && !ICI->
hasOneUse())
1209 Value *Result = Builder.CreateBinaryIntrinsic(Intrinsic::usub_sat,
A,
B);
1211 Result = Builder.CreateNeg(Result);
1217 const Value *FalseVal,
1234 return Builder.CreateBinaryIntrinsic(
1243 const Value *TrueVal,
1244 const Value *FalseVal,
1262 Value *Cmp0 = Cmp->getOperand(0);
1263 Value *Cmp1 = Cmp->getOperand(1);
1283 return Builder.CreateBinaryIntrinsic(
1284 Intrinsic::uadd_sat, Cmp0, ConstantInt::get(Cmp0->
getType(), 1));
1294 return Builder.CreateBinaryIntrinsic(Intrinsic::uadd_sat, Cmp0,
1295 ConstantInt::get(Cmp0->
getType(), *
C));
1304 return Builder.CreateBinaryIntrinsic(Intrinsic::uadd_sat, Cmp0,
1305 ConstantInt::get(Cmp0->
getType(), *
C));
1314 return Builder.CreateBinaryIntrinsic(Intrinsic::uadd_sat, Cmp0,
1315 ConstantInt::get(Cmp0->
getType(), *
C));
1333 return Builder.CreateBinaryIntrinsic(Intrinsic::uadd_sat,
X,
Y);
1343 return Builder.CreateBinaryIntrinsic(
1353 return Builder.CreateBinaryIntrinsic(Intrinsic::uadd_sat, Cmp1,
Y);
1363 Value *Cmp0 = Cmp->getOperand(0);
1364 Value *Cmp1 = Cmp->getOperand(1);
1386 return Builder.CreateBinaryIntrinsic(
1387 Intrinsic::sadd_sat, Cmp0, ConstantInt::get(Cmp0->
getType(), 1));
1392 return Builder.CreateBinaryIntrinsic(
1393 Intrinsic::sadd_sat, Cmp0,
1411 Pred = Flipped->first;
1412 Cmp1 = Flipped->second;
1416 APInt Threshold = *SatC - *
C;
1420 return Builder.CreateBinaryIntrinsic(
1421 Intrinsic::sadd_sat, Cmp0, ConstantInt::get(Cmp0->
getType(), *
C));
1434 Pred = Flipped->first;
1435 Cmp1 = Flipped->second;
1440 APInt Threshold = *SatC - *
C;
1444 return Builder.CreateBinaryIntrinsic(
1445 Intrinsic::sadd_sat, Cmp0, ConstantInt::get(Cmp0->
getType(), *
C));
1463 return Builder.CreateBinaryIntrinsic(Intrinsic::sadd_sat,
X, Cmp1);
1472 return Builder.CreateBinaryIntrinsic(Intrinsic::sadd_sat,
X, Cmp0);
1480 if (!Cmp->hasOneUse())
1502 Value *
A = Cmp->getOperand(0);
1503 Value *
B = Cmp->getOperand(1);
1516 (TI->hasNoSignedWrap() || TI->hasNoUnsignedWrap()) &&
1517 (FI->hasNoSignedWrap() || FI->hasNoUnsignedWrap())) {
1524 TI->setHasNoUnsignedWrap(
false);
1525 if (!TI->hasNoSignedWrap())
1526 TI->setHasNoSignedWrap(TI->hasOneUse());
1527 return Builder.CreateBinaryIntrinsic(Intrinsic::abs, TI, Builder.getTrue());
1534 return Builder.CreateBinaryIntrinsic(Intrinsic::abs, TI,
1535 Builder.getFalse());
1542 return Builder.CreateBinaryIntrinsic(Intrinsic::abs, FI,
1543 Builder.getFalse());
1550 return Builder.CreateBinaryIntrinsic(Intrinsic::abs, FI,
1551 Builder.getFalse());
1558 return Builder.CreateBinaryIntrinsic(Intrinsic::abs, TI,
1559 Builder.getFalse());
1607 II->getModule(), Intrinsic::cttz,
II->getType());
1663 unsigned SizeOfInBits =
Count->getType()->getScalarSizeInBits();
1666 II->dropPoisonGeneratingAnnotations();
1678 II->dropUBImplyingAttrsAndMetadata();
1692static void dropPoisonGeneratingAnnotationsForSPFCanonicalization(
Value *
Cond,
1697 I->dropPoisonGeneratingAnnotations();
1700 I->dropPoisonGeneratingAnnotations();
1707 if (!
TrueVal->getType()->isIntOrIntVectorTy())
1732 dropPoisonGeneratingAnnotationsForSPFCanonicalization(&Cmp,
LHS,
RHS);
1748 if (!
I || !
I->hasOneUse() ||
1757 for (Use &U :
I->operands()) {
1790 bool Swapped =
false;
1791 if (
Cmp.isEquivalence(
true)) {
1794 }
else if (!
Cmp.isEquivalence()) {
1798 Value *CmpLHS =
Cmp.getOperand(0), *CmpRHS =
Cmp.getOperand(1);
1799 auto ReplaceOldOpWithNewOp = [&](
Value *OldOp,
1800 Value *NewOp) -> Instruction * {
1847 if (CanReplaceCmpLHSWithRHS) {
1848 if (Instruction *R = ReplaceOldOpWithNewOp(CmpLHS, CmpRHS))
1852 if (CanReplaceCmpRHSWithLHS) {
1853 if (Instruction *R = ReplaceOldOpWithNewOp(CmpRHS, CmpLHS))
1869 SmallVector<Instruction *> DropFlags;
1870 if ((CanReplaceCmpLHSWithRHS &&
1873 &DropFlags) == TrueVal) ||
1874 (CanReplaceCmpRHSWithLHS &&
1877 &DropFlags) == TrueVal)) {
1878 for (Instruction *
I : DropFlags) {
1879 I->dropPoisonGeneratingAnnotations();
1887 if (
FalseVal->getType()->isIntOrIntVectorTy(1) &&
2011 if (Cmp00->
getType() !=
X->getType() &&
X->hasOneUse())
2019 else if (!
match(Cmp00,
2027 Value *ReplacementLow, *ReplacementHigh;
2064 std::swap(ReplacementLow, ReplacementHigh);
2070 "Unexpected predicate type.");
2078 "Unexpected predicate type.");
2080 std::swap(ThresholdLowIncl, ThresholdHighExcl);
2096 if (
X->getType() != Sel0.
getType()) {
2106 assert(ReplacementLow && ReplacementHigh &&
2107 "Constant folding of ImmConstant cannot fail");
2125 ShouldReplaceHigh, ReplacementHigh, MaybeReplacedLow,
DEBUG_TYPE);
2169 Value *SelVal0, *SelVal1;
2178 auto MatchesSelectValue = [SelVal0, SelVal1](
Constant *
C) {
2179 return C->isElementWiseEqual(SelVal0) ||
C->isElementWiseEqual(SelVal1);
2183 if (MatchesSelectValue(
C0))
2188 if (!FlippedStrictness)
2192 if (!MatchesSelectValue(FlippedStrictness->second))
2201 Cmp.getName() +
".inv");
2212 if (!
Cmp->hasOneUse())
2242 Value *TVal =
SI.getTrueValue();
2243 Value *FVal =
SI.getFalseValue();
2277 Op->dropPoisonGeneratingFlags();
2282 MMI && MMI->getLHS() ==
V &&
match(MMI->getRHS(),
m_APInt(OpC))) {
2284 {InvDomCR, ConstantRange(*OpC)});
2286 MMI->dropPoisonGeneratingAnnotations();
2349 foldSelectWithExtremeEqCond(CmpLHS, CmpRHS, TrueVal, FalseVal))
2381 Opcode = BOp->getOpcode();
2382 IsIntrinsic =
false;
2396 Opcode =
II->getIntrinsicID();
2404 const DataLayout &
DL =
Cmp->getDataLayout();
2413 if (C3 == FoldBinaryOpOrIntrinsic(
C1, C2)) {
2416 }
else if (Flipped && C3 == FoldBinaryOpOrIntrinsic(Flipped->second, C2)) {
2418 RHS = Flipped->second;
2426 return Builder.CreateBinaryIntrinsic(Opcode, MinMax, C2);
2429 Value *BinOp =
Builder.CreateBinOp(BinOpc, MinMax, C2);
2434 if (BinOpc == Instruction::Add || BinOpc == Instruction::Sub ||
2435 BinOpc == Instruction::Mul) {
2438 willNotOverflow(BinOpc,
RHS, C2, *BinOpInst,
true))
2439 BinOpInst->setHasNoSignedWrap();
2441 willNotOverflow(BinOpc,
RHS, C2, *BinOpInst,
false))
2442 BinOpInst->setHasNoUnsignedWrap();
2460static Instruction *foldICmpUSubSatWithAndForMostSignificantBitCmp(
2466 const APInt *Constant1, *Constant2;
2478 if (
SI.getType() !=
A->getType())
2489 auto *Ty =
A->getType();
2497 APInt AdjAP1 = *Constant1 - MostSignificantBit + 1;
2498 APInt AdjAP2 = *Constant2 - MostSignificantBit + 1;
2500 auto *Adj1 = ConstantInt::get(Ty, AdjAP1);
2501 auto *Adj2 = ConstantInt::get(Ty, AdjAP2);
2506 Constant *MSBConst = ConstantInt::get(Ty, MostSignificantBit);
2507 return BinaryOperator::CreateAnd(
Or, MSBConst);
2514 canonicalizeSPF(*ICI,
SI.getTrueValue(),
SI.getFalseValue(), *
this))
2517 if (
Value *
V = foldSelectInstWithICmpConst(SI, ICI,
Builder))
2520 if (
Value *
V = canonicalizeClampLike(SI, *ICI,
Builder, *
this))
2523 if (Instruction *NewSel =
2524 tryToReuseConstantFromSelectInComparison(SI, *ICI, *
this))
2526 if (Instruction *
Folded =
2527 foldICmpUSubSatWithAndForMostSignificantBitCmp(SI, ICI,
Builder))
2538 if (Instruction *NewSel = foldSelectICmpEq(SI, ICI, *
this))
2548 InstCombiner::BuilderTy::InsertPointGuard Guard(
Builder);
2553 SI.swapProfMetadata();
2558 SQ.getWithInstruction(&SI)))
2564 if (Instruction *
V = foldSelectCtlzToCttz(ICI, TrueVal, FalseVal,
Builder))
2567 if (Instruction *
V = foldSelectZeroOrOnes(ICI, TrueVal, FalseVal,
Builder))
2573 if (
Value *
V = foldSelectCttzCtlz(ICI, TrueVal, FalseVal, *
this))
2601 if (
C ==
A ||
C ==
B) {
2616 Value *CondVal =
SI.getCondition();
2621 if (!TI || !FI || !TI->hasOneUse() || !FI->hasOneUse())
2625 if ((TI->getOpcode() == Instruction::Sub &&
2626 FI->getOpcode() == Instruction::Add) ||
2627 (TI->getOpcode() == Instruction::FSub &&
2628 FI->getOpcode() == Instruction::FAdd)) {
2631 }
else if ((FI->getOpcode() == Instruction::Sub &&
2632 TI->getOpcode() == Instruction::Add) ||
2633 (FI->getOpcode() == Instruction::FSub &&
2634 TI->getOpcode() == Instruction::FAdd)) {
2640 Value *OtherAddOp =
nullptr;
2641 if (SubOp->getOperand(0) == AddOp->
getOperand(0)) {
2643 }
else if (SubOp->getOperand(0) == AddOp->
getOperand(1)) {
2651 if (
SI.getType()->isFPOrFPVectorTy()) {
2652 NegVal = Builder.
CreateFNeg(SubOp->getOperand(1));
2655 Flags &= SubOp->getFastMathFlags();
2656 NegInst->setFastMathFlags(Flags);
2659 NegVal = Builder.
CreateNeg(SubOp->getOperand(1));
2662 Value *NewTrueOp = OtherAddOp;
2663 Value *NewFalseOp = NegVal;
2667 SI.getName() +
".p", &
SI);
2669 if (
SI.getType()->isFPOrFPVectorTy()) {
2671 BinaryOperator::CreateFAdd(SubOp->getOperand(0), NewSel);
2674 Flags &= SubOp->getFastMathFlags();
2678 return BinaryOperator::CreateAdd(SubOp->getOperand(0), NewSel);
2691 Value *CondVal =
SI.getCondition();
2703 auto IsSignedSaturateLimit = [&](
Value *Limit,
bool IsAdd) {
2713 auto IsZeroOrOne = [](
const APInt &
C) {
return C.isZero() ||
C.isOne(); };
2730 IsMinMax(TrueVal, FalseVal))
2737 IsMinMax(FalseVal, TrueVal))
2743 IsMinMax(TrueVal, FalseVal))
2748 IsMinMax(FalseVal, TrueVal))
2753 IsMinMax(FalseVal, TrueVal))
2758 IsMinMax(TrueVal, FalseVal))
2766 if (
II->getIntrinsicID() == Intrinsic::uadd_with_overflow &&
2769 NewIntrinsicID = Intrinsic::uadd_sat;
2770 else if (
II->getIntrinsicID() == Intrinsic::usub_with_overflow &&
2773 NewIntrinsicID = Intrinsic::usub_sat;
2774 else if (
II->getIntrinsicID() == Intrinsic::sadd_with_overflow &&
2775 IsSignedSaturateLimit(TrueVal,
true))
2784 NewIntrinsicID = Intrinsic::sadd_sat;
2785 else if (
II->getIntrinsicID() == Intrinsic::ssub_with_overflow &&
2786 IsSignedSaturateLimit(TrueVal,
false))
2795 NewIntrinsicID = Intrinsic::ssub_sat;
2800 NewIntrinsicID,
SI.getType());
2816 if (ExtOpcode != Instruction::ZExt && ExtOpcode != Instruction::SExt)
2850 Value *CondVal =
SI.getCondition();
2856 unsigned NumElts = CondValTy->getNumElements();
2858 Mask.reserve(NumElts);
2859 for (
unsigned i = 0; i != NumElts; ++i) {
2869 Mask.push_back(i + NumElts);
2922 if (TVal ==
A || TVal ==
B || FVal ==
A || FVal ==
B)
2939 if (TSrc ==
C && FSrc ==
D) {
2943 }
else if (TSrc ==
D && FSrc ==
C) {
2991 V = BI->getOperand(0);
2995 if (Extract->getIndices()[0] !=
I)
3001 auto isCompareSameAsValue = [](
Value *CmpVal,
Value *SelVal) {
3009 return IntC && FpC && IntC->getValue() == FpC->getValue().bitcastToAPInt();
3016 if (
Select->getCondition() ==
SI.getCondition())
3017 if (
Select->getFalseValue() ==
SI.getTrueValue() ||
3018 Select->getTrueValue() ==
SI.getFalseValue())
3022 auto *CmpXchg = isExtractFromCmpXchg(
SI.getCondition(), 1);
3029 if (
auto *
X = isExtractFromCmpXchg(
SI.getTrueValue(), 0))
3031 isCompareSameAsValue(
X->getCompareOperand(),
SI.getFalseValue()))
3032 return SI.getFalseValue();
3037 if (
auto *
X = isExtractFromCmpXchg(
SI.getFalseValue(), 0))
3039 isCompareSameAsValue(
X->getCompareOperand(),
SI.getTrueValue()))
3040 return SI.getFalseValue();
3064 Value *SV0, *SV1, *SA0, *SA1;
3073 if (Or0->
getOpcode() == BinaryOperator::LShr) {
3079 Or1->
getOpcode() == BinaryOperator::LShr &&
3080 "Illegal or(shift,shift) pair");
3095 bool IsFshl = (ShAmt == SA0);
3097 if ((IsFshl && TVal != SV0) || (!IsFshl && TVal != SV1))
3117 Intrinsic::ID IID = IsFshl ? Intrinsic::fshl : Intrinsic::fshr;
3139 assert(TC != FC &&
"Expected equal select arms to simplify");
3143 bool IsTrueIfSignSet;
3161 Value *MagArg = ConstantFP::get(SelType,
abs(*TC));
3180 I->copyIRFlags(&Sel);
3183 M, Intrinsic::vector_reverse,
V->getType());
3191 return createSelReverse(
C,
X,
Y);
3195 return createSelReverse(
C,
X, FVal);
3200 return createSelReverse(
C, TVal,
Y);
3207 unsigned NumElts = VecTy->getNumElements();
3208 APInt PoisonElts(NumElts, 0);
3226 return new ShuffleVectorInst(
X, NewSel, Mask);
3231 return new ShuffleVectorInst(NewSel,
Y, Mask);
3240 return new ShuffleVectorInst(
X, NewSel, Mask);
3245 return new ShuffleVectorInst(NewSel,
Y, Mask);
3257 auto *IDomNode = DT[BB]->getIDom();
3263 Value *IfTrue, *IfFalse;
3279 if (TrueSucc == FalseSucc)
3295 else if (DT.
dominates(FalseEdge, Incoming))
3320 CandidateBlocks.
insert(
I->getParent());
3323 if (
auto *PN = foldSelectToPhiImpl(Sel, BB, DT, Builder))
3336 Value *CondVal =
SI.getCondition();
3341 Value *
Op, *RemRes, *Remainder;
3343 bool TrueIfSigned =
false;
3357 return BinaryOperator::CreateAnd(
Op,
Add);
3369 return FoldToBitwiseAnd(Remainder);
3378 return FoldToBitwiseAnd(ConstantInt::get(RemRes->
getType(), 2));
3385 Value *InnerCondVal =
SI.getCondition();
3386 Value *InnerTrueVal =
SI.getTrueValue();
3387 Value *InnerFalseVal =
SI.getFalseValue();
3389 "The type of inner condition must match with the outer.");
3391 return *Implied ? InnerTrueVal : InnerFalseVal;
3398 assert(
Op->getType()->isIntOrIntVectorTy(1) &&
3399 "Op must be either i1 or vector of i1.");
3400 if (
SI.getCondition()->getType() !=
Op->getType())
3403 return createSelectInstWithUnknownProfile(
3413 Value *CondVal =
SI.getCondition();
3415 bool ChangedFMF =
false;
3416 for (
bool Swap : {
false,
true}) {
3455 if (FMF.
noNaNs() && !
SI.hasNoNaNs()) {
3456 SI.setHasNoNaNs(
true);
3459 if (FMF.
noInfs() && !
SI.hasNoInfs()) {
3460 SI.setHasNoInfs(
true);
3467 SI.setHasNoNaNs(
true);
3481 if (!
SI.hasNoSignedZeros() &&
3484 if (!
SI.hasNoNaNs() &&
3502 Instruction *NewFNeg = UnaryOperator::CreateFNeg(Fabs);
3511 for (
bool Swap : {
false,
true}) {
3534 if (
Swap != TrueIfSigned)
3539 return ChangedFMF ? &
SI :
nullptr;
3552foldSelectOfOrderedFAbsCmpOfNaNScrubbedValue(
SelectInst &
SI,
3567 Value *InnerSel =
SI.getTrueValue();
3572 if (!
match(InnerSel,
3579 auto MatchFAbsOfInnerSel = [&](
Value *
V) {
3584 if (!MatchFAbsOfInnerSel(Cmp0)) {
3585 if (!MatchFAbsOfInnerSel(Cmp1))
3616 uint64_t WeightNotNaN, WeightNaN, WeightComparisonTrue,
3617 WeightComparisonFalse = 0;
3619 WeightNotNaN, WeightNaN);
3623 return NewSelUsesReplaced;
3633 uint64_t WeightNewSelTrue = WeightNotNaN * WeightComparisonTrue;
3635 WeightNaN * (WeightComparisonTrue + WeightComparisonFalse) +
3636 WeightNotNaN * WeightComparisonFalse;
3639 {WeightNewSelTrue, WeightNewSelFalse},
3641 return NewSelUsesReplaced;
3663 Value *XBiasedHighBits =
SI.getFalseValue();
3676 const APInt *LowBitMaskCst;
3681 const APInt *BiasCst, *HighBitMaskCst;
3682 if (!
match(XBiasedHighBits,
3685 !
match(XBiasedHighBits,
3690 if (!LowBitMaskCst->
isMask())
3693 APInt InvertedLowBitMaskCst = ~*LowBitMaskCst;
3694 if (InvertedLowBitMaskCst != *HighBitMaskCst)
3697 APInt AlignmentCst = *LowBitMaskCst + 1;
3699 if (*BiasCst != AlignmentCst && *BiasCst != *LowBitMaskCst)
3704 if (*BiasCst == *LowBitMaskCst &&
impliesPoison(XBiasedHighBits,
X))
3705 return XBiasedHighBits;
3710 Type *Ty =
X->getType();
3711 Value *XOffset = Builder.
CreateAdd(
X, ConstantInt::get(Ty, *LowBitMaskCst),
3712 X->getName() +
".biased");
3713 Value *
R = Builder.
CreateAnd(XOffset, ConstantInt::get(Ty, *HighBitMaskCst));
3719struct DecomposedSelect {
3731foldSelectOfSymmetricSelect(
SelectInst &OuterSelVal,
3734 Value *OuterCond, *InnerCond, *InnerTrueVal, *InnerFalseVal;
3768 DecomposedSelect OuterSel;
3775 std::swap(OuterSel.TrueVal, OuterSel.FalseVal);
3783 Value *InnerSelVal = IsAndVariant ? OuterSel.FalseVal : OuterSel.TrueVal;
3791 DecomposedSelect InnerSel;
3792 if (!
match(InnerSelVal,
3798 bool SwapInnerSelCond =
false;
3800 std::swap(InnerSel.TrueVal, InnerSel.FalseVal);
3801 SwapInnerSelCond = !SwapInnerSelCond;
3804 Value *AltCond =
nullptr;
3805 auto matchOuterCond = [OuterSel, IsAndVariant, &AltCond](
auto m_InnerCond) {
3810 return IsAndVariant ?
match(OuterSel.Cond,
3820 if (matchOuterCond(
m_Specific(InnerSel.Cond))) {
3825 std::swap(InnerSel.TrueVal, InnerSel.FalseVal);
3826 InnerSel.Cond = NotInnerCond;
3827 SwapInnerSelCond = !SwapInnerSelCond;
3836 AltCond, IsAndVariant ? OuterSel.TrueVal : InnerSel.FalseVal,
3837 IsAndVariant ? InnerSel.TrueVal : OuterSel.FalseVal,
DEBUG_TYPE);
3840 InnerSel.Cond, IsAndVariant ? SelInner : InnerSel.TrueVal,
3841 !IsAndVariant ? SelInner : InnerSel.FalseVal,
"",
nullptr,
3843 if (SwapInnerSelCond)
3844 SI->swapProfMetadata();
3851static bool impliesPoisonOrCond(
const Value *ValAssumedPoison,
const Value *
V,
3863 if (ICmp->hasSameSign() &&
3886 .getMaxValue() == 1;
3893 Value *CondVal =
SI.getCondition();
3896 Type *SelType =
SI.getType();
3913 if (impliesPoisonOrCond(FalseVal, CondVal,
false,
SQ)) {
3915 return BinaryOperator::CreateOr(CondVal, FalseVal);
3919 impliesPoisonOrCond(FalseVal,
B,
false,
SQ)) {
3934 auto AndFactorization = [&](
Value *Common,
Value *InnerCond,
3936 bool SelFirst =
false) -> Instruction * {
3937 Value *InnerSel =
Builder.CreateSelectWithUnknownProfile(
3941 if (FalseLogicAnd || (CondLogicAnd && Common ==
A))
3942 return createSelectInstWithUnknownProfile(Common, InnerSel,
Zero);
3944 return BinaryOperator::CreateAnd(Common, InnerSel);
3948 return AndFactorization(
A,
B,
D);
3950 return AndFactorization(
A,
B,
C);
3952 return AndFactorization(
B,
A,
D);
3954 return AndFactorization(
B,
A,
C, CondLogicAnd && FalseLogicAnd);
3959 if (impliesPoisonOrCond(TrueVal, CondVal,
true,
SQ)) {
3961 return BinaryOperator::CreateAnd(CondVal, TrueVal);
3965 impliesPoisonOrCond(TrueVal,
B,
true,
SQ)) {
3980 auto OrFactorization = [&](
Value *Common,
Value *InnerCond,
3982 bool SelFirst =
false) -> Instruction * {
3983 Value *InnerSel =
Builder.CreateSelectWithUnknownProfile(
3987 if (TrueLogicOr || (CondLogicOr && Common ==
A))
3988 return createSelectInstWithUnknownProfile(Common, One, InnerSel);
3990 return BinaryOperator::CreateOr(Common, InnerSel);
3994 return OrFactorization(
A,
B,
D);
3996 return OrFactorization(
A,
B,
C);
3998 return OrFactorization(
B,
A,
D);
4000 return OrFactorization(
B,
A,
C, CondLogicOr && TrueLogicOr);
4057 return BinaryOperator::CreateXor(
A,
B);
4066 return createSelectInstWithUnknownProfile(TrueVal, OrV,
Zero);
4071 Value *OrV =
Builder.CreateSelectWithUnknownProfile(NotC, One, TrueVal,
4073 return createSelectInstWithUnknownProfile(FalseVal, OrV,
Zero);
4083 return createSelectInstWithUnknownProfile(TrueVal, One, AndV);
4091 return createSelectInstWithUnknownProfile(FalseVal, One, AndV);
4099 auto *FI =
new FreezeInst(*
Y, (*Y)->getName() +
".fr");
4105 if (
auto *
V = foldBooleanAndOr(CondVal, Op1, SI, IsAnd,
4116 if (Res && *Res ==
false)
4122 if (Res && *Res ==
false)
4131 if (Res && *Res ==
true)
4137 if (Res && *Res ==
true)
4156 bool &ShouldDropNoWrap) {
4179 ShouldDropNoWrap =
false;
4185 auto MatchForward = [&](
Value *CommonAncestor) {
4186 const APInt *
C =
nullptr;
4187 if (CtlzOp == CommonAncestor)
4190 ShouldDropNoWrap =
true;
4195 ShouldDropNoWrap =
true;
4206 const APInt *
C =
nullptr;
4207 Value *CommonAncestor;
4208 if (MatchForward(Cond0)) {
4212 if (!MatchForward(CommonAncestor))
4250 Type *SelType =
SI.getType();
4259 Value *Cond0, *Ctlz, *CtlzOp;
4268 bool ShouldDropNoWrap;
4275 !isSafeToRemoveBitCeilSelect(
Pred, Cond0, Cond1, CtlzOp,
BitWidth,
4279 if (ShouldDropNoWrap) {
4311 Value *TV =
SI.getTrueValue();
4312 Value *FV =
SI.getFalseValue();
4333 auto FlippedPredAndConst =
4335 if (!FlippedPredAndConst)
4337 Pred = FlippedPredAndConst->first;
4338 RHS = FlippedPredAndConst->second;
4356 CmpPredicate ExtendedCmpPredicate;
4376 CmpPredicate FalseBranchSelectPredicate;
4377 const APInt *InnerTV, *InnerFV;
4383 FalseBranchSelectPredicate =
4388 if (!InnerTV->
isOne()) {
4404 CmpPredicate InnerPred;
4406 const APInt *InnerTV, *InnerFV;
4415 bool CanSubOne = IsSigned ? !
C->isMinSignedValue() : !
C->isMinValue();
4417 APInt Cminus1 = *
C - 1;
4427 bool CanAddOne = IsSigned ? !
C->isMaxSignedValue() : !
C->isMaxValue();
4429 APInt Cplus1 = *
C + 1;
4438 Intrinsic::ID IID = IsSigned ? Intrinsic::scmp : Intrinsic::ucmp;
4441 SI,
Builder.CreateIntrinsic(
SI.getType(), IID, {LHS, RHS}));
4447 KnownFPClass
Known =
4450 return Known.isKnownNeverNaN() &&
Known.isKnownNeverInfinity() &&
4490 return Op->getType()->isIntOrIntVectorTy() &&
4491 hasAffectedValue(Op, Affected, Depth + 1);
4505 if (!SIFOp || !SIFOp->hasNoSignedZeros() || !SIFOp->hasNoNaNs())
4508 auto TryFoldIntoAddConstant =
4520 Swapped ?
X : Z,
"", &
SI);
4551 return TryFoldIntoAddConstant(
Pred,
X, Z,
FAdd,
C,
false);
4555 return TryFoldIntoAddConstant(
Pred,
X, Z,
FAdd,
C,
true);
4571 bool CreateAnd =
false;
4573 Value *CmpLHS, *CmpRHS;
4581 const APInt *AndRHS;
4588 AndMask = Res->Mask;
4591 AndMask &=
Known.getMaxValue();
4601 V =
Trunc->getOperand(0);
4602 AndMask =
APInt(
V->getType()->getScalarSizeInBits(), 1);
4604 CreateAnd = !
Trunc->hasNoUnsignedWrap();
4613 CreateAnd, Builder))
4617 CreateAnd, Builder))
4630 auto *CondVal =
SI.getCondition();
4633 auto *SelTy =
SI.getType();
4635 if (!SelTy->isIntOrIntVectorTy() || SelTy->isIntOrIntVectorTy(1))
4650 if (matchNegNot(TrueVal, FalseVal,
X)) {
4653 return BinaryOperator::CreateSub(Mask,
X);
4657 if (matchNegNot(FalseVal, TrueVal,
X)) {
4659 return BinaryOperator::CreateSub(Mask,
X);
4672 if (!
Cond->hasOneUse())
4701 return BinaryOperator::CreateAnd(And1,
B);
4709static bool isSelectZeroSignInsignificant(
SelectInst &
SI) {
4712 constexpr unsigned MaxUsesToLookThrough = 16;
4713 unsigned NumUses = 0;
4716 while (!Worklist.empty()) {
4717 for (
Use &U : Worklist.pop_back_val()->
uses()) {
4718 if (++NumUses > MaxUsesToLookThrough)
4727 Worklist.push_back(
User);
4737 Value *CondVal =
SI.getCondition();
4740 Type *SelType =
SI.getType();
4744 FMF = FPMO->getFastMathFlags();
4747 SQ.getWithInstruction(&SI)))
4750 if (Instruction *
I = canonicalizeSelectToShuffle(SI))
4753 if (Instruction *
I = canonicalizeScalarSelectOfVecs(SI, *
this))
4805 return new ZExtInst(CondVal, SelType);
4809 return new SExtInst(CondVal, SelType);
4814 return new ZExtInst(NotCond, SelType);
4820 return new SExtInst(NotCond, SelType);
4824 if (Instruction *
I = foldSelectNegNot(SI,
Builder))
4827 if (Instruction *
I = foldSelectAndOrPowerOfTwo(SI,
Builder,
SQ))
4834 Value *Cmp0 = FCmp->getOperand(0), *Cmp1 = FCmp->getOperand(1);
4836 if ((Cmp0 == TrueVal && Cmp1 == FalseVal) ||
4837 (Cmp0 == FalseVal && Cmp1 == TrueVal)) {
4845 Value *NewCond =
Builder.CreateFCmpFMF(InvPred, Cmp0, Cmp1, FCmp,
4846 FCmp->getName() +
".inv");
4848 FastMathFlags FMF =
SI.getFastMathFlags();
4849 if (FCmp->hasNoNaNs())
4851 if (FCmp->hasNoInfs())
4854 NewCond, FalseVal, TrueVal, FMF,
"",
4876 Value *MatchCmp0 =
nullptr;
4877 Value *MatchCmp1 =
nullptr;
4889 if (Cmp0 == MatchCmp0 &&
4890 matchFMulByZeroIfResultEqZero(*
this, Cmp0, Cmp1, MatchCmp1, MatchCmp0,
4891 SI, SIFPOp->hasNoSignedZeros()))
4931 bool CanonicalizeIfNotNan =
4934 if (RcpIfNan || CanonicalizeIfNotNan) {
4936 DenormalMode
Mode =
F.getDenormalMode(FPSem);
4942 if (CanonicalizeIfNotNan)
4956 new FreezeInst(Cmp0, Cmp0->
getName() +
".fr"),
4957 FCmp->getIterator());
4965 if (CanonicalizeIfNotNan) {
4986 if (RcpIfNan && (
Mode.inputsAreZero() ||
Mode.outputsAreZero()))
5015 if (FCmp && FCmp->hasNoNaNs() &&
5016 (SIFPOp->hasNoSignedZeros() || isSelectZeroSignInsignificant(SI))) {
5020 Builder.CreateBinaryIntrinsic(Intrinsic::maxnum,
X,
Y, &SI);
5024 BinIntrInst->setHasNoInfs(FCmp->hasNoInfs());
5029 BinIntrInst->setHasNoSignedZeros(
true);
5032 BinIntrInst->setHasNoNaNs(
true);
5039 Builder.CreateBinaryIntrinsic(Intrinsic::minnum,
X,
Y, &SI);
5041 BinIntrInst->setHasNoInfs(FCmp->hasNoInfs());
5042 BinIntrInst->setHasNoSignedZeros(
true);
5043 BinIntrInst->setHasNoNaNs(
true);
5051 if (Instruction *Fabs = foldSelectWithFCmpToFabs(SI, *
this))
5054 if (Instruction *
I = foldSelectOfOrderedFAbsCmpOfNaNScrubbedValue(SI, *
this))
5066 if (Instruction *
V =
5070 if (
Value *
V = foldSelectBitTest(SI, CondVal, TrueVal, FalseVal,
Builder,
SQ))
5073 if (Instruction *
Add = foldAddSubSelect(SI,
Builder))
5075 if (Instruction *
Add = foldOverflowingAddSubSelect(SI,
Builder))
5085 if (TI && FI && TI->getOpcode() == FI->getOpcode())
5095 if (Instruction *
I = foldSelectWithSRem(SI, *
this,
Builder))
5100 auto SelectGepWithBase = [&](GetElementPtrInst *Gep,
Value *
Base,
5101 bool Swap) -> GetElementPtrInst * {
5115 Builder.CreateSelect(CondVal, NewT, NewF,
SI.getName() +
".idx", &SI);
5120 if (
auto *NewGep = SelectGepWithBase(TrueGep, FalseVal,
false))
5123 if (
auto *NewGep = SelectGepWithBase(FalseGep, TrueVal,
true))
5139 RHS2, SI, SPF,
RHS))
5143 RHS2, SI, SPF,
LHS))
5152 bool IsCastNeeded =
LHS->
getType() != SelType;
5157 ((CmpLHS !=
LHS && CmpLHS !=
RHS) ||
5158 (CmpRHS !=
LHS && CmpRHS !=
RHS)))) {
5163 dropPoisonGeneratingAnnotationsForSPFCanonicalization(CondVal,
LHS,
5174 Value *NewCast =
Builder.CreateCast(CastOp, NewSI, SelType);
5186 if (TrueSI->getCondition()->getType() == CondVal->
getType()) {
5196 if (TrueSI->hasOneUse()) {
5197 Value *
And =
nullptr, *OtherVal =
nullptr;
5199 if (TrueSI->getFalseValue() == FalseVal) {
5200 And =
Builder.CreateLogicalAnd(CondVal, TrueSI->getCondition(),
"",
5202 OtherVal = TrueSI->getTrueValue();
5205 else if (TrueSI->getTrueValue() == FalseVal) {
5206 Value *InvertedCond =
Builder.CreateNot(TrueSI->getCondition());
5207 And =
Builder.CreateLogicalAnd(CondVal, InvertedCond,
"", &SI);
5208 OtherVal = TrueSI->getFalseValue();
5210 if (
And && OtherVal) {
5220 if (FalseSI->getCondition()->getType() == CondVal->
getType()) {
5224 *FalseSI, CondVal,
false))
5227 if (FalseSI->hasOneUse()) {
5228 Value *
Or =
nullptr, *OtherVal =
nullptr;
5230 if (FalseSI->getTrueValue() == TrueVal) {
5231 Or =
Builder.CreateLogicalOr(CondVal, FalseSI->getCondition(),
"",
5233 OtherVal = FalseSI->getFalseValue();
5236 else if (FalseSI->getFalseValue() == TrueVal) {
5237 Value *InvertedCond =
Builder.CreateNot(FalseSI->getCondition());
5238 Or =
Builder.CreateLogicalOr(CondVal, InvertedCond,
"", &SI);
5239 OtherVal = FalseSI->getTrueValue();
5241 if (
Or && OtherVal) {
5257 BinaryOperator *TrueBO;
5260 if (TrueBOSI->getCondition() == CondVal) {
5267 if (TrueBOSI->getCondition() == CondVal) {
5276 BinaryOperator *FalseBO;
5279 if (FalseBOSI->getCondition() == CondVal) {
5286 if (FalseBOSI->getCondition() == CondVal) {
5299 SI.swapProfMetadata();
5314 if (
Known.One.isOne())
5316 if (
Known.Zero.isOne())
5320 if (Instruction *BitCastSel = foldSelectCmpBitcasts(SI,
Builder))
5324 if (
Value *
V = foldSelectCmpXchg(SI))
5330 if (Instruction *Funnel = foldSelectFunnelShift(SI,
Builder))
5333 if (Instruction *Copysign = foldSelectToCopysign(SI,
Builder))
5336 if (Instruction *PN = foldSelectToPhi(SI,
DT,
Builder))
5339 if (
Value *
V = foldRoundUpIntegerWithPow2Alignment(SI,
Builder))
5354 MaskedInst->setArgOperand(2, FalseVal );
5369 bool CanMergeSelectIntoLoad =
false;
5373 if (CanMergeSelectIntoLoad) {
5376 MaskedInst->setArgOperand(2, TrueVal );
5381 if (Instruction *
I = foldSelectOfSymmetricSelect(SI,
Builder))
5384 if (Instruction *
I = foldNestedSelects(SI,
Builder))
5394 if (Instruction *
I = foldBitCeil(SI,
Builder, *
this))
5408 auto FoldSelectWithAndOrCond = [&](
bool IsAnd,
Value *
A,
5409 Value *
B) -> Instruction * {
5415 if (NestedSI->getCondition() ==
A)
5419 SQ.getWithInstruction(&SI))) {
5421 A, IsAnd ?
V : TrueVal, IsAnd ? FalseVal :
V,
"",
nullptr,
5431 if (
Value *
V = canonicalizeSPF(*Cmp, TrueVal, FalseVal, *
this)) {
5433 A, IsAnd ?
V : TrueVal, IsAnd ? FalseVal :
V,
"",
nullptr,
5446 if (Instruction *
I = FoldSelectWithAndOrCond(
true,
LHS,
RHS))
5448 if (Instruction *
I = FoldSelectWithAndOrCond(
true,
RHS,
LHS))
5451 if (Instruction *
I = FoldSelectWithAndOrCond(
false,
LHS,
RHS))
5453 if (Instruction *
I = FoldSelectWithAndOrCond(
false,
RHS,
LHS))
5459 if (Instruction *
I = FoldSelectWithAndOrCond(
true,
LHS,
RHS))
5462 if (Instruction *
I = FoldSelectWithAndOrCond(
false,
LHS,
RHS))
5469 return BinaryOperator::CreateXor(CondVal, FalseVal);
5476 CondContext
CC(CondVal);
5478 CC.AffectedValues.insert(
V);
5480 SimplifyQuery Q =
SQ.getWithInstruction(&SI).getWithCondContext(
CC);
5481 if (!
CC.AffectedValues.empty()) {
5483 hasAffectedValue(TrueVal,
CC.AffectedValues, 0)) {
5485 if (
Known.isConstant())
5487 ConstantInt::get(SelType,
Known.getConstant()));
5492 hasAffectedValue(FalseVal,
CC.AffectedValues, 0)) {
5494 if (
Known.isConstant())
5496 ConstantInt::get(SelType,
Known.getConstant()));
5507 if (TrueVal ==
Trunc)
5509 if (FalseVal ==
Trunc)
5513 if (TrueVal ==
Trunc)
5516 if (FalseVal ==
Trunc)
5523 .countMaxActiveBits() == 1)
5524 return BinaryOperator::CreateAnd(
Trunc, TrueVal);
5529 .countMaxActiveBits() == 1) {
5530 return BinaryOperator::CreateOr(
Trunc, FalseVal);
5534 Value *MaskedLoadPtr;
5540 if (
DT.dominates(FalseVal, LoadInst)) {
5541 Builder.SetInsertPoint(LoadInst);
5543 TrueVal->getType(), MaskedLoadPtr,
5544 LoadInst->getParamAlign(0).valueOrOne(), CondVal, FalseVal);
5545 In->setAAMetadata(LoadInst->getAAMetadata());
5553 unsigned BitWidth =
SI.getType()->getScalarSizeInBits();
5555 Value *CmpLHS, *CmpRHS;
5572 SI.getModule(), Intrinsic::scmp, {SI.getType(), SI.getType()});
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Register Bank Select
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const HexagonInstrInfo * TII
This file provides internal interfaces used to implement the InstCombine.
static Value * foldSelectICmpMinMax(const ICmpInst *Cmp, Value *TVal, Value *FVal, InstCombiner::BuilderTy &Builder, const SimplifyQuery &SQ)
Try to fold a select to a min/max intrinsic.
static bool isConstantBeneficialInIntrinsicArg(Intrinsic::ID IID, unsigned ArgNo)
Return true if a constant in the given argument position of the given intrinsic may enable cheaper lo...
static Instruction * foldSelectIntoIntrinsicArg(SelectInst &SI, IntrinsicInst *TII, IntrinsicInst *FII, InstCombiner::BuilderTy &Builder)
select C, f(..., X, ...), f(..., Y, ...) --> f(..., select C, X, Y, ...)
static Value * canonicalizeSaturatedAddSigned(ICmpInst *Cmp, Value *TVal, Value *FVal, InstCombiner::BuilderTy &Builder)
static Value * canonicalizeSaturatedAdd(ICmpInst *Cmp, Value *TVal, Value *FVal, InstCombiner::BuilderTy &Builder)
static Instruction * foldSetClearBits(SelectInst &Sel, InstCombiner::BuilderTy &Builder)
Canonicalize a set or clear of a masked set of constant bits to select-of-constants form.
static unsigned getSelectFoldableOperands(BinaryOperator *I)
We want to turn code that looks like this: C = or A, B D = select cond, C, A into: C = select cond,...
static Value * canonicalizeSaturatedSubtract(const ICmpInst *ICI, const Value *TrueVal, const Value *FalseVal, InstCombiner::BuilderTy &Builder)
static Value * canoncalizeSelectICmpMinMax(const ICmpInst *Cmp, Value *TVal, Value *FVal, InstCombiner::BuilderTy &Builder, const SimplifyQuery &SQ)
static Value * foldAbsDiff(ICmpInst *Cmp, Value *TVal, Value *FVal, InstCombiner::BuilderTy &Builder)
Try to match patterns with select and subtract as absolute difference.
static Instruction * foldSelectZeroOrFixedOp(SelectInst &SI, InstCombinerImpl &IC)
static Instruction * foldSelectBinOpIdentity(SelectInst &Sel, const TargetLibraryInfo &TLI, InstCombinerImpl &IC)
Replace a select operand based on an equality comparison with the identity constant of a binop.
static Value * foldSelectICmpAnd(SelectInst &Sel, Value *CondVal, Value *TrueVal, Value *FalseVal, Value *V, const APInt &AndMask, bool CreateAnd, InstCombiner::BuilderTy &Builder)
This folds: select (icmp eq (and X, C1)), TC, FC iff C1 is a power 2 and the difference between TC an...
static Value * foldSelectICmpAndZeroShl(const ICmpInst *Cmp, Value *TVal, Value *FVal, InstCombiner::BuilderTy &Builder)
We want to turn: (select (icmp eq (and X, C1), 0), 0, (shl [nsw/nuw] X, C2)); iff C1 is a mask and th...
static Value * canonicalizeSaturatedSubtractSigned(const ICmpInst *ICI, const Value *TrueVal, const Value *FalseVal, InstCombiner::BuilderTy &Builder)
static Value * canonicalizeSaturatedAddUnsigned(ICmpInst *Cmp, Value *TVal, Value *FVal, InstCombiner::BuilderTy &Builder)
static Value * foldSelectICmpLshrAshr(const ICmpInst *IC, Value *TrueVal, Value *FalseVal, InstCombiner::BuilderTy &Builder)
We want to turn: (select (icmp sgt x, C), lshr (X, Y), ashr (X, Y)); iff C s>= -1 (select (icmp slt x...
static bool isSelect01(const APInt &C1I, const APInt &C2I)
static Instruction * foldSelectICmpAndAnd(Type *SelType, const Value *Cond, Value *TVal, Value *FVal, InstCombiner::BuilderTy &Builder)
We want to turn: (select (icmp eq (and X, Y), 0), (and (lshr X, Z), 1), 1) into: zext (icmp ne i32 (a...
static Value * canonicalizeSaturatedSubtractUnsigned(const ICmpInst *ICI, const Value *TrueVal, const Value *FalseVal, InstCombiner::BuilderTy &Builder)
Transform patterns such as (a > b) ?
static Value * foldSelectICmpAndBinOp(Value *CondVal, Value *TrueVal, Value *FalseVal, Value *V, const APInt &AndMask, bool CreateAnd, InstCombiner::BuilderTy &Builder)
We want to turn: (select (icmp eq (and X, C1), 0), Y, (BinOp Y, C2)) into: IF C2 u>= C1 (BinOp Y,...
This file provides the interface for the instcombine pass implementation.
static bool hasNoSignedWrap(BinaryOperator &I)
static bool hasNoUnsignedWrap(BinaryOperator &I)
uint64_t IntrinsicInst * II
This file contains the declarations for profiling metadata utility functions.
MachineBasicBlock * Folded
SmallVector< MachineOperand, 4 > Cond
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallVector class.
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static const uint32_t IV[8]
bool bitwiseIsEqual(const APFloat &RHS) const
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
static APInt getSignMask(unsigned BitWidth)
Get the SignMask for a specific bit width.
bool isMinSignedValue() const
Determine if this is the smallest signed value.
uint64_t getZExtValue() const
Get zero extended value.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
bool isZero() const
Determine if this value is zero, i.e. all bits are clear.
bool isSignMask() const
Check if the APInt's value is returned by getSignMask.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
bool isMinValue() const
Determine if this is the smallest unsigned value.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
unsigned logBase2() const
bool isMask(unsigned numBits) const
bool isMaxSignedValue() const
Determine if this is the largest signed value.
bool isNonNegative() const
Determine if this APInt Value is non-negative (>= 0)
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
bool isSignBitSet() const
Determine if sign bit of this APInt is set.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
bool isOne() const
Determine if this is a value of 1.
bool isMaxValue() const
Determine if this is the largest unsigned value.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
An instruction that atomically checks whether a specified value is in a memory location,...
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
BinaryOps getOpcode() const
static LLVM_ABI BinaryOperator * CreateNot(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
This class represents a no-op cast from one type to another.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Value * getArgOperand(unsigned i) const
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
This class is the base class for the comparison instructions.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ FCMP_ULT
1 1 0 0 True if unordered or less than
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
@ ICMP_ULT
unsigned less than
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
@ ICMP_SGE
signed greater or equal
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
@ ICMP_ULE
unsigned less or equal
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
static bool isFPPredicate(Predicate P)
bool isNonStrictPredicate() const
static bool isRelational(Predicate P)
Return true if the predicate is relational (not EQ or NE).
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Predicate getPredicate() const
Return the predicate for this instruction.
static LLVM_ABI bool isUnordered(Predicate predicate)
Determine if the predicate is an unordered operation.
Predicate getFlippedStrictnessPredicate() const
For predicate of kind "is X or equal to 0" returns the predicate "is X".
bool isIntPredicate() const
static LLVM_ABI bool isOrdered(Predicate predicate)
Determine if the predicate is an ordered operation.
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
static LLVM_ABI std::optional< CmpPredicate > getMatching(CmpPredicate A, CmpPredicate B)
Compares two CmpPredicates taking samesign into account and returns the canonicalized CmpPredicate if...
static LLVM_ABI Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static LLVM_ABI Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
static LLVM_ABI Constant * getNeg(Constant *C, bool HasNSW=false)
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
This class represents a range of values.
LLVM_ABI ConstantRange add(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an addition of a value in this ran...
LLVM_ABI bool icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const
Does the predicate Pred hold between ranges this and Other?
static LLVM_ABI ConstantRange intrinsic(Intrinsic::ID IntrinsicID, ArrayRef< ConstantRange > Ops)
Compute range of intrinsic result for the given operand ranges.
static LLVM_ABI ConstantRange makeExactICmpRegion(CmpInst::Predicate Pred, const APInt &Other)
Produce the exact range such that all values in the returned range satisfy the given predicate with a...
LLVM_ABI ConstantRange binaryNot() const
Return a new range representing the possible values resulting from a binary-xor of a value in this ra...
LLVM_ABI ConstantRange binaryOp(Instruction::BinaryOps BinOp, const ConstantRange &Other) const
Return a new range representing the possible values resulting from an application of the specified bi...
LLVM_ABI ConstantRange sub(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a subtraction of a value in this r...
This is an important base class in LLVM.
static LLVM_ABI Constant * mergeUndefsWith(Constant *C, Constant *Other)
Merges undefs of a Constant with another Constant, along with the undefs already present.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
LLVM_ABI bool isOneValue() const
Returns true if the value is one.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
A parsed version of the target data layout string in and methods for querying it.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
Tagged union holding either a T or a Error.
This provides a helper for copying FMF from an instruction or setting specified flags.
Utility class for floating point operations which can have information about relaxed accuracy require...
FastMathFlags getFastMathFlags() const
Convenience function for getting all the fast-math flags.
Convenience struct for specifying and reasoning about fast-math flags.
static FastMathFlags intersectRewrite(FastMathFlags LHS, FastMathFlags RHS)
Intersect rewrite-based flags.
bool noSignedZeros() const
static FastMathFlags unionValue(FastMathFlags LHS, FastMathFlags RHS)
Union value flags.
void setNoSignedZeros(bool B=true)
void setNoNaNs(bool B=true)
void setNoInfs(bool B=true)
This class represents a freeze function that returns random concrete value if an operand is either a ...
Value * getPointerOperand()
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Type * getSourceElementType() const
LLVM_ABI GEPNoWrapFlags getNoWrapFlags() const
Get the nowrap flags for the GEP instruction.
This instruction compares its operands according to the predicate given to the constructor.
static CmpPredicate getSwappedCmpPredicate(CmpPredicate Pred)
static bool isLT(Predicate P)
Return true if the predicate is SLT or ULT.
CmpPredicate getInverseCmpPredicate() const
static bool isGT(Predicate P)
Return true if the predicate is SGT or UGT.
static CmpPredicate getInverseCmpPredicate(CmpPredicate Pred)
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
bool isRelational() const
Return true if the predicate is relational (not EQ or NE).
Common base class shared among various IRBuilders.
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
LLVM_ABI Value * CreateSelectFMF(Value *C, Value *True, Value *False, FMFSource FMFSource, const Twine &Name="", Instruction *MDFrom=nullptr)
LLVM_ABI Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Value * CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name="")
LLVM_ABI Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateFreeze(Value *V, const Twine &Name="")
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="", bool HasSameSign=false)
Value * CreateFAbs(Value *V, FMFSource FMFSource={}, const Twine &Name="")
Create call to the fabs intrinsic.
Value * CreateFCmpFMF(CmpInst::Predicate P, Value *LHS, Value *RHS, FMFSource FMFSource, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
LLVM_ABI Value * CreateBinaryIntrinsic(Intrinsic::ID ID, Value *LHS, Value *RHS, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with 2 operands which is mangled on the first type.
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Value * CreateNot(Value *V, const Twine &Name="")
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
LLVM_ABI Value * CreateSelectWithUnknownProfile(Value *C, Value *True, Value *False, StringRef PassName, const Twine &Name="")
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
ConstantInt * getFalse()
Get the constant value for i1 false.
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
Value * CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name="")
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="", bool IsDisjoint=false)
Instruction * foldSelectToCmp(SelectInst &SI)
bool fmulByZeroIsZero(Value *MulVal, FastMathFlags FMF, const Instruction *CtxI) const
Check if fmul MulVal, +0.0 will yield +0.0 (or signed zero is ignorable).
Instruction * foldSelectEqualityTest(SelectInst &SI)
Instruction * foldSelectValueEquivalence(SelectInst &SI, CmpInst &CI)
Instruction * foldOpIntoPhi(Instruction &I, PHINode *PN, bool AllowMultipleUses=false)
Given a binary operator, cast instruction, or select which has a PHI node as operand #0,...
Instruction * foldVectorSelect(SelectInst &Sel)
Value * SimplifyDemandedVectorElts(Value *V, APInt DemandedElts, APInt &PoisonElts, unsigned Depth=0, bool AllowMultipleUsers=false) override
The specified value produces a vector with any number of elements.
Instruction * foldSPFofSPF(Instruction *Inner, SelectPatternFlavor SPF1, Value *A, Value *B, Instruction &Outer, SelectPatternFlavor SPF2, Value *C)
Instruction * foldSelectOpOp(SelectInst &SI, Instruction *TI, Instruction *FI)
We have (select c, TI, FI), and we know that TI and FI have the same opcode.
Instruction * foldSelectIntrinsic(SelectInst &SI)
This transforms patterns of the form: select cond, intrinsic(x, ...), intrinsic(y,...
bool replaceInInstruction(Value *V, Value *Old, Value *New, unsigned Depth=0)
Instruction * foldSelectInstWithICmp(SelectInst &SI, ICmpInst *ICI)
Value * simplifyNestedSelectsUsingImpliedCond(SelectInst &SI, Value *CondVal, bool CondIsTrue)
Given that CondVal is known to be CondIsTrue, try to simplify SI to one of its arms.
bool sinkNotIntoOtherHandOfLogicalOp(Instruction &I)
Instruction * foldSelectIntoOp(SelectInst &SI, Value *, Value *)
Try to fold the select into one of the operands to allow further optimization.
Instruction * FoldOrOfLogicalAnds(Value *Op0, Value *Op1)
Value * foldSelectWithConstOpToBinOp(ICmpInst *Cmp, Value *TrueVal, Value *FalseVal)
Instruction * visitSelectInst(SelectInst &SI)
Instruction * foldSelectOfBools(SelectInst &SI)
Instruction * foldSelectExtConst(SelectInst &Sel)
The core instruction combiner logic.
const DataLayout & getDataLayout() const
bool isKnownToBeAPowerOfTwo(const Value *V, bool OrZero=false, const Instruction *CtxI=nullptr, unsigned Depth=0)
Instruction * InsertNewInstBefore(Instruction *New, BasicBlock::iterator Old)
Inserts an instruction New before instruction Old.
Instruction * replaceInstUsesWith(Instruction &I, Value *V)
A combiner-aware RAUW-like routine.
static bool shouldAvoidAbsorbingNotIntoSelect(const SelectInst &SI)
void replaceUse(Use &U, Value *NewValue)
Replace use and add the previously used value to the worklist.
static bool isCanonicalPredicate(CmpPredicate Pred)
Predicate canonicalization reduces the number of patterns that need to be matched by other transforms...
InstructionWorklist & Worklist
A worklist of the instructions that need to be simplified.
IRBuilder< TargetFolder, IRBuilderInstCombineInserter > BuilderTy
An IRBuilder that automatically inserts new instructions into the worklist.
void addToWorklist(Instruction *I)
Instruction * replaceOperand(Instruction &I, unsigned OpNum, Value *V)
Replace operand of instruction and add old operand to the worklist.
void computeKnownBits(const Value *V, KnownBits &Known, const Instruction *CtxI, unsigned Depth=0) const
Value * getFreelyInverted(Value *V, bool WillInvertAllUses, BuilderTy *Builder, bool &DoesConsume)
const SimplifyQuery & getSimplifyQuery() const
static Constant * AddOne(Constant *C)
Add one to a Constant.
LLVM_ABI bool hasNoNaNs() const LLVM_READONLY
Determine whether the no-NaNs flag is set.
LLVM_ABI bool hasNoUnsignedWrap() const LLVM_READONLY
Determine whether the no unsigned wrap flag is set.
LLVM_ABI bool hasNoInfs() const LLVM_READONLY
Determine whether the no-infs flag is set.
LLVM_ABI bool isSameOperationAs(const Instruction *I, unsigned flags=0) const LLVM_READONLY
This function determines if the specified instruction executes the same operation as the current one.
LLVM_ABI void setHasNoSignedZeros(bool B)
Set or clear the no-signed-zeros flag on this instruction, which must be an operator which supports t...
LLVM_ABI bool hasNoSignedZeros() const LLVM_READONLY
Determine whether the no-signed-zeros flag is set.
LLVM_ABI bool hasNoSignedWrap() const LLVM_READONLY
Determine whether the no signed wrap flag is set.
LLVM_ABI void copyIRFlags(const Value *V, bool IncludeWrapFlags=true)
Convenience method to copy supported exact, fast-math, and (optionally) wrapping flags from V to this...
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
LLVM_ABI void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction.
LLVM_ABI void setHasNoNaNs(bool B)
Set or clear the no-nans flag on this instruction, which must be an operator which supports this flag...
LLVM_ABI bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
LLVM_ABI void setFastMathFlags(FastMathFlags FMF)
Convenience function for setting multiple fast-math flags on this instruction, which must be an opera...
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
LLVM_ABI void swapProfMetadata()
If the instruction has "branch_weights" MD_prof metadata and the MDNode has three operands (including...
LLVM_ABI void setHasNoInfs(bool B)
Set or clear the no-infs flag on this instruction, which must be an operator which supports this flag...
LLVM_ABI FastMathFlags getFastMathFlags() const LLVM_READONLY
Convenience function for getting all the fast-math flags, which must be an operator which supports th...
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
A wrapper class for inspecting calls to intrinsic functions.
bool isKnownNeverNaN() const
Return true if it's known this can never be a nan.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
This class represents a sign extension of integer types.
This class represents the LLVM 'select' instruction.
const Value * getFalseValue() const
void swapValues()
Swap the true and false values of the select instruction.
const Value * getCondition() const
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, const Instruction *MDFrom=nullptr)
const Value * getTrueValue() const
bool insert(const value_type &X)
Insert a new element into the SetVector.
This instruction constructs a fixed permutation of two input vectors.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Provides information about what library functions are available for the current target.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
bool isIEEELikeFPTy() const
Return true if this is a well-behaved IEEE-like type, which has a IEEE compatible layout,...
LLVM_ABI const fltSemantics & getFltSemantics() const
static UnaryOperator * CreateFNegFMF(Value *Op, Instruction *FMFSource, const Twine &Name="", InsertPosition InsertBefore=nullptr)
A Use represents the edge between a Value definition and its users.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
bool hasOneUse() const
Return true if there is exactly one use of this value.
iterator_range< use_iterator > uses()
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
Represents an op.with.overflow intrinsic.
This class represents zero extension of integer types.
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
int getMinValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return the minimum value of an extendable operand.
int getMaxValue(MCInstrInfo const &MCII, MCInst const &MCI)
Return the maximum value of an extendable operand.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
BinaryOpc_match< LHS, RHS, false > m_BinOp(unsigned Opcode, const LHS &L, const RHS &R)
SpecificConstantMatch m_ZeroInt()
Convenience matchers for specific integer values.
auto m_PosZeroFP()
Matches a floating-point positive zero.
BinaryOp_match< SpecificConstantMatch, SrcTy, TargetOpcode::G_SUB > m_Neg(const SrcTy &&Src)
Matches a register negated by a G_SUB.
AllOnesConstantMatch m_AllOnes()
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
OneUse_match< SubPat > m_OneUse(const SubPat &SP)
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
match_combine_and< Ty... > m_CombineAnd(const Ty &...Ps)
Combine pattern matchers matching all of Ps patterns.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
cst_pred_ty< is_negative > m_Negative()
Match an integer or vector of negative values.
auto m_Cmp()
Matches any compare instruction and ignore it.
BinaryOp_match< cst_pred_ty< is_all_ones, false >, ValTy, Instruction::Xor, true > m_NotForbidPoison(const ValTy &V)
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
CmpClass_match< LHS, RHS, FCmpInst > m_FCmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FMul, true > m_c_FMul(const LHS &L, const RHS &R)
Matches FMul with LHS and RHS in either order.
cst_pred_ty< is_sign_mask > m_SignMask()
Match an integer or vector with only the sign bit(s) set.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FSub > m_FSub(const LHS &L, const RHS &R)
cst_pred_ty< is_power2 > m_Power2()
Match an integer or vector power-of-2.
match_combine_or< CastInst_match< OpTy, TruncInst >, OpTy > m_TruncOrSelf(const OpTy &Op)
CommutativeBinaryIntrinsic_match< IntrID, T0, T1 > m_c_Intrinsic(const T0 &Op0, const T1 &Op1)
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
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.
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
BinaryOp_match< LHS, RHS, Instruction::Xor > m_Xor(const LHS &L, const RHS &R)
ap_match< APInt > m_APIntAllowPoison(const APInt *&Res)
Match APInt while allowing poison in splat vector constants.
LogicalOp_match< LHS, RHS, Instruction::And > m_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R either in the form of L & R or L ?
auto m_ConstantExpr()
Match a constant expression or a constant that contains a constant expression.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWSub(const LHS &L, const RHS &R)
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
match_combine_or< CastInst_match< OpTy, ZExtInst >, OpTy > m_ZExtOrSelf(const OpTy &Op)
bool match(Val *V, const Pattern &P)
BinOpPred_match< LHS, RHS, is_idiv_op > m_IDiv(const LHS &L, const RHS &R)
Matches integer division operations.
match_bind< Instruction > m_Instruction(Instruction *&I)
Match an instruction, capturing it if we match.
match_deferred< Value > m_Deferred(Value *const &V)
Like m_Specific(), but works if the specific value to match is determined as part of the same match()...
cstfp_pred_ty< is_any_zero_fp > m_AnyZeroFP()
Match a floating-point negative zero or positive zero.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
specific_intval< true > m_SpecificIntAllowPoison(const APInt &V)
ap_match< APFloat > m_APFloatAllowPoison(const APFloat *&Res)
Match APFloat while allowing poison in splat vector constants.
CmpClass_match< LHS, RHS, ICmpInst, true > m_c_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
Matches an ICmp with a predicate over LHS and RHS in either order.
auto match_fn(const Pattern &P)
A match functor that can be used as a UnaryPredicate in functional algorithms like all_of.
OverflowingBinaryOp_match< cst_pred_ty< is_zero_int >, ValTy, Instruction::Sub, OverflowingBinaryOperator::NoSignedWrap > m_NSWNeg(const ValTy &V)
Matches a 'Neg' as 'sub nsw 0, V'.
TwoOps_match< Val_t, Idx_t, Instruction::ExtractElement > m_ExtractElt(const Val_t &Val, const Idx_t &Idx)
Matches ExtractElementInst.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
ThreeOps_match< Cond, LHS, RHS, Instruction::Select > m_Select(const Cond &C, const LHS &L, const RHS &R)
Matches SelectInst.
auto m_BinOp()
Match an arbitrary binary operation and ignore it.
auto m_BasicBlock()
Match an arbitrary basic block value and ignore it.
ExtractValue_match< Ind, Val_t > m_ExtractValue(const Val_t &V)
Match a single index ExtractValue instruction.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
cst_pred_ty< is_any_apint > m_AnyIntegralConstant()
Match an integer or vector with any integral constant.
auto m_Value()
Match an arbitrary value and ignore it.
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.
BinaryOp_match< LHS, RHS, Instruction::FAdd > m_FAdd(const LHS &L, const RHS &R)
auto m_Ctpop(const Opnd0 &Op0)
auto m_Constant()
Match an arbitrary Constant and ignore it.
NoWrapTrunc_match< OpTy, TruncInst::NoSignedWrap > m_NSWTrunc(const OpTy &Op)
Matches trunc nsw.
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
TwoOps_match< V1_t, V2_t, Instruction::ShuffleVector > m_Shuffle(const V1_t &v1, const V2_t &v2)
Matches ShuffleVectorInst independently of mask value.
ap_match< APInt > m_APIntForbidPoison(const APInt *&Res)
Match APInt while forbidding poison in splat vector constants.
cst_pred_ty< is_strictlypositive > m_StrictlyPositive()
Match an integer or vector of strictly positive values.
auto m_MaskedGather(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedGather Intrinsic.
match_bind< WithOverflowInst > m_WithOverflowInst(WithOverflowInst *&I)
Match a with overflow intrinsic, capturing it if we match.
SpecificCmpClass_match< LHS, RHS, ICmpInst > m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
auto m_Ctlz(const Opnd0 &Op0, const Opnd1 &Op1)
match_combine_or< FMaxMin_match< LHS, RHS, ofmin_pred_ty >, FMaxMin_match< LHS, RHS, ufmin_pred_ty > > m_OrdOrUnordFMin(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point minimum function.
auto m_FCanonicalize(const Opnd0 &Op0)
is_zero< true > m_Zero()
Match any null constant or a vector with all elements equal to 0.
auto m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
cst_pred_ty< icmp_pred_with_threshold, false > m_SpecificInt_ICMP_ForbidPoison(ICmpInst::Predicate Predicate, const APInt &Threshold)
Match an integer or vector with every element comparing 'pred' (eg/ne/...) to Threshold.
match_immconstant_ty m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
auto m_c_LogicalOp(const LHS &L, const RHS &R)
Matches either L && R or L || R with LHS and RHS in either order.
NoWrapTrunc_match< OpTy, TruncInst::NoUnsignedWrap > m_NUWTrunc(const OpTy &Op)
Matches trunc nuw.
SelectLike_match< CondTy, LTy, RTy > m_SelectLike(const CondTy &C, const LTy &TrueC, const RTy &FalseC)
Matches a value that behaves like a boolean-controlled select, i.e.
specific_fpval m_FPOne()
Match a float 1.0 or vector with all elements equal to 1.0.
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.
SpecificCmpClass_match< LHS, RHS, FCmpInst > m_SpecificFCmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
CastOperator_match< OpTy, Instruction::BitCast > m_BitCast(const OpTy &Op)
Matches BitCast.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
auto m_MaskedLoad(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
Matches MaskedLoad Intrinsic.
FNeg_match< OpTy, true > m_FNegOrFSubNegZero(const OpTy &X)
Match fneg X or fsub -0.0, X.
cst_pred_ty< is_maxsignedvalue > m_MaxSignedValue()
Match an integer or vector with values having all bits except for the high bit set (0x7f....
auto m_FAbs(const Opnd0 &Op0)
AnyBinaryOp_match< LHS, RHS, true > m_c_BinOp(const LHS &L, const RHS &R)
Matches a BinaryOperator with LHS and RHS in either order.
match_combine_or< FMaxMin_match< LHS, RHS, ofmax_pred_ty >, FMaxMin_match< LHS, RHS, ufmax_pred_ty > > m_OrdOrUnordFMax(const LHS &L, const RHS &R)
Match an 'ordered' or 'unordered' floating point maximum function.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Add, OverflowingBinaryOperator::NoSignedWrap > m_NSWAdd(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
LogicalOp_match< LHS, RHS, Instruction::And, true > m_c_LogicalAnd(const LHS &L, const RHS &R)
Matches L && R with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::FDiv > m_FDiv(const LHS &L, const RHS &R)
BinOpPred_match< LHS, RHS, is_irem_op > m_IRem(const LHS &L, const RHS &R)
Matches integer remainder operations.
auto m_MaxOrMin(const Opnd0 &Op0, const Opnd1 &Op1)
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
brc_match< Cond_t, match_bind< BasicBlock >, match_bind< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
BinaryOp_match< LHS, RHS, Instruction::SRem > m_SRem(const LHS &L, const RHS &R)
auto m_Undef()
Match an arbitrary undef constant.
auto m_VecReverse(const Opnd0 &Op0)
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
CastInst_match< OpTy, SExtInst > m_SExt(const OpTy &Op)
Matches SExt.
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.
LogicalOp_match< LHS, RHS, Instruction::Or, true > m_c_LogicalOr(const LHS &L, const RHS &R)
Matches L || R with LHS and RHS in either order.
SpecificCmpClass_match< LHS, RHS, ICmpInst, true > m_c_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
ElementWiseBitCast_match< OpTy > m_ElementWiseBitCast(const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::Mul, true > m_c_Mul(const LHS &L, const RHS &R)
Matches a Mul with LHS and RHS in either order.
auto m_Cttz(const Opnd0 &Op0, const Opnd1 &Op1)
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
auto m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
cst_pred_ty< icmp_pred_with_threshold > m_SpecificInt_ICMP(ICmpInst::Predicate Predicate, const APInt &Threshold)
Match an integer or vector with every element comparing 'pred' (eg/ne/...) to Threshold.
auto m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
Not(const Pred &P) -> Not< Pred >
ElementType
The element type of an SRV or UAV resource.
DiagnosticInfoOptimizationBase::Argument NV
NodeAddr< UseNode * > Use
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI KnownFPClass computeKnownFPClass(const Value *V, const APInt &DemandedElts, FPClassTest InterestedClasses, const SimplifyQuery &SQ, unsigned Depth=0)
Determine which floating-point classes are valid for V, and return them in KnownFPClass bit sets.
LLVM_ABI cl::opt< bool > ProfcheckDisableMetadataFixes
LLVM_ABI bool isSignBitCheck(ICmpInst::Predicate Pred, const APInt &RHS, bool &TrueIfSigned)
Given an exploded icmp instruction, return true if the comparison only checks the sign bit.
@ Known
Known to have no common set bits.
LLVM_ABI void setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I, StringRef PassName, const Function *F=nullptr)
Like setExplicitlyUnknownBranchWeights(...), but only sets unknown branch weights in the new instruct...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
auto dyn_cast_if_present(const Y &Val)
dyn_cast_if_present<X> - Functionally identical to dyn_cast, except that a null (or none in the case ...
LLVM_ABI void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
LLVM_ABI CmpInst::Predicate getMinMaxPred(SelectPatternFlavor SPF, bool Ordered=false)
Return the canonical comparison predicate for the specified minimum/maximum flavor.
LLVM_ABI bool canIgnoreSignBitOfZero(const Use &U)
Return true if the sign bit of the FP value can be ignored by the user when the value is zero.
LLVM_ABI bool isGuaranteedNotToBeUndef(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be undef, but may be poison.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI Constant * ConstantFoldIntrinsic(Intrinsic::ID ID, ArrayRef< Constant * > Ops, Type *Ty, const DataLayout &DL, const Function *CtxF=nullptr)
LLVM_ABI bool isKnownToBeAPowerOfTwo(const Value *V, const DataLayout &DL, bool OrZero=false, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true, unsigned Depth=0)
Return true if the given value is known to have exactly one bit set when defined.
LLVM_ABI Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const Function *CtxF=nullptr)
Attempt to constant fold a compare instruction (icmp/fcmp) with the specified operands.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI bool isSplatValue(const Value *V, int Index=-1, unsigned Depth=0)
Return true if each element of the vector value V is poisoned or equal to every other non-poisoned el...
constexpr unsigned MaxAnalysisRecursionDepth
SelectPatternFlavor
Specific patterns of select instructions we can match.
@ SPF_ABS
Floating point maxnum.
@ SPF_NABS
Absolute value.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM_ABI bool canReplacePointersIfEqual(const Value *From, const Value *To, const DataLayout &DL)
Returns true if a pointer value From can be replaced with another pointer value \To if they are deeme...
LLVM_ABI bool impliesPoison(const Value *ValAssumedPoison, const Value *V)
Return true if V is poison given that ValAssumedPoison is already poison.
LLVM_ABI SelectPatternResult getSelectPattern(CmpInst::Predicate Pred, SelectPatternNaNBehavior NaNBehavior=SPNB_NA, bool Ordered=false)
Determine the pattern for predicate X Pred Y ? X : Y.
LLVM_ABI bool cannotBeNegativeZero(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if we can prove that the specified FP value is never equal to -0.0.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Value * simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for a SelectInst, fold the result or return null.
LLVM_ABI Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)
Attempt to constant fold a cast with the specified operand.
LLVM_ABI Value * simplifyAndInst(Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for an And, fold the result or return null.
LLVM_ABI bool isKnownInversion(const Value *X, const Value *Y)
Return true iff:
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI bool isNotCrossLaneOperation(const Instruction *I)
Return true if the instruction doesn't potentially cross vector lanes.
LLVM_ABI Constant * ConstantFoldBinaryOpOperands(unsigned Opcode, Constant *LHS, Constant *RHS, const DataLayout &DL)
Attempt to constant fold a binary operation with the specified operands.
LLVM_ABI bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth=0)
Return true if the given value is known to be non-zero when defined.
constexpr int PoisonMaskElem
LLVM_ABI Intrinsic::ID getMinMaxIntrinsic(SelectPatternFlavor SPF)
Convert given SPF to equivalent min/max intrinsic.
LLVM_ABI SelectPatternResult matchDecomposedSelectPattern(CmpInst *CmpI, Value *TrueVal, Value *FalseVal, Value *&LHS, Value *&RHS, FastMathFlags FMF=FastMathFlags(), Instruction::CastOps *CastOp=nullptr)
Determine the pattern that a select with the given compare as its predicate and given values as its t...
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
@ And
Bitwise or logical AND of integers.
@ SMin
Signed integer min implemented in terms of select(cmp()).
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
LLVM_ABI bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx)
Given an instruction, is it legal to set operand OpIdx to a non-constant value?
DWARFExpression::Operation Op
bool isSafeToSpeculativelyExecuteWithVariableReplaced(const Instruction *I, bool IgnoreUBImplyingAttrs=true)
Don't use information from its non-constant operands.
constexpr unsigned BitWidth
LLVM_ABI Constant * getLosslessInvCast(Constant *C, Type *InvCastTo, unsigned CastOp, const DataLayout &DL, PreservedCastFlags *Flags=nullptr)
Try to cast C to InvC losslessly, satisfying CastOp(InvC) equals C, or CastOp(InvC) is a refined valu...
LLVM_ABI bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
LLVM_ABI Value * simplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp, const SimplifyQuery &Q, bool AllowRefinement, SmallVectorImpl< Instruction * > *DropFlags=nullptr)
See if V simplifies when its operand Op is replaced with RepOp.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool isKnownNeverNaN(const Value *V, const SimplifyQuery &SQ, unsigned Depth=0)
Return true if the floating-point scalar value is not a NaN or if the floating-point vector value has...
auto predecessors(const MachineBasicBlock *BB)
LLVM_ABI std::optional< std::pair< CmpPredicate, Constant * > > getFlippedStrictnessPredicateAndConstant(CmpPredicate Pred, Constant *C)
Convert an integer comparison with a constant RHS into an equivalent form with the strictness flipped...
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI bool isGuaranteedNotToBePoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be poison, but may be undef.
LLVM_ABI void setFittedBranchWeights(Instruction &I, ArrayRef< uint64_t > Weights, bool IsExpected, bool ElideAllZero=false)
Variant of setBranchWeights where the Weights will be fit first to uint32_t by shifting right.
LLVM_ABI SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
LLVM_ABI bool isTriviallyVectorizable(Intrinsic::ID ID)
Identify if the intrinsic is trivially vectorizable.
LLVM_ABI bool isCheckForZeroAndMulWithOverflow(Value *Op0, Value *Op1, bool IsAnd, Use *&Y)
Match one of the patterns up to the select/logic op: Op0 = icmp ne i4 X, 0 Agg = call { i4,...
LLVM_ABI std::optional< bool > isImpliedCondition(const Value *LHS, const Value *RHS, const DataLayout &DL, bool LHSIsTrue=true, unsigned Depth=0)
Return true if RHS is known to be implied true by LHS.
LLVM_ABI std::optional< DecomposedBitTest > decomposeBitTestICmp(Value *LHS, Value *RHS, CmpInst::Predicate Pred, bool LookThroughTrunc=true, bool AllowNonZeroC=false, bool DecomposeAnd=false)
Decompose an icmp into the form ((X & Mask) pred C) if possible.
LLVM_ABI bool canIgnoreSignBitOfNaN(const Use &U)
Return true if the sign bit of the FP value can be ignored by the user when the value is NaN.
LLVM_ABI void findValuesAffectedByCondition(Value *Cond, bool IsAssume, function_ref< void(Value *)> InsertAffected)
Call InsertAffected on all Values whose known bits / value may be affected by the condition Cond.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static constexpr DenormalMode getIEEE()
SelectPatternFlavor Flavor
bool Ordered
Only applicable if Flavor is SPF_FMINNUM or SPF_FMAXNUM.
static bool isMinOrMax(SelectPatternFlavor SPF)
When implementing this min/max pattern as fcmp; select, does the fcmp have to be ordered?
SimplifyQuery getWithInstruction(const Instruction *I) const