[llvm] [InstCombine] Fold ((X << nuw Z) binop nuw Y) >>u Z --> X binop nuw (Y >>u Z) (PR #88193)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue May 7 08:54:19 PDT 2024
================
@@ -1259,6 +1259,53 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
match(Op1, m_SpecificIntAllowPoison(BitWidth - 1)))
return new ZExtInst(Builder.CreateIsNotNeg(X, "isnotneg"), Ty);
+ // ((X << nuw Z) sub nuw Y) >>u exact Z --> X sub nuw (Y >>u exact Z),
+ // ONLY if I is exact, and both the shift and sub are nuw
+ Value *Y;
+ if (I.isExact() &&
+ match(Op0, m_OneUse(m_NUWSub(m_NUWShl(m_Value(X), m_Specific(Op1)),
+ m_Value(Y))))) {
+ Value *NewLshr = Builder.CreateLShr(Y, Op1, "", /* isExact */ true);
----------------
dtcxzyw wrote:
```suggestion
Value *NewLshr = Builder.CreateLShr(Y, Op1, "", /*isExact=*/true);
```
https://github.com/llvm/llvm-project/pull/88193
More information about the llvm-commits
mailing list