[llvm] [InstCombine] Fold zext(X) + C2 pred C -> X + C3 pred C4 (PR #110511)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 6 00:36:29 PDT 2024
================
@@ -3168,6 +3168,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(
----------------
dtcxzyw wrote:
We need a new ConstantRange API to convert ranges for `zext(V)` to ranges for `V`.
For example, we can convert `zext(i8 X to i32) - 255 u< -4` to `X + 1 u< -4`. But current implementation cannot achieve this.
https://github.com/llvm/llvm-project/pull/110511
More information about the llvm-commits
mailing list