@@ -4082,23 +4082,22 @@ Instruction *InstCombinerImpl::foldSelectICmp(ICmpInst::Predicate Pred,
4082
4082
// / The Mask can be a constant, too.
4083
4083
// / For some predicates, the operands are commutative.
4084
4084
// / 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,
4086
4087
InstCombiner::BuilderTy &Builder) {
4087
- ICmpInst::Predicate SrcPred;
4088
- Value *X, *M, *Y;
4088
+ Value *M, *Y;
4089
4089
auto m_VariableMask = m_CombineOr (
4090
4090
m_CombineOr (m_Not (m_Shl (m_AllOnes (), m_Value ())),
4091
4091
m_Add (m_Shl (m_One (), m_Value ()), m_AllOnes ())),
4092
4092
m_CombineOr (m_LShr (m_AllOnes (), m_Value ()),
4093
4093
m_LShr (m_Shl (m_AllOnes (), m_Value (Y)), m_Deferred (Y))));
4094
4094
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))))
4098
4097
return nullptr ;
4099
4098
4100
4099
ICmpInst::Predicate DstPred;
4101
- switch (SrcPred ) {
4100
+ switch (Pred ) {
4102
4101
case ICmpInst::Predicate::ICMP_EQ:
4103
4102
// x & (-1 >> y) == x -> x u<= (-1 >> y)
4104
4103
DstPred = ICmpInst::Predicate::ICMP_ULE;
@@ -4164,7 +4163,7 @@ static Value *foldICmpWithLowBitMaskedVal(ICmpInst &I,
4164
4163
M = Constant::replaceUndefsWith (VecC, SafeReplacementConstant);
4165
4164
}
4166
4165
4167
- return Builder.CreateICmp (DstPred, X , M);
4166
+ return Builder.CreateICmp (DstPred, Op1 , M);
4168
4167
}
4169
4168
4170
4169
// / Some comparisons can be simplified.
@@ -5081,9 +5080,6 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
5081
5080
if (Value *V = foldMultiplicationOverflowCheck (I))
5082
5081
return replaceInstUsesWith (I, V);
5083
5082
5084
- if (Value *V = foldICmpWithLowBitMaskedVal (I, Builder))
5085
- return replaceInstUsesWith (I, V);
5086
-
5087
5083
if (Instruction *R = foldICmpAndXX (I, Q, *this ))
5088
5084
return R;
5089
5085
@@ -6984,6 +6980,9 @@ Instruction *InstCombinerImpl::foldICmpCommutative(ICmpInst::Predicate Pred,
6984
6980
}
6985
6981
}
6986
6982
6983
+ if (Value *V = foldICmpWithLowBitMaskedVal (Pred, Op0, Op1, Builder))
6984
+ return replaceInstUsesWith (CxtI, V);
6985
+
6987
6986
return nullptr ;
6988
6987
}
6989
6988
0 commit comments