[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
Nick Lewycky
nicholas at mxc.ca
Sat Jul 13 12:03:08 PDT 2013
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.
- 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.
Nick
More information about the llvm-commits
mailing list