InstCombine: Don't unconditionally preserve 'nsw' when shrinking constants
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 22 Aug 2014 07:56:32 +0000 (07:56 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 22 Aug 2014 07:56:32 +0000 (07:56 +0000)
commitc86bdc73e8b3f69708fafc1ce957216062c995cd
tree2c1629fd4a55fd6072ce615a2e56efa4efd8a011
parent6ca2d8b7c7461910610405e8bde5ef0ca9506d62
InstCombine: Don't unconditionally preserve 'nsw' when shrinking constants

Consider:
  %add = add nsw i32 %a, -16777216
  %and = and i32 %add, 255

Regardless of whether or not we demand the sign bit of %add, we cannot
replace -16777216 with 2130706432 without also removing 'nsw' from the
instruction.

This fixes PR20377.

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