Hi!
The r12-4475 change added extra code to recog_for_combine to attempt to
force some constants into the constant pool.
Unfortunately, as this (UB at runtime) testcase shows, such changes are
harmful for computed_jump_p jumps. The computed_jump_p returns false
for loads from constant pool MEMs:
case MEM:
return ! (GET_CODE (XEXP (x, 0)) == SYMBOL_REF
&& CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)));
and so if we try to optimize a computed jump that way, it becomes
a non-computed jump which doesn't match any other jump category
(simplejump_p, tablejump_p, condjump_p, returnjump_p, eh_returnjump_p,
asm goto) and doesn't have any label recorded in JUMP_LABEL (because,
it doesn't really jump to any LABEL), so some passes like dwarf2cfi
can get confused about it and ICE.
The following patch just prevents that, by only doing the r12-4475
changes if it is not a jump.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2025-11-20 Jakub Jelinek <[email protected]>
PR target/120250
* combine.cc (recog_for_combine): Don't try to put SET_SRC
into a constant pool if SET_DEST is pc_rtx.
* gcc.c-torture/compile/pr120250.c: New test.
--- gcc/combine.cc.jj 2025-10-21 11:27:04.884882995 +0200
+++ gcc/combine.cc 2025-11-19 15:03:23.350157882 +0100
@@ -11759,7 +11759,8 @@ recog_for_combine (rtx *pnewpat, rtx_ins
rtx src = SET_SRC (pat);
if (CONSTANT_P (src)
&& !CONST_INT_P (src)
- && crtl->uses_const_pool)
+ && crtl->uses_const_pool
+ && SET_DEST (pat) != pc_rtx)
{
machine_mode mode = GET_MODE (src);
if (mode == VOIDmode)
--- gcc/testsuite/gcc.c-torture/compile/pr120250.c.jj 2025-11-19
15:28:12.937891927 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr120250.c 2025-11-19
15:27:53.225174446 +0100
@@ -0,0 +1,38 @@
+/* PR target/120250 */
+
+int a = 5, b = 7, c, *d;
+void *l;
+void foo (const char *s);
+void bar (void);
+void qux (const char *, int);
+
+int
+baz (int *d, int a, int b)
+{
+ int c = 0;
+ for (int i = 0; i < a; ++i)
+ for (int j = 0; j < b; ++j)
+ c += d[i * b + j];
+ return c;
+}
+
+int
+main ()
+{
+ d = __builtin_malloc (a * b * sizeof (int));
+ if (!d)
+ {
+ foo ("foo");
+ __builtin_exit (1);
+ }
+ for (int i = 0; i < a; ++i)
+ for (int j = 0; j < b; ++j)
+ d[i * b + j] = i * b + j;
+ l = (void *) &bar;
+ goto *l;
+bar:
+ c = baz (d, a, b);
+ qux ("bar", c);
+ __builtin_free (d);
+ return 0;
+}
Jakub