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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 23:42:51 PDT 2024


================
@@ -1450,9 +1460,24 @@ Instruction *InstCombinerImpl::visitLShr(BinaryOperator &I) {
           NewMul->setHasNoSignedWrap(true);
           return NewMul;
         }
+
+        // Special case: lshr nuw (mul (X, 3), 1) -> add nuw nsw (X, lshr(X, 1)
+        if (ShAmtC == 1 && MulC->getZExtValue() == 3) {
----------------
arsenm wrote:

Is there a more general form for this than these specific constants? Why is this the one special case? 

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


More information about the llvm-commits mailing list