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

Noah Goldstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 22 11:59:41 PDT 2023


goldstein.w.n added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp:264
       return BinaryOperator::CreateMul(
           NegOp0, ConstantExpr::getNeg(cast<Constant>(Op1)), I.getName());
 
----------------
nikic wrote:
> goldstein.w.n wrote:
> > You can have NSW on this mul given that `Op1` is a constant.
> I don't think you can add nsw on the mul if I got this right: https://alive2.llvm.org/ce/z/lSk99J
> 
> Though it looks like passing nsw to the negator would be okay: https://alive2.llvm.org/ce/z/MrwT5K
You have it right, the idea though is that since `Op1` is a constant we can infer when it would be NSW i.e:
https://alive2.llvm.org/ce/z/6JPtJR


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

https://reviews.llvm.org/D158510



More information about the llvm-commits mailing list