[PATCH] D132777: [InstCombine] Propagate the nuw for combine of add+mul

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 27 06:05:25 PDT 2022


spatel added a comment.

Please include a general proof link to Alive2.



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:236
+      if (I.hasNoUnsignedWrap() && BOp0->hasNoUnsignedWrap()) {
+        cast<BinaryOperator>(NewMul)->setHasNoUnsignedWrap();
+        BO->setHasNoUnsignedWrap();
----------------
To be safe, use "dyn_cast" here. I don't have an example, but it is possible that the builder can constant fold the multiply, so the NewMul is not a BinaryOperator at this point.


================
Comment at: llvm/test/Transforms/InstCombine/mul.ll:628
+; Keep nuw flag in this change
+define i32 @add_mul_nuw(i32 %a) {
+; CHECK-LABEL: @add_mul_nuw(
----------------
Do we have tests where only the add or only the mul has nuw?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132777/new/

https://reviews.llvm.org/D132777



More information about the llvm-commits mailing list