On 09/28/2016 02:48 AM, Kyrill Tkachov wrote:
Hi all,

This patch tries to avoid materialising an immediate
when comparison has shown that it is already loaded.
This is performed during ifcvt and only when the target has the
conditional negate
or inverse optabs, which for now is only aarch64.

Thus for the code:
int
foo (int a, int b)
{
  return a == 5 ? -5 : b;
}

we currently emit on aarch64:
foo:
        mov     w2, -5
        cmp     w0, 5
        csel    w0, w1, w2, ne
        ret

but with this patch we emit:
foo:
        cmp     w0, 5
        csneg   w0, w1, w0, ne
        ret

Bootstrapped and tested on arm, aarch64, x86_64.

Ok for trunk?

Thanks,
Kyrill

P.S. The simpler form of the transformation: X == CST ? CST : Y --> X ==
CST ? X : Y
could also be beneficial IMO but I found that it can cause bad codegen
in combine
due to extending the live range of X. I'm still working on a way to work
around that,
but that is a separate piece of work anyway.
FWIW, the simpler form of the transformation is already done just prior to leaving SSA form in tree-ssa-uncprop.c. So there may not be a ton of opportunities for the simpler form in the RTL optimizers.

My only concern here is this transformation isn't significantly different than the simpler form, which is apparently causing some kind of combine problem.

I'd like to understand the combine problem better before giving final approval to this patch.


Jeff

Reply via email to