[PATCH] [InstCombine] Don't propagate nsw for A*B+A*C => A*(B+C).

Sanjoy Das sanjoy at playingwithpointers.com
Fri May 8 16:22:50 PDT 2015


Hi majnemer, IlyaKrotov,

InstCombine transform `A *nsw B +nsw A *nsw C` to `A *nsw (B + C)`.
This is incorrect -- e.g. if A = -1, B = 1, C = INT_SMAX.  Then
nothing in the LHS overflows, but the multiplication in RHS overflows.

I'll have to admit that this proposed fix is a bit heavy-handed -- if
you think this will materially affect optimization then we can try to do
this transform for cases where we can prove correctness.  For instance,
I *think* (but have not proved) that we can transform `(A +nsw A) +nsw
A` to `A *nsw 3`.

http://reviews.llvm.org/D9629

Files:
  lib/Transforms/InstCombine/InstructionCombining.cpp
  test/Transforms/InstCombine/add2.ll

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9629.25386.patch
Type: text/x-patch
Size: 3093 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150508/4af5e2f4/attachment.bin>


More information about the llvm-commits mailing list