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

            Bug ID: 128698
           Summary: wrong code at -O1/-Og when a function has exactly 500
                    large/huge _BitInt SSA names
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shimizu2486 at gmail dot com
  Target Milestone: ---

Live reproducer: https://godbolt.org/z/bGEoejWxq

$ cat t1.c
#include <stdio.h>
typedef _BitInt(200) T;
__attribute__((noipa)) T g(T x) { return x + 1; }
__attribute__((noipa)) void use(T x) {}
#define A use(g(a));
#define B A A A A A A A A
#define C B B B B B B B B
__attribute__((noipa)) T f(T a, T b) {
  T s = g(a);
  T t = g(b);
  C C C C C C C B B B B B B /* 496 calls */
  return s * t;
}
int main(void) {
  T r = f(2, 4);
  printf("%llu\n", (unsigned long long)r);
}

f(2, 4) returns g(2) * g(4) = 3 * 5 = 15, so the program should print 15.

$ gcc -O0 t1.c -o t1 && ./t1
15                   (correct)
$ gcc -O1 t1.c -o t1 && ./t1
250000               (wrong)

  x86-64 trunk (842e09f03b64)   wrong
  x86-64 16.2.0                 wrong
  x86-64 15.3.0                 wrong
  x86-64 14.4.0                 wrong

-O1 and -Og are wrong; -O0, -O2, -O3 and -Os are correct, and so is -O1 with
-fno-tree-coalesce-vars.  With 495 or 497 calls instead of 496 the program is
correct.  In -fdump-tree-bitintlower1-details, f has 500 SSA names under
"Mapping SSA_NAMEs to decls" (the 496 call results, s, t, a and b), and at -O1
all 500 are mapped to a.  arm-linux-gnueabihf -O1 is wrong the same way.

Reply via email to