[PATCH] InstCombine: Optimize (1 << X) UPred CstP2 to X UPred Log2(CstP2)

David Majnemer david.majnemer at gmail.com
Sun Jun 9 17:15:26 PDT 2013


On Sun, Jun 9, 2013 at 1:27 PM, David Majnemer <david.majnemer at gmail.com>wrote:

> On Sun, Jun 9, 2013 at 10:37 AM, Duncan Sands <duncan.sands at gmail.com>wrote:
>
>> Hi David,
>>
>>
>> On 09/06/13 14:10, David Majnemer wrote:
>>
>>> We may, after other optimizations, find ourselves with IR that looks
>>> like:
>>>
>>>    %shl = shl i32 1, %y
>>>    %cmp = icmp ult i32 %shl, 32
>>>
>>> However, we should transform it to:
>>>
>>>    %cmp = icmp ult i32 %y, 5
>>>
>>> The attached patch teaches visitICmpInstWithInstAndIntCst how to perform
>>> this
>>> transform.
>>>
>>
>> while the patch looks OK, I think it could be more general.  In your
>> example,
>> if the icmp ult was with, say, 30 then you still could have transformed
>> it.
>> In the case of an icmp eq comparison, if the RHS is not a power of two
>> then
>> it cannot be equal to the left hand side, so you could fold the
>> comparison to
>> false.
>>
>
> Thanks! I've attached an updated patch that implements additional
> transforms.
>

And yet more transforms, it turns out we turn some unsigned comparisons
into signed comparisons. Optimize these too.


>
>
>>
>> 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/20130609/83d5c6fe/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: shift-cmp.diff
Type: application/octet-stream
Size: 6864 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130609/83d5c6fe/attachment.obj>


More information about the llvm-commits mailing list