https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116649
--- Comment #6 from Segher Boessenkool <segher at gcc dot gnu.org> ---
(In reply to Jeevitha from comment #4)
> (In reply to Segher Boessenkool from comment #3)
> > There are way more places we could usefully generate set[n]bc[r] insns. For
> > example, consider
> >
> > int f(int a, int b, int x) { return a < b ? x+5 : x+6; }
> >
> > We currently generate a branchy thing for that, I actually expected an isel
> > thing, but we could likely do better with setbc even.
> >
> > So if you find anything more, please let us know!
>
> Currently, this code emits the following sequence:
>
> f:
> cmpw 0,3,4
> bge 0,.L2
> addi 3,5,5
> extsw 3,3
> blr
> .L2:
> addi 3,5,6
> extsw 3,3
> blr
> A better sequence using isel could be:
>
> cmpw %r3,%r4
> li %r3,6
> li %r4,5
> isel %r3,%r4,%r3,0
> add %r3,%r3,%r5
> extsw %r3,%r3
> blr
>
> No idea with set[n]bc[r] insns.
> Do we have a PR for this missed optimisation?
Or even
cmpw 3,4 ; addi 3,5,5 ; addi 4,5,6
isel 3,3,4,0
(and the extsw is superfluous always anyway, known problem, there are PRs for
that, it would be lovely to fix that (although it doesn't matter much for
performance in the end, this is not on hot paths).
The setbc thing would be like
cmpw 3,4 ; setbc 3,0 ; addi 3,3,5
(which has a slightly longer latency in cases (not here), but is fewer insns
anyway).