[PATCH] InstCombine: Be more agressive optimizing 'udiv' instructions with 'select' denominators
Duncan Sands
duncan.sands at gmail.com
Sun Jun 9 10:30:05 PDT 2013
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.
Ciao, Duncan.
More information about the llvm-commits
mailing list