https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129307
Bug ID: 129307
Summary: [17 Regression] ICE at -O2 in expand_mult, at
expmed.cc:3887: 256-bit multiply from the
long-multiply recogniser reaches expand after PRE,
since r17-3443
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
typedef unsigned __int128 u128;
__int128 a = 3, c;
long b = 10;
void f (void)
{
for (unsigned i = 0; i < 6; i++)
{
/* High 128 bits of x * y, written out with 64x64->128 multiplies. */
u128 x = b / (u128) a;
u128 y = __builtin_clzg (i, 8);
u128 lolo = (u128) (unsigned long) x * (unsigned long) y;
u128 lohi = (unsigned long) x * (y >> 64);
u128 hilo = (x >> 64) * (unsigned long) y;
u128 hihi = (x >> 64) * (y >> 64);
u128 mid = (lolo >> 64) + (unsigned long) lohi + (unsigned long) hilo;
c = hihi + (lohi >> 64) + (hilo >> 64) + (mid >> 64);
if (a)
c = 0;
}
}
int main (void)
{
f ();
return c != 0;
}
$ gcc -O2 -c repro.c
during RTL pass: expand
repro.c: In function 'f':
repro.c:18:46: internal compiler error: in expand_mult, at expmed.cc:3887
18 | c = hihi + (lohi >> 64) + (hilo >> 64) + (mid >> 64);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
0x2c63bef internal_error(char const*, ...)
../../gcc/diagnostic-global-context.cc:787
0xbb5cfd fancy_abort(char const*, int, char const*)
../../gcc/diagnostics/context.cc:1813
0x9084b1 expand_mult(machine_mode, rtx_def*, rtx_def*, rtx_def*, int, bool)
../../gcc/expmed.cc:3887
0xf028f3 expand_expr_real_gassign(gassign*, rtx_def*, machine_mode,
expand_modifier, rtx_def**, bool)
../../gcc/expr.cc:11482
...
Only -O2 ICEs; -O0, -O1, -O3 and -Os compile it. -fno-tree-pre makes it go
away.
## Bisect results
Started with r17-3443:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=aac02c9666184d19334a0527ec444b5e55fbd113
("widening_mul: Lower long-multiply chains to inline longhand").
## Checked versions (x86_64)
- gcc trunk 17.0.0 20261203 (0b526284fa1): ICE at -O2
- r17-3443 (aac02c96661): ICE; its parent: OK
- basepoints/gcc-17: OK
- gcc 16.2, 15.3, 14.4: OK
Godbolt (gcc trunk -O2): https://godbolt.org/z/TrPP5KoE3
Thanks.