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

            Bug ID: 129225
           Summary: Improve address arithmetic for RISC-V
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: law at gcc dot gnu.org
  Target Milestone: ---

RISC-V has limited memory forms (until Zilx is ratified, and even when
ratified, it's not mandatory in rva23).  Essentially for scalar ops  we have
reg and reg+simm12.

Consider:

long f (long *a, long i)
{
  long *p = a + i;
  return p[804] + p[446];
}

        sh3add  a1,a1,a0        # 8     [c=4 l=4]  *shNadd
        li      a5,804          # 9     [c=4 l=4]  *movdi_64bit/1
        sh3add  t0,a5,a1        # 10    [c=4 l=4]  *shNadd
        addi    t1,a1,1521      # 11    [c=4 l=4]  *adddi3/1
        ld      a0,0(t0)                # 13    [c=28 l=4]  *movdi_64bit/2
        ld      t2,2047(t1)             # 14    [c=28 l=4]  *movdi_64bit/2
        add     a0,a0,t2        # 20    [c=4 l=4]  *adddi3/0

But we can do better.  With careful selection of a constant, we can do a single
"li+shadd" to get an address that offsettable by a simm12 in the memory
reference.  That'll drop an sh3add and addi out of the dynamic stream.  Rough
estimates would be about 50M instructions saved in x264, perhaps more and it'd
be fairly generic, so it'd likely help elsewhere too.

Gimple isn't a great match because we don't know the span we can cover.  RTL is
painful because synthesize_add has scrambled the address computation in ways
that make it harder to recover.

Anyway, not working on it, just wanted to get it recorded so its not lost.

Reply via email to