[PATCH] Prefer small negative constants in InstCombine
Eli Friedman
eli.friedman at gmail.com
Wed Jun 26 11:24:10 PDT 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130626/df198f9f/attachment.html>
More information about the llvm-commits
mailing list