@@ -818,11 +818,11 @@ static Value *foldSignedTruncationCheck(ICmpInst *ICmp0, ICmpInst *ICmp1,
818818 // Match icmp ult (add %arg, C01), C1 (C1 == C01 << 1; powers of two)
819819 auto tryToMatchSignedTruncationCheck = [](ICmpInst *ICmp, Value *&X,
820820 APInt &SignBitMask) -> bool {
821- CmpInst::Predicate Pred;
822821 const APInt *I01, *I1; // powers of two; I1 == I01 << 1
823- if (!(match (ICmp,
824- m_ICmp (Pred, m_Add (m_Value (X), m_Power2 (I01)), m_Power2 (I1))) &&
825- Pred == ICmpInst::ICMP_ULT && I1->ugt (*I01) && I01->shl (1 ) == *I1))
822+ if (!(match (ICmp, m_SpecificICmp (ICmpInst::ICMP_ULT,
823+ m_Add (m_Value (X), m_Power2 (I01)),
824+ m_Power2 (I1))) &&
825+ I1->ugt (*I01) && I01->shl (1 ) == *I1))
826826 return false ;
827827 // Which bit is the new sign bit as per the 'signed truncation' pattern?
828828 SignBitMask = *I01;
@@ -936,20 +936,21 @@ static Value *foldIsPowerOf2(ICmpInst *Cmp0, ICmpInst *Cmp1, bool JoinedByAnd,
936936 std::swap (Cmp0, Cmp1);
937937
938938 // (X != 0) && (ctpop(X) u< 2) --> ctpop(X) == 1
939- CmpInst::Predicate Pred0, Pred1;
940939 Value *X;
941- if (JoinedByAnd && match (Cmp0, m_ICmp (Pred0, m_Value (X), m_ZeroInt ())) &&
942- match (Cmp1, m_ICmp (Pred1, m_Intrinsic<Intrinsic::ctpop>(m_Specific (X)),
943- m_SpecificInt (2 ))) &&
944- Pred0 == ICmpInst::ICMP_NE && Pred1 == ICmpInst::ICMP_ULT) {
940+ if (JoinedByAnd &&
941+ match (Cmp0, m_SpecificICmp (ICmpInst::ICMP_NE, m_Value (X), m_ZeroInt ())) &&
942+ match (Cmp1, m_SpecificICmp (ICmpInst::ICMP_ULT,
943+ m_Intrinsic<Intrinsic::ctpop>(m_Specific (X)),
944+ m_SpecificInt (2 )))) {
945945 Value *CtPop = Cmp1->getOperand (0 );
946946 return Builder.CreateICmpEQ (CtPop, ConstantInt::get (CtPop->getType (), 1 ));
947947 }
948948 // (X == 0) || (ctpop(X) u> 1) --> ctpop(X) != 1
949- if (!JoinedByAnd && match (Cmp0, m_ICmp (Pred0, m_Value (X), m_ZeroInt ())) &&
950- match (Cmp1, m_ICmp (Pred1, m_Intrinsic<Intrinsic::ctpop>(m_Specific (X)),
951- m_SpecificInt (1 ))) &&
952- Pred0 == ICmpInst::ICMP_EQ && Pred1 == ICmpInst::ICMP_UGT) {
949+ if (!JoinedByAnd &&
950+ match (Cmp0, m_SpecificICmp (ICmpInst::ICMP_EQ, m_Value (X), m_ZeroInt ())) &&
951+ match (Cmp1, m_SpecificICmp (ICmpInst::ICMP_UGT,
952+ m_Intrinsic<Intrinsic::ctpop>(m_Specific (X)),
953+ m_SpecificInt (1 )))) {
953954 Value *CtPop = Cmp1->getOperand (0 );
954955 return Builder.CreateICmpNE (CtPop, ConstantInt::get (CtPop->getType (), 1 ));
955956 }
@@ -1608,31 +1609,30 @@ static Instruction *reassociateFCmps(BinaryOperator &BO,
16081609 // There are 4 commuted variants of the pattern. Canonicalize operands of this
16091610 // logic op so an fcmp is operand 0 and a matching logic op is operand 1.
16101611 Value *Op0 = BO.getOperand (0 ), *Op1 = BO.getOperand (1 ), *X;
1611- FCmpInst::Predicate Pred;
1612- if (match (Op1, m_FCmp (Pred, m_Value (), m_AnyZeroFP ())))
1612+ if (match (Op1, m_FCmp (m_Value (), m_AnyZeroFP ())))
16131613 std::swap (Op0, Op1);
16141614
16151615 // Match inner binop and the predicate for combining 2 NAN checks into 1.
16161616 Value *BO10, *BO11;
16171617 FCmpInst::Predicate NanPred = Opcode == Instruction::And ? FCmpInst::FCMP_ORD
16181618 : FCmpInst::FCMP_UNO;
1619- if (!match (Op0, m_FCmp (Pred , m_Value (X), m_AnyZeroFP ())) || Pred != NanPred ||
1619+ if (!match (Op0, m_SpecificFCmp (NanPred , m_Value (X), m_AnyZeroFP ())) ||
16201620 !match (Op1, m_BinOp (Opcode, m_Value (BO10), m_Value (BO11))))
16211621 return nullptr ;
16221622
16231623 // The inner logic op must have a matching fcmp operand.
16241624 Value *Y;
1625- if (!match (BO10, m_FCmp (Pred , m_Value (Y), m_AnyZeroFP ())) ||
1626- Pred != NanPred || X->getType () != Y->getType ())
1625+ if (!match (BO10, m_SpecificFCmp (NanPred , m_Value (Y), m_AnyZeroFP ())) ||
1626+ X->getType () != Y->getType ())
16271627 std::swap (BO10, BO11);
16281628
1629- if (!match (BO10, m_FCmp (Pred , m_Value (Y), m_AnyZeroFP ())) ||
1630- Pred != NanPred || X->getType () != Y->getType ())
1629+ if (!match (BO10, m_SpecificFCmp (NanPred , m_Value (Y), m_AnyZeroFP ())) ||
1630+ X->getType () != Y->getType ())
16311631 return nullptr ;
16321632
16331633 // and (fcmp ord X, 0), (and (fcmp ord Y, 0), Z) --> and (fcmp ord X, Y), Z
16341634 // or (fcmp uno X, 0), (or (fcmp uno Y, 0), Z) --> or (fcmp uno X, Y), Z
1635- Value *NewFCmp = Builder.CreateFCmp (Pred , X, Y);
1635+ Value *NewFCmp = Builder.CreateFCmp (NanPred , X, Y);
16361636 if (auto *NewFCmpInst = dyn_cast<FCmpInst>(NewFCmp)) {
16371637 // Intersect FMF from the 2 source fcmps.
16381638 NewFCmpInst->copyIRFlags (Op0);
@@ -1744,14 +1744,13 @@ Instruction *InstCombinerImpl::foldCastedBitwiseLogic(BinaryOperator &I) {
17441744 // -> zext(bitwise(A < 0, icmp))
17451745 auto FoldBitwiseICmpZeroWithICmp = [&](Value *Op0,
17461746 Value *Op1) -> Instruction * {
1747- ICmpInst::Predicate Pred;
17481747 Value *A;
17491748 bool IsMatched =
17501749 match (Op0,
17511750 m_OneUse (m_LShr (
17521751 m_Value (A),
17531752 m_SpecificInt (Op0->getType ()->getScalarSizeInBits () - 1 )))) &&
1754- match (Op1, m_OneUse (m_ZExt (m_ICmp (Pred, m_Value (), m_Value ()))));
1753+ match (Op1, m_OneUse (m_ZExt (m_ICmp (m_Value (), m_Value ()))));
17551754
17561755 if (!IsMatched)
17571756 return nullptr ;
@@ -3878,14 +3877,14 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
38783877 if (match (&I,
38793878 m_c_Or (m_CombineAnd (m_ExtractValue<1 >(m_Value (UMulWithOv)),
38803879 m_Value (Ov)),
3881- m_CombineAnd (m_ICmp (Pred,
3882- m_CombineAnd (m_ExtractValue< 0 >(
3883- m_Deferred (UMulWithOv)),
3884- m_Value (Mul )),
3885- m_ZeroInt ( )),
3886- m_Value (MulIsNotZero)))) &&
3887- (Ov-> hasOneUse () || (MulIsNotZero-> hasOneUse () && Mul-> hasOneUse ( ))) &&
3888- Pred == CmpInst::ICMP_NE ) {
3880+ m_CombineAnd (
3881+ m_SpecificICmp (ICmpInst::ICMP_NE,
3882+ m_CombineAnd (m_ExtractValue< 0 >(
3883+ m_Deferred (UMulWithOv )),
3884+ m_Value (Mul )),
3885+ m_ZeroInt ()),
3886+ m_Value (MulIsNotZero) ))) &&
3887+ (Ov-> hasOneUse () || (MulIsNotZero-> hasOneUse () && Mul-> hasOneUse ())) ) {
38893888 Value *A, *B;
38903889 if (match (UMulWithOv, m_Intrinsic<Intrinsic::umul_with_overflow>(
38913890 m_Value (A), m_Value (B)))) {
0 commit comments