[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

David Majnemer david.majnemer at gmail.com
Fri Jul 26 13:04:45 PDT 2013


Ping


On Sat, Jul 13, 2013 at 3:21 PM, 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.
>>>
>>
>> +  // adding a power-of-two or zero to the same power-of-two or zero
>> yields
>> +  // either the original power-of-two, a larger power-of-two or zero.
>>
>> Sentences start with capital letters.
>>
>
> Done.
>
>
>>
>> -    if (OverflowingBinaryOperator *VOBO = cast<**
>> OverflowingBinaryOperator>(V))
>> +    OverflowingBinaryOperator *VOBO = cast<**
>> OverflowingBinaryOperator>(V);
>>
>> Thank you!
>>
>>
>> So, you've replaced logic that only worked on 'and' operations to use
>> ComputeMaskedBits instead. I'm not entirely convinced the new logic catches
>> everything the old logic did. ComputeMaskedBits needs to know exactly which
>> n-th bit is set, isKnownToBeAPowerOfTwo does not. That's why we have this
>> function at all.
>>
>> The previous code should fire on:
>>
>> define void @test(i32 %x, i32 %y) {
>>   %A = shl i32 1, %x
>>   %B = shl i32 1, %y
>>   %C = and i32 %A, %B
>>   %D = add i32 %C, %A
>>   ; check %D here (isZero=true)
>>   [...]
>>
>> and I don't think the new code will.
>
>
> Correct, I added the old logic back with a test so that it won't get
> removed by accident again.
>
> Thanks for taking a look!
>
>
>>
>>
>> Nick
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130726/5ddda8de/attachment.html>


More information about the llvm-commits mailing list