[llvm] r182200 - isKnownToBeAPowerOfTwo: (X & Y) + Y is a power of 2 or zero if y is also.

David Majnemer david.majnemer at gmail.com
Sat May 18 18:56:22 PDT 2013


On Sat, May 18, 2013 at 3:03 PM, David Majnemer <david.majnemer at gmail.com>wrote:

> On Sat, May 18, 2013 at 1:13 PM, Duncan Sands <duncan.sands at gmail.com>wrote:
>
>> Hi David,
>>
>>
>> On 18/05/13 21:30, David Majnemer wrote:
>>
>>> Author: majnemer
>>> Date: Sat May 18 14:30:37 2013
>>> New Revision: 182200
>>>
>>> URL: http://llvm.org/viewvc/llvm-**project?rev=182200&view=rev<http://llvm.org/viewvc/llvm-project?rev=182200&view=rev>
>>> Log:
>>> isKnownToBeAPowerOfTwo: (X & Y) + Y is a power of 2 or zero if y is also.
>>>
>>
>> if the + is nsw or nuw then the sum can't be zero.  I don't know if this
>> is
>> useful in practice.
>>
>
> I noticed this too, I'm trying to find if I can tickle something that
> would make this happen.
>

So, I've found a way to make this possible: set the NSW bit on the 'add'
created in foldSelectICmpAnd.
Then the following:
  %1 = lshr i32 %x, 8
  %2 = and i32 %1, 32
  %3 = add i32 %2, 32
  %4 = xor i32 %x, -1
  %5 = and i32 %3, %4
  %6 = icmp ne i32 %5, 0

will get optimized:
  %and = lshr i32 %x, 8
  %0 = and i32 %and, 32
  %1 = add nsw i32 %0, 32
  %2 = and i32 %1, %x
  %tobool2 = icmp eq i32 %2, 0

My only concern is that I'm not entirely convinced that it's always safe
(just mostly safe) to set the NSW bit.
Ben or Duncan (or preferably both!), does it look safe to set the NSW bit
there?

Thanks
-- 
David Majnemer


>
>>
>> Ciao, Duncan.
>>
>> ______________________________**_________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/**mailman/listinfo/llvm-commits<http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130518/83b2eb9a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nsw-nuw-p2.diff
Type: application/octet-stream
Size: 2252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130518/83b2eb9a/attachment.obj>


More information about the llvm-commits mailing list