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

            Bug ID: 128907
           Summary: RISC-V: +11% instructions on 523.xalancbmk_r vs GCC
                    15.1
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anton at ozlabs dot org
                CC: pfustc at gcc dot gnu.org, rdapp at gcc dot gnu.org
  Target Milestone: ---
            Target: riscv

I'm chasing a regression with xalancbmk where GCC trunk executes about 11% more
instructions than GCC 15.1 on Ascalon with -O3 -mcpu=tt-ascalon-d8 (ie
zvl256b). I worked with Claude to narrow it down to
XalanDOMStringCache::release. Here is a reduced test case:

  #include <algorithm>
  #include <vector>
  bool release(std::vector<long*>& busy, long* p)
  {
    std::vector<long*>::iterator i = std::find(busy.begin(), busy.end(), p);
    if (i == busy.end()) return false;
    busy.erase(i);
    return true;
  }

And a test case:

#include <cstdio>
#include <cstdlib>
#include <vector>
bool release(std::vector<long*>& busy, long* p);
int main(int argc, char** argv)
{
  int n = argc > 1 ? atoi(argv[1]) : 1000, reps = argc > 2 ? atoi(argv[2]) :
100000;
  std::vector<long*> busy(n); long* pool = new long[n];
  for (int i = 0; i < n; i++) busy[i] = pool + i;
  long hits = 0;
  for (int r = 0; r < reps; r++) { long* p = pool + (n - 1 - (r & 7)); hits +=
release(busy, p); busy.push_back(p); }
  printf("%ld\n", hits); return 0;
}

when built with -O3 -mcpu=tt-ascalon-d8, trunk is about 36% more instructions.
The issue bisects to eee51f9a4b6, "vect: Extend peeling and versioning for
alignment to VLA modes". It looks like we previously had a VLS loop that got
unrolled 4x (and takes 6.5 instructions):

        vsetivli        zero,4,e64,m1,ta,ma
...

.L76:
        vle64.v v1,0(a4)
        addi    a7,a4,32
        addi    a2,a2,4
        addi    a4,a4,64
        vmseq.vx        v1,v1,a1
        vcpop.m a3,v1
        bne     a3,zero,.L62
        vle64.v v1,0(a7)
        vadd.vv v2,v2,v3
        vmseq.vx        v1,v1,a1
        vcpop.m a3,v1
        bne     a3,zero,.L62
        vle64.v v1,0(a4)
        addi    a4,a7,64
        vadd.vv v2,v2,v3
        vmseq.vx        v1,v1,a1
        vcpop.m a3,v1
        bne     a3,zero,.L62
        vle64.v v1,0(a4)
        addi    a4,a7,96
        vadd.vv v2,v2,v3
        vmseq.vx        v1,v1,a1
        vcpop.m a3,v1
        bne     a3,zero,.L62
        vadd.vv v2,v2,v3
        bne     a2,t1,.L76

And now we have a VLA loop that is not unrolled (that takes 9 instructions):

.L10:
        vsetvli t5,t4,e64,m1,ta,ma
        vle64.v v1,0(t0)
        sub     t4,t4,t5
        sh3add  t0,t5,t0
        vmseq.vv        v0,v1,v2
        vcpop.m a3,v0
        bne     a3,zero,.L80
        add     a7,a7,t5
        bne     t4,zero,.L10

Reply via email to