Bug 118717 - [12 Regression] GCC 15 produces ICE with ruby-3.4.1 when lto is used: ractor.c:592:1: internal compiler error: SSA corruption
Summary: [12 Regression] GCC 15 produces ICE with ruby-3.4.1 when lto is used: ractor....
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 15.0
: P2 normal
Target Milestone: 12.5
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2025-01-31 17:41 UTC by Ted Rodgers
Modified: 2025-06-10 00:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 10.5.0, 12.4.1, 13.3.1, 14.2.1, 15.0
Known to fail: 11.1.0, 11.4.0, 12.1.0, 12.4.0, 13.3.0, 14.2.0
Last reconfirmed: 2025-01-31 00:00:00


Attachments
ractor.i file (268.55 KB, application/x-gzip)
2025-01-31 17:43 UTC, Ted Rodgers
Details
thread.i file (326.52 KB, application/x-gzip)
2025-01-31 17:43 UTC, Ted Rodgers
Details
-O2 testcase (no lto required) (774 bytes, text/plain)
2025-01-31 23:27 UTC, Drea Pinski
Details
Further reduced and slightly cleaned up (309 bytes, text/plain)
2025-01-31 23:49 UTC, Drea Pinski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ted Rodgers 2025-01-31 17:41:45 UTC
Linking two pre-compiled objects from  ruby-3.4.1 with lot enabled produces: SSA corruption.   Compiler error does not occur if the two objects were built without enabling lto.


x86_64-pc-linux-gnu-gcc -shared -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-soname,libruby34.so.3.4  -fstack-protector-strong -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs ractor.o thread.o -o libruby34.so.3.4.1

Unable to coalesce ssa_names 33 and 35 which are marked as MUST COALESCE.
_ec_33(ab) and  _ec_35(ab)
during RTL pass: expand
../../var/tmp/portage/dev-lang/ruby-3.4.1-r1/work/ruby-3.4.1/ractor.c: In function ‘ractor_check_ints.constprop’:
../../var/tmp/portage/dev-lang/ruby-3.4.1-r1/work/ruby-3.4.1/ractor.c:592:1: internal compiler error: SSA corruption
  592 | ractor_check_ints(rb_execution_context_t *ec, rb_ractor_t *cr, ractor_sleep_cleanup_function cf_func, void *cf_data)
      | ^
0x5598c7ae8234 internal_error(char const*, ...)
	/usr/src/debug/sys-devel/gcc-15.0.1_pre20250126/gcc-15-20250126/gcc/diagnostic-global-context.cc:517
0x5598c61b8565 fail_abnormal_edge_coalesce
	/usr/src/debug/sys-devel/gcc-15.0.1_pre20250126/gcc-15-20250126/gcc/tree-ssa-coalesce.cc:1012
0x5598c61b8565 coalesce_partitions
	/usr/src/debug/sys-devel/gcc-15.0.1_pre20250126/gcc-15-20250126/gcc/tree-ssa-coalesce.cc:1444
0x5598c61b94ad coalesce_ssa_name(_var_map*)
	/usr/src/debug/sys-devel/gcc-15.0.1_pre20250126/gcc-15-20250126/gcc/tree-ssa-coalesce.cc:1898
0x5598c6105d61 remove_ssa_form
	/usr/src/debug/sys-devel/gcc-15.0.1_pre20250126/gcc-15-20250126/gcc/tree-outof-ssa.cc:1069
0x5598c6105d61 rewrite_out_of_ssa(ssaexpand*)
	/usr/src/debug/sys-devel/gcc-15.0.1_pre20250126/gcc-15-20250126/gcc/tree-outof-ssa.cc:1357
0x5598c5871ed3 execute
	/usr/src/debug/sys-devel/gcc-15.0.1_pre20250126/gcc-15-20250126/gcc/cfgexpand.cc:6955
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.
make: *** [/tmp/ccolZslg.mk:2: /tmp/ccGLHZqh.ltrans0.ltrans.o] Error 1
lto-wrapper: fatal error: make returned 2 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/15/../../../../x86_64-pc-linux-gnu/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status



''''
Fails (lto enabled):

x86_64-pc-linux-gnu-gcc -march=native -O3 -flto -mprefer-vector-width=512 -fno-vect-cost-model -pipe -fno-omit-frame-pointer -fno-strict-aliasing -fPIC  -fno-strict-overflow -fvisibility=hidden -fexcess-precision=standard    -o thread.o -c thread.i

x86_64-pc-linux-gnu-gcc -march=native -O3 -flto -mprefer-vector-width=512 -fno-vect-cost-model -pipe -fno-omit-frame-pointer -fno-strict-aliasing -fPIC  -fno-strict-overflow -fvisibility=hidden -fexcess-precision=standard -o ractor.o -c ractor.i



x86_64-pc-linux-gnu-gcc -shared -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-soname,libruby34.so.3.4  -fstack-protector-strong -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs ractor.o thread.o -o libruby34.so.3.4.1



''''
Works (no lto): 

x86_64-pc-linux-gnu-gcc -march=native -O3 -mprefer-vector-width=512 -fno-vect-cost-model -pipe -fno-omit-frame-pointer -fno-strict-aliasing -fPIC  -fno-strict-overflow -fvisibility=hidden -fexcess-precision=standard    -o thread.o -c thread.i

x86_64-pc-linux-gnu-gcc -march=native -O3 -mprefer-vector-width=512 -fno-vect-cost-model -pipe -fno-omit-frame-pointer -fno-strict-aliasing -fPIC  -fno-strict-overflow -fvisibility=hidden -fexcess-precision=standard -o ractor.o -c ractor.i


x86_64-pc-linux-gnu-gcc -shared -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs -Wl,-soname,libruby34.so.3.4  -fstack-protector-strong -Wl,-O1 -Wl,--as-needed -Wl,-z,pack-relative-relocs ractor.o thread.o -o libruby34.so.3.4.1
Comment 1 Ted Rodgers 2025-01-31 17:43:07 UTC
Created attachment 60340 [details]
ractor.i file
Comment 2 Ted Rodgers 2025-01-31 17:43:44 UTC
Created attachment 60341 [details]
thread.i file
Comment 3 Ted Rodgers 2025-01-31 17:57:00 UTC
-march=native expands to:

-march=sapphirerapids -mabm -mno-sgx -mrtm -mshstk --param=l1-cache-line-size=64 --param=l1-cache-size=48 --param=l2-cache-size=76800
Comment 4 Drea Pinski 2025-01-31 18:17:38 UTC
Reducing ...
Comment 5 Sam James 2025-01-31 18:36:07 UTC
fwiw this showed up when I started to force using `setjmp` instead of `__builtin_setjmp` in ruby a few days ago. I haven't looked at how (if at all) we treat those differently because on mobile
Comment 6 Drea Pinski 2025-01-31 18:38:54 UTC
(In reply to Sam James from comment #5)
> fwiw this showed up when I started to force using `setjmp` instead of
> `__builtin_setjmp` in ruby a few days ago. I haven't looked at how (if at
> all) we treat those differently because on mobile

Well __builtin_setjmp should be treated as return twice but maybe it is not exactly. Anyways __builtin_setjmp should really not be used as it is not equal to setjmp which is why I assume you were forcing to use setjmp instead.
Comment 7 Drea Pinski 2025-01-31 22:40:24 UTC
I Have ractor.i down to ~56 lines. I am reducing thread.i right now. and then will try to get a decent testcase together.
Comment 8 Drea Pinski 2025-01-31 23:27:44 UTC
Created attachment 60345 [details]
-O2 testcase (no lto required)
Comment 9 Drea Pinski 2025-01-31 23:49:20 UTC
Created attachment 60346 [details]
Further reduced and slightly cleaned up
Comment 10 Drea Pinski 2025-01-31 23:49:34 UTC
Confirmed.
Comment 11 Drea Pinski 2025-01-31 23:57:40 UTC
With my new reduced testcase it goes further back and fails in GCC 11.1.0 also.
Comment 12 Richard Biener 2025-02-03 08:25:36 UTC
Broken by cselim:

-  <bb 9> [local count: 713752698]:
-  if (_23 != 0)
-    goto <bb 10>; [50.00%]
-  else
-    goto <bb 11>; [50.00%]
-
-  <bb 10> [local count: 356876349]:
-  _ec_4(ab)->tag = 0;
-  goto <bb 12>; [100.00%]
-
-  <bb 11> [local count: 356876349]:
-  _ec_4(ab)->tag = 0;
-
-  <bb 12> [local count: 1072883005]:
-  # _ec_6(ab) = PHI <_ec_4(ab)(11), _ec_4(ab)(10)>
+  <bb 9> [local count: 1072883005]:
+  # _ec_6(ab) = PHI <_ec_4(ab)(8)>
+  # cstore_22 = PHI <0(8)>
+  _ec_4(ab)->tag = cstore_22;
Comment 13 GCC Commits 2025-02-03 10:23:49 UTC
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:fbcbbfe2bf83eb8b1347144eeca37b06be5a8bb5

commit r15-7331-gfbcbbfe2bf83eb8b1347144eeca37b06be5a8bb5
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Feb 3 09:55:50 2025 +0100

    tree-optimization/118717 - store commoning vs. abnormals
    
    When we sink common stores in cselim or the sink pass we have to
    make sure to not introduce overlapping lifetimes for abnormals
    used in the ref.  The easiest is to avoid sinking stmts which
    reference abnormals at all which is what the following does.
    
            PR tree-optimization/118717
            * tree-ssa-phiopt.cc (cond_if_else_store_replacement_1):
            Do not common stores referencing abnormal SSA names.
            * tree-ssa-sink.cc (sink_common_stores_to_bb): Likewise.
    
            * gcc.dg/torture/pr118717.c: New testcase.
Comment 14 GCC Commits 2025-02-24 11:50:17 UTC
The releases/gcc-14 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:93e7442f0845e4ee5222a2370eb1a83d513939aa

commit r14-11339-g93e7442f0845e4ee5222a2370eb1a83d513939aa
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Feb 3 09:55:50 2025 +0100

    tree-optimization/118717 - store commoning vs. abnormals
    
    When we sink common stores in cselim or the sink pass we have to
    make sure to not introduce overlapping lifetimes for abnormals
    used in the ref.  The easiest is to avoid sinking stmts which
    reference abnormals at all which is what the following does.
    
            PR tree-optimization/118717
            * tree-ssa-phiopt.cc (cond_if_else_store_replacement_1):
            Do not common stores referencing abnormal SSA names.
            * tree-ssa-sink.cc (sink_common_stores_to_bb): Likewise.
    
            * gcc.dg/torture/pr118717.c: New testcase.
    
    (cherry picked from commit fbcbbfe2bf83eb8b1347144eeca37b06be5a8bb5)
Comment 15 GCC Commits 2025-02-25 08:45:43 UTC
The releases/gcc-13 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:08852469a263da1a05f020041c647e42c5cff09a

commit r13-9394-g08852469a263da1a05f020041c647e42c5cff09a
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Feb 3 09:55:50 2025 +0100

    tree-optimization/118717 - store commoning vs. abnormals
    
    When we sink common stores in cselim or the sink pass we have to
    make sure to not introduce overlapping lifetimes for abnormals
    used in the ref.  The easiest is to avoid sinking stmts which
    reference abnormals at all which is what the following does.
    
            PR tree-optimization/118717
            * tree-ssa-phiopt.cc (cond_if_else_store_replacement_1):
            Do not common stores referencing abnormal SSA names.
            * tree-ssa-sink.cc (sink_common_stores_to_bb): Likewise.
    
            * gcc.dg/torture/pr118717.c: New testcase.
    
    (cherry picked from commit fbcbbfe2bf83eb8b1347144eeca37b06be5a8bb5)
Comment 16 GCC Commits 2025-04-04 11:55:46 UTC
The releases/gcc-12 branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:8eca273335750e100efff8f45aee285290be3c46

commit r12-11017-g8eca273335750e100efff8f45aee285290be3c46
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Feb 3 09:55:50 2025 +0100

    tree-optimization/118717 - store commoning vs. abnormals
    
    When we sink common stores in cselim or the sink pass we have to
    make sure to not introduce overlapping lifetimes for abnormals
    used in the ref.  The easiest is to avoid sinking stmts which
    reference abnormals at all which is what the following does.
    
            PR tree-optimization/118717
            * tree-ssa-phiopt.cc (cond_if_else_store_replacement_1):
            Do not common stores referencing abnormal SSA names.
            * tree-ssa-sink.cc (sink_common_stores_to_bb): Likewise.
    
            * gcc.dg/torture/pr118717.c: New testcase.
    
    (cherry picked from commit fbcbbfe2bf83eb8b1347144eeca37b06be5a8bb5)
Comment 17 Richard Biener 2025-04-04 12:02:17 UTC
Fixed.