[PATCH] D158510: [InstCombine] Propagate nsw flag when negating

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 22 09:39:17 PDT 2023


goldstein.w.n added a comment.

All of these except the `-1 << X` case work for NUW as well: https://alive2.llvm.org/ce/z/zzPZRQ
Maybe instead of a bool pass a bitmask of flags? Would make it easier to add `NUW` support in a followup.



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:264
       return BinaryOperator::CreateMul(
           NegOp0, ConstantExpr::getNeg(cast<Constant>(Op1)), I.getName());
 
----------------
You can have NSW on this mul given that `Op1` is a constant.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineNegator.cpp:241
+                             I->getName() + ".neg", /* HasNUW */ false,
+                             IsNSW && I->hasNoSignedWrap());
   }
----------------
Nit: I would rename `IsNSW` to `MayNSW` or `ParentNSW` as that seems to more accurately represent the usage.


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

https://reviews.llvm.org/D158510



More information about the llvm-commits mailing list