[llvm-commits] [PATCH] Simplify negated bit test

Benjamin Kramer benny.kra at gmail.com
Mon Dec 10 14:08:37 PST 2012


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