https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128447

            Bug ID: 128447
           Summary: Another related values case for ifcvt.cc
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: law at gcc dot gnu.org
            Blocks: 26163
  Target Milestone: ---
            Target: riscv

int
f (int a, int b, int c)
{
  return c ? (a << 4) + b : (a + b) << 4;
}

Compiled with -O2 -march=rv64gcbv_zicond generates:

        addw    a5,a0,a1        # 35    [c=8 l=4]  addsi3_extended/0
        slliw   a0,a0,4 # 37    [c=8 l=4]  ashlsi3_extend
        addw    t1,a0,a1        # 38    [c=8 l=4]  addsi3_extended/0
        slliw   t0,a5,4 # 36    [c=8 l=4]  ashlsi3_extend
        czero.nez       t2,t0,a2        # 41    [c=4 l=4]  *czero.nez.didi
        czero.eqz       a1,t1,a2        # 40    [c=4 l=4]  *czero.eqz.didi
        add     a0,t2,a1        # 30    [c=4 l=4]  *adddi3/0


Which is a generalized conditional move.  But we can do better.

What's different across the arms is whether or not we select b or b << 4.  SO
we could instead generate something like this:


slliw     a5,a0,4
addi      a4,zero,4
czero.nez a4,a4,a2
sllw      a1,a1,a4
addw      a0,a5,a1

This shows up 10-12m times across x264 in related forms.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26163
[Bug 26163] [meta-bug] missed optimization in SPEC (2026, 2k17, 2k and 2k6 and
95)

Reply via email to