[InstCombine] Don't eagerly propagate nsw for A*B+A*C => A*(B+C)
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 22 May 2015 23:02:11 +0000 (23:02 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 22 May 2015 23:02:11 +0000 (23:02 +0000)
commit12baade49832cdeb0fcc44dfe24f08b946c77763
tree72ccab11be752f7c62509d229d5f73cab771486f
parent464deacf054ac64f7952a8da7ddb1fda8651e053
[InstCombine] Don't eagerly propagate nsw for A*B+A*C => A*(B+C)

InstCombine transforms 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.

We need to first make sure that we won't multiple by INT_SMAX + 1.

Test case `add_of_mul` contributed by Sanjoy Das.

This fixes PR23635.

Differential Revision: http://reviews.llvm.org/D9629

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238066 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/add2.ll