diff options
| author | Craig Topper <craig.topper@gmail.com> | 2017-04-06 21:06:03 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@gmail.com> | 2017-04-06 21:06:03 +0000 |
| commit | b4da6840d85a9d0b62da4915ff0f9c075d6d8c7c (patch) | |
| tree | 8bde2ae6746b13d2f09e3eb2049760a08847a0f0 /llvm | |
| parent | 9b9800951da1c342223bd174dc1fcd441b6061b7 (diff) | |
| download | bcm5719-llvm-b4da6840d85a9d0b62da4915ff0f9c075d6d8c7c.tar.gz bcm5719-llvm-b4da6840d85a9d0b62da4915ff0f9c075d6d8c7c.zip | |
[InstCombine] When checking to see if we can turn subtracts of 2^n - 1 into xor, we only need to call computeKnownBits on the RHS not the whole subtract. While there use isMask instead of isPowerOf2(C+1)
Calling computeKnownBits on the RHS should allows us to recurse one step further. isMask is equivalent to the isPowerOf2(C+1) except in the case where C is all ones. But that was already handled earlier by creating a not which is an Xor with all ones. So this should be fine.
llvm-svn: 299710
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index b9c73370f96..a0d74677dc6 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1621,12 +1621,14 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { // Turn this into a xor if LHS is 2^n-1 and the remaining bits are known // zero. - if ((*Op0C + 1).isPowerOf2()) { - APInt KnownZero(BitWidth, 0); - APInt KnownOne(BitWidth, 0); - computeKnownBits(&I, KnownZero, KnownOne, 0, &I); - if ((*Op0C | KnownZero).isAllOnesValue()) + if (Op0C->isMask()) { + APInt RHSKnownZero(BitWidth, 0); + APInt RHSKnownOne(BitWidth, 0); + computeKnownBits(Op1, RHSKnownZero, RHSKnownOne, 0, &I); + if ((*Op0C | RHSKnownZero).isAllOnesValue()) { + assert(0); return BinaryOperator::CreateXor(Op1, Op0); + } } } |

