Lines Matching defs:SI

271 Instruction *InstCombinerImpl::foldSelectOpOp(SelectInst &SI, Instruction *TI,
277 if ((match(&SI, m_SMin(m_Value(), m_Value())) ||
278 match(&SI, m_SMax(m_Value(), m_Value())) ||
279 match(&SI, m_UMin(m_Value(), m_Value())) ||
280 match(&SI, m_UMax(m_Value(), m_Value()))))
284 Value *Cond = SI.getCondition();
320 SI.getName() + ".v", &SI);
373 FMF |= SI.getFastMathFlags();
375 Builder.CreateSelect(Cond, X, Y, SI.getName() + ".v", &SI);
393 Builder.CreateSelect(Cond, OtherOpT, OtherOpF, "minmaxop", &SI);
409 FPMathOperator *SelectFPOp = cast<FPMathOperator>(&SI);
420 return replaceInstUsesWith(SI, NewLdexp);
435 SI.getName() + ".v", &SI);
483 SI.getName() + ".v", &SI);
510 Instruction *InstCombinerImpl::foldSelectIntoOp(SelectInst &SI, Value *TrueVal,
514 auto TryFoldSelectIntoOp = [&](SelectInst &SI, Value *TrueVal,
535 if (isa<FPMathOperator>(&SI))
536 FMF = SI.getFastMathFlags();
554 if (isa<FPMathOperator>(&SI) &&
555 !computeKnownFPClass(FalseVal, FMF, fcNan, &SI).isKnownNeverNaN())
558 Value *NewSel = Builder.CreateSelect(SI.getCondition(), Swapped ? C : OOp,
559 Swapped ? OOp : C, "", &SI);
560 if (isa<FPMathOperator>(&SI))
569 if (Instruction *R = TryFoldSelectIntoOp(SI, TrueVal, FalseVal, false))
572 if (Instruction *R = TryFoldSelectIntoOp(SI, FalseVal, TrueVal, true))
858 static Instruction *foldSelectZeroOrMul(SelectInst &SI, InstCombinerImpl &IC) {
859 auto *CondVal = SI.getCondition();
860 auto *TrueVal = SI.getTrueValue();
861 auto *FalseVal = SI.getFalseValue();
897 return IC.replaceInstUsesWith(SI, FalseValI);
1668 static Value *foldSelectInstWithICmpConst(SelectInst &SI, ICmpInst *ICI,
1677 Value *TVal = SI.getTrueValue();
1678 Value *FVal = SI.getFalseValue();
1697 if (match(&SI, m_Select(m_Specific(ICI), m_APInt(C), m_BinOp(BO))))
1699 else if (match(&SI, m_Select(m_Specific(ICI), m_BinOp(BO), m_APInt(C))))
1717 static Instruction *foldSelectICmpEq(SelectInst &SI, ICmpInst *ICI,
1723 Value *TrueVal = SI.getTrueValue();
1724 Value *FalseVal = SI.getFalseValue();
1771 return IC.replaceInstUsesWith(SI, FalseVal);
1777 return IC.replaceInstUsesWith(SI, FalseVal);
1789 return IC.replaceInstUsesWith(SI, FalseVal);
1795 return IC.replaceInstUsesWith(SI, FalseVal);
1807 return IC.replaceInstUsesWith(SI, FalseVal);
1813 return IC.replaceInstUsesWith(SI, FalseVal);
1821 Instruction *InstCombinerImpl::foldSelectInstWithICmp(SelectInst &SI,
1823 if (Instruction *NewSel = foldSelectValueEquivalence(SI, *ICI))
1827 canonicalizeSPF(*ICI, SI.getTrueValue(), SI.getFalseValue(), *this))
1828 return replaceInstUsesWith(SI, V);
1830 if (Value *V = foldSelectInstWithICmpConst(SI, ICI, Builder))
1831 return replaceInstUsesWith(SI, V);
1833 if (Value *V = canonicalizeClampLike(SI, *ICI, Builder, *this))
1834 return replaceInstUsesWith(SI, V);
1837 tryToReuseConstantFromSelectInComparison(SI, *ICI, *this))
1840 if (Value *V = foldSelectICmpAnd(SI, ICI, Builder))
1841 return replaceInstUsesWith(SI, V);
1845 Value *TrueVal = SI.getTrueValue();
1846 Value *FalseVal = SI.getFalseValue();
1853 replaceOperand(SI, 1, CmpRHS);
1857 replaceOperand(SI, 2, CmpRHS);
1862 if (Instruction *NewSel = foldSelectICmpEq(SI, ICI, *this))
1873 Builder.SetInsertPoint(&SI);
1875 replaceOperand(SI, 0, IsNeg);
1876 SI.swapValues();
1877 SI.swapProfMetadata();
1878 return &SI;
1927 return replaceInstUsesWith(SI, V);
1932 foldSelectICmpAndAnd(SI.getType(), ICI, TrueVal, FalseVal, Builder))
1936 return replaceInstUsesWith(SI, V);
1945 return replaceInstUsesWith(SI, V);
1948 return replaceInstUsesWith(SI, V);
1951 return replaceInstUsesWith(SI, V);
1954 return replaceInstUsesWith(SI, V);
1957 return replaceInstUsesWith(SI, V);
1960 return replaceInstUsesWith(SI, V);
1962 return Changed ? &SI : nullptr;
1965 /// SI is a select whose condition is a PHI node (but the two may be in
1975 const SelectInst &SI) {
1983 const PHINode *CondPHI = cast<PHINode>(SI.getCondition());
1991 if (SI.getParent() == CondPHI->getParent() &&
2023 static Instruction *foldAddSubSelect(SelectInst &SI,
2025 Value *CondVal = SI.getCondition();
2026 Value *TrueVal = SI.getTrueValue();
2027 Value *FalseVal = SI.getFalseValue();
2060 if (SI.getType()->isFPOrFPVectorTy()) {
2076 SI.getName() + ".p", &SI);
2078 if (SI.getType()->isFPOrFPVectorTy()) {
2099 foldOverflowingAddSubSelect(SelectInst &SI, InstCombiner::BuilderTy &Builder) {
2100 Value *CondVal = SI.getCondition();
2101 Value *TrueVal = SI.getTrueValue();
2102 Value *FalseVal = SI.getFalseValue();
2209 Intrinsic::getDeclaration(SI.getModule(), NewIntrinsicID, SI.getType());
2258 static Instruction *canonicalizeSelectToShuffle(SelectInst &SI) {
2259 Value *CondVal = SI.getCondition();
2290 return new ShuffleVectorInst(SI.getTrueValue(), SI.getFalseValue(), Mask);
2385 static Value *foldSelectCmpXchg(SelectInst &SI) {
2401 if (SI.hasOneUse())
2402 if (auto *Select = dyn_cast<SelectInst>(SI.user_back()))
2403 if (Select->getCondition() == SI.getCondition())
2404 if (Select->getFalseValue() == SI.getTrueValue() ||
2405 Select->getTrueValue() == SI.getFalseValue())
2409 auto *CmpXchg = isExtractFromCmpXchg(SI.getCondition(), 1);
2416 if (auto *X = isExtractFromCmpXchg(SI.getTrueValue(), 0))
2417 if (X == CmpXchg && X->getCompareOperand() == SI.getFalseValue())
2418 return SI.getFalseValue();
2423 if (auto *X = isExtractFromCmpXchg(SI.getFalseValue(), 0))
2424 if (X == CmpXchg && X->getCompareOperand() == SI.getTrueValue())
2425 return SI.getFalseValue();
2719 static Instruction *foldSelectWithSRem(SelectInst &SI, InstCombinerImpl &IC,
2721 Value *CondVal = SI.getCondition();
2722 Value *TrueVal = SI.getTrueValue();
2723 Value *FalseVal = SI.getFalseValue();
2794 /// Given that \p CondVal is known to be \p CondIsTrue, try to simplify \p SI.
2795 static Value *simplifyNestedSelectsUsingImpliedCond(SelectInst &SI,
2799 Value *InnerCondVal = SI.getCondition();
2800 Value *InnerTrueVal = SI.getTrueValue();
2801 Value *InnerFalseVal = SI.getFalseValue();
2810 SelectInst &SI,
2814 if (SI.getCondition()->getType() != Op->getType())
2816 if (Value *V = simplifyNestedSelectsUsingImpliedCond(SI, Op, IsAnd, DL))
2825 static Instruction *foldSelectWithFCmpToFabs(SelectInst &SI,
2827 Value *CondVal = SI.getCondition();
2831 Value *TrueVal = SI.getTrueValue();
2832 Value *X = SI.getFalseValue();
2845 Value *Fabs = IC.Builder.CreateUnaryIntrinsic(Intrinsic::fabs, X, &SI);
2846 return IC.replaceInstUsesWith(SI, Fabs);
2849 Value *Fabs = IC.Builder.CreateUnaryIntrinsic(Intrinsic::fabs, X, &SI);
2850 return IC.replaceInstUsesWith(SI, Fabs);
2861 if (FMF.noNaNs() && !SI.hasNoNaNs()) {
2862 SI.setHasNoNaNs(true);
2865 if (FMF.noInfs() && !SI.hasNoInfs()) {
2866 SI.setHasNoInfs(true);
2880 if (!SI.hasNoSignedZeros() || !SI.hasNoNaNs())
2892 Value *Fabs = IC.Builder.CreateUnaryIntrinsic(Intrinsic::fabs, X, &SI);
2893 return IC.replaceInstUsesWith(SI, Fabs);
2896 Value *Fabs = IC.Builder.CreateUnaryIntrinsic(Intrinsic::fabs, X, &SI);
2898 NewFNeg->setFastMathFlags(SI.getFastMathFlags());
2907 Value *TrueVal = SI.getTrueValue();
2908 Value *X = SI.getFalseValue();
2927 Value *Fabs = IC.Builder.CreateUnaryIntrinsic(Intrinsic::fabs, X, &SI);
2929 return IC.replaceInstUsesWith(SI, Fabs);
2930 return UnaryOperator::CreateFNegFMF(Fabs, &SI);
2933 return ChangedFMF ? &SI : nullptr;
2951 foldRoundUpIntegerWithPow2Alignment(SelectInst &SI,
2953 Value *Cond = SI.getCondition();
2954 Value *X = SI.getTrueValue();
2955 Value *XBiasedHighBits = SI.getFalseValue();
3006 R->takeName(&SI);
3122 Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) {
3123 Value *CondVal = SI.getCondition();
3124 Value *TrueVal = SI.getTrueValue();
3125 Value *FalseVal = SI.getFalseValue();
3126 Type *SelType = SI.getType();
3152 SI, Builder.CreateLogicalOr(A, Builder.CreateOr(B, FalseVal)));
3159 return replaceInstUsesWith(SI, V);
3200 SI, Builder.CreateLogicalAnd(A, Builder.CreateAnd(B, TrueVal)));
3207 return replaceInstUsesWith(SI, V);
3253 if (match(&SI, m_LogicalAnd(m_Not(m_Value(A)), m_Not(m_Value(B)))) &&
3260 if (match(&SI, m_LogicalOr(m_Not(m_Value(A)), m_Not(m_Value(B)))) &&
3268 return replaceOperand(SI, 0, A);
3272 return replaceOperand(SI, 0, A);
3275 if (match(&SI, m_c_LogicalAnd(m_Not(m_LogicalAnd(m_Value(A), m_Value(B))),
3314 return replaceInstUsesWith(SI, Op1);
3319 if (auto *V = foldAndOrOfICmps(ICmp0, ICmp1, SI, IsAnd,
3321 return replaceInstUsesWith(SI, V);
3331 return replaceOperand(SI, 0, A);
3337 return replaceOperand(SI, 1, A);
3346 return replaceOperand(SI, 2, A);
3352 return replaceOperand(SI, 0, A);
3490 static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) {
3491 Type *SelType = SI.getType();
3494 Value *FalseVal = SI.getFalseValue();
3495 Value *TrueVal = SI.getTrueValue();
3499 if (!match(SI.getCondition(), m_ICmp(Pred, m_Value(Cond0), m_APInt(Cond1))))
3584 Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
3585 Value *CondVal = SI.getCondition();
3586 Value *TrueVal = SI.getTrueValue();
3587 Value *FalseVal = SI.getFalseValue();
3588 Type *SelType = SI.getType();
3591 SQ.getWithInstruction(&SI)))
3592 return replaceInstUsesWith(SI, V);
3594 if (Instruction *I = canonicalizeSelectToShuffle(SI))
3597 if (Instruction *I = canonicalizeScalarSelectOfVecs(SI, *this))
3609 return replaceOperand(SI, 1, S);
3614 return replaceOperand(SI, 2, S);
3617 if (Instruction *R = foldSelectOfBools(SI))
3652 auto *SIFPOp = dyn_cast<FPMathOperator>(&SI);
3673 return replaceInstUsesWith(SI, NewSel);
3706 SI, SIFPOp->hasNoSignedZeros()))
3707 return replaceInstUsesWith(SI, Cmp0);
3718 if (match(&SI, m_OrdFMax(m_Value(X), m_Value(Y))))
3720 SI, Builder.CreateBinaryIntrinsic(Intrinsic::maxnum, X, Y, &SI));
3722 if (match(&SI, m_OrdFMin(m_Value(X), m_Value(Y))))
3724 SI, Builder.CreateBinaryIntrinsic(Intrinsic::minnum, X, Y, &SI));
3729 if (Instruction *Fabs = foldSelectWithFCmpToFabs(SI, *this))
3734 if (Instruction *Result = foldSelectInstWithICmp(SI, ICI))
3737 if (Instruction *Add = foldAddSubSelect(SI, Builder))
3739 if (Instruction *Add = foldOverflowingAddSubSelect(SI, Builder))
3741 if (Instruction *Or = foldSetClearBits(SI, Builder))
3743 if (Instruction *Mul = foldSelectZeroOrMul(SI, *this))
3750 if (Instruction *IV = foldSelectOpOp(SI, TI, FI))
3753 if (Instruction *I = foldSelectExtConst(SI))
3756 if (Instruction *I = foldSelectWithSRem(SI, *this, Builder))
3776 Builder.CreateSelect(CondVal, NewT, NewF, SI.getName() + ".idx", &SI);
3789 if (Instruction *FoldI = foldSelectIntoOp(SI, TrueVal, FalseVal))
3794 SelectPatternResult SPR = matchSelectPattern(&SI, LHS, RHS, &CastOp);
3800 RHS2, SI, SPF, RHS))
3804 RHS2, SI, SPF, LHS))
3828 cast<FPMathOperator>(SI.getCondition())->getFastMathFlags();
3833 Value *NewSI = Builder.CreateSelect(Cmp, LHS, RHS, SI.getName(), &SI);
3835 return replaceInstUsesWith(SI, NewSI);
3838 return replaceInstUsesWith(SI, NewCast);
3844 if (auto *PN = dyn_cast<PHINode>(SI.getCondition()))
3846 if (canSelectOperandBeMappingIntoPredBlock(TrueVal, SI) &&
3847 canSelectOperandBeMappingIntoPredBlock(FalseVal, SI))
3848 if (Instruction *NV = foldOpIntoPhi(SI, PN))
3857 return replaceOperand(SI, 1, V);
3865 replaceOperand(SI, 0, And);
3866 replaceOperand(SI, 1, TrueSI->getTrueValue());
3867 return &SI;
3877 return replaceOperand(SI, 2, V);
3882 replaceOperand(SI, 0, Or);
3883 replaceOperand(SI, 2, FalseSI->getFalseValue());
3884 return &SI;
3901 return &SI;
3908 return &SI;
3920 return &SI;
3927 return &SI;
3934 !InstCombiner::shouldAvoidAbsorbingNotIntoSelect(SI)) {
3935 replaceOperand(SI, 0, NotCond);
3936 SI.swapValues();
3937 SI.swapProfMetadata();
3938 return &SI;
3941 if (Instruction *I = foldVectorSelect(SI))
3951 computeKnownBits(CondVal, Known, 0, &SI);
3953 return replaceInstUsesWith(SI, TrueVal);
3955 return replaceInstUsesWith(SI, FalseVal);
3958 if (Instruction *BitCastSel = foldSelectCmpBitcasts(SI, Builder))
3962 if (Value *V = foldSelectCmpXchg(SI))
3963 return replaceInstUsesWith(SI, V);
3965 if (Instruction *Select = foldSelectBinOpIdentity(SI, TLI, *this))
3968 if (Instruction *Funnel = foldSelectFunnelShift(SI, Builder))
3971 if (Instruction *Copysign = foldSelectToCopysign(SI, Builder))
3974 if (Instruction *PN = foldSelectToPhi(SI, DT, Builder))
3975 return replaceInstUsesWith(SI, PN);
3977 if (Value *Fr = foldSelectWithFrozenICmp(SI, Builder))
3978 return replaceInstUsesWith(SI, Fr);
3980 if (Value *V = foldRoundUpIntegerWithPow2Alignment(SI, Builder))
3981 return replaceInstUsesWith(SI, V);
3993 return replaceInstUsesWith(SI, MaskedInst);
4008 if (Value *V = simplifyAndInst(CondVal, Mask, SQ.getWithInstruction(&SI)))
4015 return replaceInstUsesWith(SI, MaskedInst);
4019 if (Instruction *I = foldSelectOfSymmetricSelect(SI, Builder))
4022 if (Instruction *I = foldNestedSelects(SI, Builder))
4029 if (sinkNotIntoOtherHandOfLogicalOp(SI))
4030 return &SI;
4032 if (Instruction *I = foldBitCeil(SI, Builder))
4043 SQ.getWithInstruction(&SI)))
4081 if (CondVal->getType() == SI.getType() && isKnownInversion(FalseVal, TrueVal))
4093 SimplifyQuery Q = SQ.getWithInstruction(&SI).getWithCondContext(CC);
4099 return replaceOperand(SI, 1,
4108 return replaceOperand(SI, 2,