1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

[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
This commit is contained in:
Craig Topper 2017-04-06 21:06:03 +00:00
parent 5f1e090b9b
commit bb70356d71

View File

@ -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);
}
}
}