https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127302
Bug ID: 127302
Summary: 505.mcf_r miscompiled since 4fe2072d5d16 (allow
backward threading to loop exit)
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: anton at ozlabs dot org
Target Milestone: ---
I'm seeing an issue building 505.mcf_r for RISC-V with -O3 -mcpu=tt-ascalon-d8.
I haven't been able to reproduce it on x86-64. I've also struggled to create a
cut down test case.
I tested 07337728c028 and 4fe2072d5d16, and the output of mcf changes:
diff -u good.out bad.out
--- good.out 2026-09-09 21:43:00.383385755 +0000
+++ bad.out 2026-09-09 21:44:41.458143184 +0000
@@ -11,198 +11,313 @@
objective value : 15887540369
new implicit arcs : 24900000
active arcs : 25160767
-simplex iterations : 910670
-objective value : 12149258952
-erased arcs : 24879927
-new implicit arcs : 24879927
+simplex iterations : 1134020
+objective value : 13036968874
+erased arcs : 24877215
+new implicit arcs : 24877215
The bad commit:
commit 4fe2072d5d16ce26112d8035e627d47809aaa6c2 (HEAD)
Author: Richard Biener <[email protected]>
Date: Mon Aug 17 09:58:27 2026 +0200
tree-optimization/126887 - allow backward threading to loop exit
The following allows the backward thread through a loop header
to exit, allowing it to fully peel a not iterating loop on a
threading path. The backward thread copier cannot handle copying
loops, but this special case is OK and is also handled by the
forward threader. We have to take care to not randomly peel
loops though, not even after loop opts, so this patch adds
appropriate measures and a testcase.
PR tree-optimization/126887
* tree-ssa-threadbackward.cc (back_threader::find_paths_to_names):
Allow to search past a loop header in case we are threading a
loop exit test.
* tree-ssa-threadupdate.cc
(back_jt_path_registry::duplicate_thread_path): Properly
detect when a entered subloop is dissolved by threading,
but avoid creating new entries into the original loop.
(jt_path_registry::cancel_invalid_paths): Do not allow
peeling loops.
* gcc.dg/tree-ssa/ssa-thread-23.c: New testcase.
* gcc.dg/tree-ssa/ssa-thread-24.c: Likewise.