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

            Bug ID: 116585
           Summary: SSA corruption with -O3,-fvect-cost-model=very-cheap
                    cures the failure
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qinzhao at gcc dot gnu.org
  Target Milestone: ---

This is bug we found with GCC8 for our very large application. and it can be
repeated till the trunk GCC. (I can reproduce it with GCC15 on both x86 and
aarch64).

the reduced testing case is:
char *s1, *s2;
extern int* my_alloc (int);
extern int _setjmp ();
extern void bar();
void foo(int s1len, int s2len) {
  int e;
  e = _setjmp ();
  {
    int l, i;
    int *md = my_alloc(((sizeof(int)) * (s1len + 1) * (s2len )));
    s1len++;
    {
      for (; s1len; l) {
        for (; s2len; l) {
          for (; s1len; i) {
            int j;
            {
              j = 1;
              for (; j < s2len; j++) {
                int cost;
                if (s1[1] == s2[1])
                  cost = 0;
                else
                  cost = 1;
                md[j * s1len ] = ((cost));
              }
            }
          }
        }
      }
    }
    bar();
  }
}
/home/opc/Install/latest-d/bin/gcc -O3 t.c

Unable to coalesce ssa_names 16 and 30 which are marked as MUST COALESCE.
s1len_16(ab) and  s1len_30(ab)
during RTL pass: expand
t.c: In function ‘foo’:
t.c:5:6: internal compiler error: SSA corruption
    5 | void foo(int s1len, int s2len) {
      |      ^~~
0x342551c internal_error(char const*, ...)
        ../../latest-gcc/gcc/diagnostic-global-context.cc:491
0x18f966c fail_abnormal_edge_coalesce
        ../../latest-gcc/gcc/tree-ssa-coalesce.cc:1012
0x18fb01f coalesce_partitions
        ../../latest-gcc/gcc/tree-ssa-coalesce.cc:1444
0x18fd11d coalesce_ssa_name(_var_map*)
        ../../latest-gcc/gcc/tree-ssa-coalesce.cc:1898
0x1866853 remove_ssa_form
        ../../latest-gcc/gcc/tree-outof-ssa.cc:1065
0x186750b rewrite_out_of_ssa(ssaexpand*)
        ../../latest-gcc/gcc/tree-outof-ssa.cc:1353
0x100c5e5 execute
        ../../latest-gcc/gcc/cfgexpand.cc:6678
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

Adding -fvect-cost-model=very-cheap cures the failure on both x86 and aarch64.
/home/opc/Install/latest-d/bin/gcc -O3 -fvect-cost-model=very-cheap t.c
/home/opc/Install/latest/bin/ld: /lib/../lib64/crt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
/home/opc/Install/latest/bin/ld: /tmp/cceYCJoo.o: in function `foo':
t.c:(.text+0x2c): undefined reference to `my_alloc'
/home/opc/Install/latest/bin/ld: t.c:(.text+0x37): undefined reference to `bar'
collect2: error: ld returned 1 exit status

Reply via email to