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

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 04:24:34 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) {
----------------
AtariDreams wrote:

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

(X+(x<<1))>>1 is canonicalized to x*3/2 so this is missed as a result

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


More information about the llvm-commits mailing list