[ValueTracking] Recognize that and(x, add (x, -1)) clears the low bit
authorPhilip Reames <listmail@philipreames.com>
Tue, 10 Nov 2015 18:46:14 +0000 (18:46 +0000)
committerPhilip Reames <listmail@philipreames.com>
Tue, 10 Nov 2015 18:46:14 +0000 (18:46 +0000)
commit6054badbddce7b3a779aba0f7c553fe69c9a0abc
treed740d6fa233ddbcd7e46f69759ee43ac4a0da9e2
parenta407ebde72396bb2395b1ec73162b7771a858836
[ValueTracking] Recognize that and(x, add (x, -1)) clears the low bit

This is a cleaned up version of a patch by John Regehr with permission. Originally found via the souper tool.

If we add an odd number to x, then bitwise-and the result with x, we know that the low bit of the result must be zero. Either it was zero in x originally, or the add cleared it in the temporary value. As a result, one of the two values anded together must have the bit cleared.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252629 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/ValueTracking.cpp
test/Transforms/InstSimplify/add-mask.ll [new file with mode: 0644]