[llvm] f89e4e3 - [InstCombine] Move `foldICmpWithLowBitMaskedVal` to `foldICmpCommutative`; NFC
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 10 12:33:52 PDT 2024
Author: Noah Goldstein
Date: 2024-03-10T14:33:34-05:00
New Revision: f89e4e339f31ad331aeab9a35183bc75bc42f2b6
URL: https://github.com/llvm/llvm-project/commit/f89e4e339f31ad331aeab9a35183bc75bc42f2b6
DIFF: https://github.com/llvm/llvm-project/commit/f89e4e339f31ad331aeab9a35183bc75bc42f2b6.diff
LOG: [InstCombine] Move `foldICmpWithLowBitMaskedVal` to `foldICmpCommutative`; NFC
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index fc2688f425bb8f..8786ef1c6b082d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -4082,23 +4082,22 @@ Instruction *InstCombinerImpl::foldSelectICmp(ICmpInst::Predicate Pred,
/// The Mask can be a constant, too.
/// For some predicates, the operands are commutative.
/// For others, x can only be on a specific side.
-static Value *foldICmpWithLowBitMaskedVal(ICmpInst &I,
+static Value *foldICmpWithLowBitMaskedVal(ICmpInst::Predicate Pred, Value *Op0,
+ Value *Op1,
InstCombiner::BuilderTy &Builder) {
- ICmpInst::Predicate SrcPred;
- Value *X, *M, *Y;
+ Value *M, *Y;
auto m_VariableMask = m_CombineOr(
m_CombineOr(m_Not(m_Shl(m_AllOnes(), m_Value())),
m_Add(m_Shl(m_One(), m_Value()), m_AllOnes())),
m_CombineOr(m_LShr(m_AllOnes(), m_Value()),
m_LShr(m_Shl(m_AllOnes(), m_Value(Y)), m_Deferred(Y))));
auto m_Mask = m_CombineOr(m_VariableMask, m_LowBitMask());
- if (!match(&I, m_c_ICmp(SrcPred,
- m_c_And(m_CombineAnd(m_Mask, m_Value(M)), m_Value(X)),
- m_Deferred(X))))
+
+ if (!match(Op0, m_c_And(m_CombineAnd(m_Mask, m_Value(M)), m_Specific(Op1))))
return nullptr;
ICmpInst::Predicate DstPred;
- switch (SrcPred) {
+ switch (Pred) {
case ICmpInst::Predicate::ICMP_EQ:
// x & (-1 >> y) == x -> x u<= (-1 >> y)
DstPred = ICmpInst::Predicate::ICMP_ULE;
@@ -4164,7 +4163,7 @@ static Value *foldICmpWithLowBitMaskedVal(ICmpInst &I,
M = Constant::replaceUndefsWith(VecC, SafeReplacementConstant);
}
- return Builder.CreateICmp(DstPred, X, M);
+ return Builder.CreateICmp(DstPred, Op1, M);
}
/// Some comparisons can be simplified.
@@ -5081,9 +5080,6 @@ Instruction *InstCombinerImpl::foldICmpBinOp(ICmpInst &I,
if (Value *V = foldMultiplicationOverflowCheck(I))
return replaceInstUsesWith(I, V);
- if (Value *V = foldICmpWithLowBitMaskedVal(I, Builder))
- return replaceInstUsesWith(I, V);
-
if (Instruction *R = foldICmpAndXX(I, Q, *this))
return R;
@@ -6984,6 +6980,9 @@ Instruction *InstCombinerImpl::foldICmpCommutative(ICmpInst::Predicate Pred,
}
}
+ if (Value *V = foldICmpWithLowBitMaskedVal(Pred, Op0, Op1, Builder))
+ return replaceInstUsesWith(CxtI, V);
+
return nullptr;
}
More information about the llvm-commits
mailing list