InstCombine: Don't miscompile X % ((Pow2 << A) >>u B)
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 14 Oct 2014 20:28:40 +0000 (20:28 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 14 Oct 2014 20:28:40 +0000 (20:28 +0000)
commit505187a9bd6beb779d3ae76b44efa69a72f68173
treebb83bc84bda76ad9c1ca9b83979e67453887a260
parentd6315ea5a52251420e98ed0fa096c513ce7f57f9
InstCombine: Don't miscompile X % ((Pow2 << A) >>u B)

We assumed that A must be greater than B because the right hand side of
a remainder operator must be nonzero.

However, it is possible for A to be less than B if Pow2 is a power of
two greater than 1.

Take for example:
i32 %A = 0
i32 %B = 31
i32 Pow2 = 2147483648

((Pow2 << 0) >>u 31) is non-zero but A is less than B.

This fixes PR21274.

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