[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
Sat Jul 13 15:21:12 PDT 2013


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/20130713/02162b0a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: uremp2v2.diff
Type: application/octet-stream
Size: 4101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130713/02162b0a/attachment.obj>


More information about the llvm-commits mailing list