[PATCH] ValueTracking: Teach isKnownToBeAPowerOfTwo that a power-of-two-or-zero + the same power-of-two-or-zero is a power-of-two-or-zero
Jay Foad
jay.foad at gmail.com
Mon Jul 29 04:20:23 PDT 2013
On 13 July 2013 23:21, David Majnemer <david.majnemer at gmail.com> wrote:
> On Sat, Jul 13, 2013 at 12:03 PM, Nick Lewycky <nicholas at mxc.ca> wrote:
>>
>> David Majnemer wrote:
>>>
>>> Attached is a patch to strengthen isKnownToBeAPowerOfTwo's analysis on
>>> add instructions.
>>>
>>> It calls into ComputeMaskedBits to figure out which bits are set on both
>>> add operands and determines if the value is a power-of-two-or-zero or
>>> not.
The logic looks OK to me.
I think you could relax this condition this a tiny bit:
+ APInt ComplementLHSZeroBits = ~LHSZeroBits;
+ if (ComplementLHSZeroBits == ~RHSZeroBits &&
+ ComplementLHSZeroBits.isPowerOf2()) {
to:
if ((~(LHSZeroBits & RHSZeroBits)).isPowerOf2())
but that's mostly a matter of taste. (It would be nice if there was an
APInt::isPowerOf2OrZero.)
Jay.
More information about the llvm-commits
mailing list