[PATCH] InstCombine: Be more agressive optimizing 'udiv' instructions with 'select' denominators

David Majnemer david.majnemer at gmail.com
Sun Jun 9 12:06:30 PDT 2013


On Sun, Jun 9, 2013 at 10:30 AM, Duncan Sands <duncan.sands at gmail.com>wrote:

> Hi David,
>
>
> On 09/06/13 12:22, David Majnemer wrote:
>
>> Real world code [*] sometimes has the denominator of a 'udiv' be a
>> 'select' but
>> the select operands may not have the same structural form.
>>
>> The attached patch treats the true and false operands as right hand sides
>> of a
>> divide and feeds them into the same logical than simplified 'udiv'
>> instructions.
>>
>> I wouldn't be surprised if there was a better/more systematic way of
>> dealing
>> with this problem, I'd be happy to implement suggestions.
>>
>> --
>> David Majnemer
>>
>> [*] AddressSanitizerModule::**runOnModule
>>
>
> might this turn this:
>
>   %x_is_zero = icmp eq i32 %x, 0
>   %divisor = select i1 %x_is_zero, i32 1, x
>   %y = udiv i32 %z, %divisor
>
> into:
>
>   %x_is_zero = icmp eq i32 %x, 0
>   %y1 = udiv i32 %z, %x
>   %y = select i1 %x_is_zero, i32 %z, %y1
>
> ?
>
> I.e. turning a safe division into one that map trap.


No, the optimization is only worth performing if I can prove that we don't
need to perform division at all.
This means that both arms of the select must be able to be simplified.


>
> Ciao, Duncan.
>


Thanks for looking at the patch!


> ______________________________**_________________
> 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/fb529b36/attachment.html>


More information about the llvm-commits mailing list