https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129266
Bug ID: 129266
Summary: [17 Regression] ICE: SSA corruption (Unable to
coalesce ssa_names 6 and 11 which are marked as MUST
COALESCE) at -O1 with a computed goto in a loop since
r17-111-g27b2a84e580ac1
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: ice-on-valid-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: haoxintu at gmail dot com
Target Milestone: ---
Hi,
$cat repro.c
long f(unsigned c)
{
long b = 1;
unsigned d = 0;
void *e[] = { &&l0, &&l1 };
top:
if (d >= 4)
goto out;
d++;
goto *e[c]; /* c is 0 or 1 */
l1:
switch (d)
{
case 32:
case 1:
b = c;
/* fall through */
default:
b = b ^ d;
}
goto out;
l0:
c = 1;
goto top;
out:
return b;
}
int main(void)
{
if (f(0) != 3 || f(1) != 0)
__builtin_abort();
return 0;
}
$ gcc -O1 -c repro.c
Unable to coalesce ssa_names 6 and 11 which are marked as MUST COALESCE.
d_6(ab) and d_11(ab)
during RTL pass: expand
repro.c: In function 'f':
repro.c:1:6: internal compiler error: SSA corruption
1 | long f(unsigned c)
| ^
0x29bd8db internal_error(char const*, ...)
../../gcc/diagnostic-global-context.cc:787
0x1476f34 fail_abnormal_edge_coalesce
../../gcc/tree-ssa-coalesce.cc:1014
0x1476f34 coalesce_partitions
../../gcc/tree-ssa-coalesce.cc:1446
0x1476f34 coalesce_ssa_name(_var_map*)
../../gcc/tree-ssa-coalesce.cc:1900
0x13faae4 remove_ssa_form
../../gcc/tree-outof-ssa.cc:1181
0x13faae4 rewrite_out_of_ssa(ssaexpand*)
../../gcc/tree-outof-ssa.cc:1529
0xd205da execute
../../gcc/cfgexpand.cc:7074
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.
```
Only -O1 fails; -O0, -O2, -O3 and -Os compile it. The program is valid: it runs
correctly at -O0 (f(0) == 3, f(1) == 0), and ASan/UBSan are clean with both gcc
and clang.
The loop counter `d` lives across the abnormal edges of the computed goto, so
its SSA names are marked (ab). Something at -O1 makes two versions of `d`
(`d_6` and `d_11`) live at the same time, so out-of-SSA cannot coalesce them.
Any one of `-fno-tree-ch`, `-fno-tree-forwprop` or `-fno-tree-loop-optimize`
avoids the ICE.
Bisected to r17-111-g27b2a84e580ac1
(https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=27b2a84e580ac14677821daf736b9190f7aa5fc0):
match.pd: Relax single_use for fold-to-zero comparisons
Reproduced in Godbolt (gcc trunk, -O1 -c): https://godbolt.org/z/n3cYn3h7M
## Checked versions
- gcc trunk r17-7041-g531fc99cb65 (2026-12-02, local): ICE at -O1
- gcc 16.2, 15.2, 14.1, 13.2: compile it at -O1 and -O2
- clang 21: compiles it and runs correctly at -O0 to -Os
Thanks.