@@ -4082,23 +4082,22 @@ Instruction *InstCombinerImpl::foldSelectICmp(ICmpInst::Predicate Pred,
40824082// / The Mask can be a constant, too.
40834083// / For some predicates, the operands are commutative.
40844084// / For others, x can only be on a specific side.
4085- static Value *foldICmpWithLowBitMaskedVal (ICmpInst &I,
4085+ static Value *foldICmpWithLowBitMaskedVal (ICmpInst::Predicate Pred, Value *Op0,
4086+ Value *Op1,
40864087 InstCombiner::BuilderTy &Builder) {
4087- ICmpInst::Predicate SrcPred;
4088- Value *X, *M, *Y;
4088+ Value *M, *Y;
40894089 auto m_VariableMask = m_CombineOr (
40904090 m_CombineOr (m_Not (m_Shl (m_AllOnes (), m_Value ())),
40914091 m_Add (m_Shl (m_One (), m_Value ()), m_AllOnes ())),
40924092 m_CombineOr (m_LShr (m_AllOnes (), m_Value ()),
40934093 m_LShr (m_Shl (m_AllOnes (), m_Value (Y)), m_Deferred (Y))));
40944094 auto m_Mask = m_CombineOr (m_VariableMask, m_LowBitMask ());
4095- if (!match (&I, m_c_ICmp (SrcPred,
4096- m_c_And (m_CombineAnd (m_Mask, m_Value (M)), m_Value (X)),
4097- m_Deferred (X))))
4095+
4096+ if (!match (Op0, m_c_And (m_CombineAnd (m_Mask, m_Value (M)), m_Specific (Op1))))
40984097 return nullptr ;
40994098
41004099 ICmpInst::Predicate DstPred;
4101- switch (SrcPred ) {
4100+ switch (Pred ) {
41024101 case ICmpInst::Predicate::ICMP_EQ:
41034102 // x & (-1 >> y) == x -> x u<= (-1 >> y)
41044103 DstPred = ICmpInst::Predicate::ICMP_ULE;
@@ -4164,7 +4163,7 @@ static Value *foldICmpWithLowBitMaskedVal(ICmpInst &I,
41644163 M = Constant::replaceUndefsWith (VecC, SafeReplacementConstant);
41654164 }
41664165
4167- return Builder.CreateICmp (DstPred, X , M);
4166+ return Builder.CreateICmp (DstPred, Op1 , M);
41684167}
41694168
41704169// / Some comparisons can be simplified.
@@ -5081,9 +5080,6 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
50815080 if (Value *V = foldMultiplicationOverflowCheck (I))
50825081 return replaceInstUsesWith (I, V);
50835082
5084- if (Value *V = foldICmpWithLowBitMaskedVal (I, Builder))
5085- return replaceInstUsesWith (I, V);
5086-
50875083 if (Instruction *R = foldICmpAndXX (I, Q, *this ))
50885084 return R;
50895085
@@ -6984,6 +6980,9 @@ Instruction *InstCombinerImpl::foldICmpCommutative(ICmpInst::Predicate Pred,
69846980 }
69856981 }
69866982
6983+ if (Value *V = foldICmpWithLowBitMaskedVal (Pred, Op0, Op1, Builder))
6984+ return replaceInstUsesWith (CxtI, V);
6985+
69876986 return nullptr ;
69886987}
69896988
0 commit comments