[llvm] [InstCombine] Fold adds + shifts with nsw and nuw flags (PR #88193)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 9 14:27:31 PDT 2024


================
@@ -1267,6 +1267,19 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
       match(Op1, m_SpecificIntAllowUndef(BitWidth - 1)))
     return new ZExtInst(Builder.CreateIsNotNeg(X, "isnotneg"), Ty);
 
+  // Special Case:
+  // if both the add and the shift are nuw, we can omit the AND entirely
+  // ((X << Y) nuw + Z nuw) >>u Z --> (X + (Y >>u Z))
----------------
AtariDreams wrote:

Yeah

https://github.com/llvm/llvm-project/pull/88193


More information about the llvm-commits mailing list