[llvm-commits] [PATCH] Simplify negated bit test
Jakub Staszak
kubastaszak at gmail.com
Mon Dec 10 14:36:54 PST 2012
Benjamin,
This optimization doesn't seem to change SHL right value, so I don't fully understand how it can invalidate the code.
"isPowerOfTwo" from VT seems to be much better idea though.
I am also a little bit surprised, that 1 << 32 is undef, but 2 << 31 is 0. LLVM docs say so, I just don't get why :)
- Kuba
On Dec 10, 2012, at 11:08 PM, Benjamin Kramer <benny.kra at gmail.com> wrote:
>
> On 10.12.2012, at 22:16, Jakub Staszak <kubastaszak at gmail.com> wrote:
>
>>
>> On Dec 10, 2012, at 9:58 PM, David Majnemer <david.majnemer at gmail.com> wrote:
>>
>>>
>>> 2. It doesn't have to be 1 which is shifted. It works with any power-of-two value (you can use m_Power2 pattern).
>>> I was under the impression that m_Power2 does not handle values generated from shl instructions.
>>>
>>> Further, it seems that LLVM already turns !!(~A & C) into !(A & C) where C is a constant and a power of 2. Should I add such a transform anyway?
>>>
>>
>> What I meant was you should m_Power2 the constant value itself. So it should work also with (2 << x), (4 << x), etc.
>
> The transformation is not valid if the shift operation can yield a zero result. In the original patch this wasn't possible because shifts greater or equal the bit width are undefined. 2 << 31 on i32 is defined and zero.
>
> Instead of the shift matching "isPowerOfTwo" from ValueTracking.h could be used to make the transformation more powerful. It handles the "1 << X" case and many others too.
>
> - Ben
More information about the llvm-commits
mailing list