https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129291
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c |tree-optimization
Keywords| |wrong-code
Last reconfirmed| |2026-12-04
Summary|[8/9/10/11/12/13/14/15/16/1 |[14/15/16/17 Regression]
|7 Regression] wrong code |wrong code with -O3
|with -O3 |-floop-nest-optimize:
|-floop-nest-optimize: |original schedule drops an
|original schedule drops an |intermediate loop after
|intermediate loop after |loop distribution
|loop distribution |
Status|UNCONFIRMED |NEW
Target Milestone|--- |14.5
Ever confirmed|0 |1
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed on trunk (xgcc 17.0.0 20261204, git 804c0a04557) with the comment 0
testcase:
-O3 -floop-nest-optimize repro.c => B[4] = 14 (expected 12), exit 1
The reporter's analysis checks out. The SCoP covers loops 1,4,5,2,3, but the
[sese-to-poly] original schedule has dimensions only for L_1, L_3, L_4 and L_5;
loop_2 (the source i1 loop) is missing from the schedule of S_5 (the B[]
store):
L_1[{S_19[..]->[(i1)]; S_16[..]->[(i1)]; S_5[i1,i2,i3]->[(i1)]}]
sequence: {S_16,S_19} -> L_4 -> L_5 ; S_5 -> L_3
This comes from embed_in_surrounding_loops() (graphite-sese-to-poly.cc): after
build_schedule_loop_nest() has built the loop_4/loop_5 nest, the remaining S_5
pbb is picked up by the loop at line 1139 via build_schedule_loop(), which only
inserts S_5's own loop (L_3); the call at line 1152 then embeds it in loop_1,
so loop_2 is never added. A gdb trace confirms
build_schedule_loop_nest(loop_4), build_schedule_loop_nest(loop_5), then, from
embed_in_surrounding_loops(loop=loop_4), build_schedule_loop(S_5) with index==2
and the line-1152 embed in loop_1 with index==3.
Additional data points:
- Loop distribution is the trigger, not -O3 itself: -O2 -floop-nest-optimize is
correct, but -O1/-O2 -ftree-loop-distribution -floop-nest-optimize reproduce;
-O3 -floop-nest-optimize -fno-tree-loop-distribution is correct.
- -fno-graphite does not disable the transform: gate_graphite_transforms()
(graphite.cc:551-556) sets flag_graphite=1 whenever -floop-nest-optimize is
given.
- -fno-tree-ch avoids the bug only because SCoP detection then fails ('cannot
represent loop_1', number of SCoPs: 0).
- -fchecking=2 does not diagnose anything.
Possibly related to PR 129278.