[PATCH] Prefer small negative constants in InstCombine

Michael Gottesman mgottesman at apple.com
Wed Jun 26 11:36:43 PDT 2013


If this is disruptive to other architectures/optimizations in the middle end, perhaps you can use a dagcombine to do this. You would check for movabsq, see if it is being piped into an add, and if that is true fix it up.

Just my 17179869180 cents.

Michael

On Jun 26, 2013, at 11:24 AM, Eli Friedman <eli.friedman at gmail.com> wrote:

> On Wed, Jun 26, 2013 at 6:56 AM, Tim Northover <tnorthover at apple.com> wrote:
> Hi,
> 
> The attached patch adds a heuristic to ShrinkDemandedConstant so that small negative constants are preferred over large ones even if as an unsigned value the transformation would be an improvement.
> 
> The motivating case is added as a test:
> define i32 @foo(i64 %in) {
>   %sub = sub i64 %in, 4
>   %shift = lshr i64 %sub, 2
>   %res = trunc i64 %shift to i32
> 
>   ret i32 %res
> }
> 
> On x86-64 this currently generates:
> 
> _foo:
>         movabsq $17179869180, %rax      ## imm = 0x3FFFFFFFC
>         addq    %rdi, %rax
>         shrq    $2, %rax
>         ret
> 
> with an unnecessary and large movabsq. With this change the fact that we’re really subtracting 4 survives to CodeGen and we just emit
> 
> _foo:
>         leaq -4(%rdi), %rax
>         shrq $2, %rax
>         ret
> 
> Does anyone have any objections to this change? Is it likely to cause more damage than good for later passes?
> 
> 
> This seems like a big change that could affect all sorts of optimizations; I'd like to see performance numbers from the nightly test suite.
> 
> Also, I'm not sure this code is actually performing the check you want it to; it appears that, for example, it would prefer -3 over -4.
> 
> -Eli 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> 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/20130626/003f14e2/attachment.html>


More information about the llvm-commits mailing list