https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115650
Bug ID: 115650 Summary: [15 Regression] ARC backend bug exposed by late-combine pass Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: law at gcc dot gnu.org Target Milestone: --- This code generates code that can't be groked by as/ld with -O2: /* { dg-do run } */ int a, b[2]; int main () { lbl: for (; a; a--) if (b[10000]) goto lbl; return 0; } The problem is this instruction: ld.as r2,[gp,@b@sda+40000] ;23 # 12 [c=8 l=8] *movsi_insn/23 That will trigger errors like this from the linker: pr60115.c:(.text.startup+0x6): relocation truncated to fit: R_ARC_SDA16_LD2 against symbol `b' defined in .sbss section in /tmp/ccgCSiHr.o With the right magic options this can also be triggered without the late combine pass. The trick is to disable PRE and LICM so that these instructions end up in the same block and are then subject to combine: (insn 11 8 12 3 (set (reg/f:SI 157) (const:SI (plus:SI (symbol_ref:SI ("b") [flags 0x6] <var_decl 0x7f0b5ab20240 b>) (const_int 40960 [0xa000])))) "j.c":10:10 3 {*movsi_insn} (nil)) (insn 12 11 13 3 (set (reg:SI 158 [ b[10000] ]) (mem:SI (plus:SI (reg/f:SI 157) (const_int -960 [0xfffffffffffffc40])) [1 b[10000]+0 S4 A32])) "j.c":10:8 3 {*movsi_insn} (expr_list:REG_DEAD (reg/f:SI 157) (nil))) That will result in: (insn 12 11 13 3 (set (reg:SI 158 [ b[10000] ]) (mem:SI (const:SI (plus:SI (symbol_ref:SI ("b") [flags 0x6] <var_decl 0x7f0b5ab20240 b>) (const_int 40000 [0x9c40]))) [1 b[10000]+0 S4 A32])) "j.c":10:8 3 {*movsi_insn} (nil)) Which triggers the subsequent linker error. This is almost certainly a bug in the ARC backend. I'm not currently chasing it down.