InstCombine: Fix miscompile in X % -Y -> X % Y transform
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 13 Oct 2014 22:37:51 +0000 (22:37 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 13 Oct 2014 22:37:51 +0000 (22:37 +0000)
commitaf6be11a601711f9c41a0f51acd3efcee5e00222
tree60fd27a96bccc1727aa3b596ef7de33e8c55f4d1
parent3a143ce2e79a7a7a12981f2d13ea771ff31ff888
InstCombine: Fix miscompile in X % -Y -> X % Y transform

We assumed that negation operations of the form (0 - %Z) resulted in a
negative number.  This isn't true if %Z was originally negative.
Substituting the negative number into the remainder operation may result
in undefined behavior because the dividend might be INT_MIN.

This fixes PR21256.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219639 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
test/Transforms/InstCombine/apint-sub.ll
test/Transforms/InstCombine/sub.ll