[llvm] [InstCombine] Fold zext(X) + C2 pred C -> X + C3 pred C4 (PR #110511)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 20 02:17:31 PST 2024
================
@@ -3169,6 +3169,31 @@ Instruction *InstCombinerImpl::foldICmpAddConstant(ICmpInst &Cmp,
Builder.CreateAdd(X, ConstantInt::get(Ty, *C2 - C - 1)),
ConstantInt::get(Ty, ~C));
+ // zext(V) + C2 pred C -> V + C3 pred' C4
+ Value *V;
+ if (match(X, m_ZExt(m_Value(V)))) {
+ Type *NewCmpTy = V->getType();
+ unsigned CmpBW = Ty->getScalarSizeInBits();
+ unsigned NewCmpBW = NewCmpTy->getScalarSizeInBits();
+ if (shouldChangeType(Ty, NewCmpTy)) {
+ if (auto ZExtCR = CR.exactIntersectWith(ConstantRange(
+ APInt::getZero(CmpBW), APInt::getOneBitSet(CmpBW, NewCmpBW)))) {
----------------
nikic wrote:
Can this condition be written as `CR.getActiveBits() <= NewCmpBW`? The exact intersection here seems pretty roundabout.
https://github.com/llvm/llvm-project/pull/110511
More information about the llvm-commits
mailing list