https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117868
Bug ID: 117868
Summary: [avr][lra] Wrong code with -mlra in simd-1.c
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gjl at gcc dot gnu.org
Target Milestone: ---
Created attachment 59759
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59759&action=edit
simd-1.c: Modified C test case
$ avr-gcc -mmcu=atmega128 -dumpbase "" -save-temps -dp -Os -o simd-1.elf -mlra
simd-1.c
With the attached simd-1.c test case (which is a simplified version of
gcc.c-torture/execute/simd-1.c) runs into abort. The final test in an AVRtest
dump reads:
000674: LDD Y+q (###)->1b (R28)->10af (10ca)->00 (R24)<-00
000676: LDD Y+q (###)->1c (R28)->10af (10cb)->00 (R25)<-00
000678: LDD Y+q (###)->1d (R28)->10af (10cc)->69 (R26)<-69
00067a: LDD Y+q (###)->1e (R28)->10af (10cd)->00 (R27)<-00
00067c: SBIW (###)->00 (R26)->0069 (R26)<-0069 (SREG)->'Z' (SREG)<-''
00067e: SBCI (###)->00 (R25)->00 (R25)<-00 (SREG)->'' (SREG)<-''
000680: SBCI (###)->96 (R24)->00 (R24)<-6a (SREG)->'' (SREG)<-'C'
000682: BREQ (SREG)->'C' Z->0
000684: RJMP
0003de: CALL (SPL)->10af (10af)<-f1 (10ae)<-01 (SPL)<-10ad
+++[1->2] main --> abort
0006da: *** SYSCALL #31: abort
which is the log for:
ldd r24,Y+27 ; 853 [c=16 l=4] *movsi/2
ldd r25,Y+28
ldd r26,Y+29
ldd r27,Y+30
sbiw r26,0 ; 854 [c=28 l=3] *cmpsi/2
sbci r25,hi8(150)
sbci r24,lo8(150)
breq .+2 ; 855 [c=4 l=2] branch
rjmp .L9
So insn 853 is reading from frame location Y+27. However, some instructions
above that, there is:
ldd r12,Y+37 ; 978 [c=16 l=4] *movsi/2
ldd r13,Y+38
ldd r14,Y+39
ldd r15,Y+40
ldd r8,Y+33 ; 979 [c=16 l=4] *movsi/2
ldd r9,Y+34
ldd r10,Y+35
ldd r11,Y+36
ldd r4,Y+29 ; 980 [c=16 l=4] *movsi/2
ldd r5,Y+30
ldd r6,Y+31
ldd r7,Y+32
ldd r24,Y+25 ; 981 [c=16 l=4] *movsi/2
ldd r25,Y+26
ldd r26,Y+27
ldd r27,Y+28
which is reading from locations Y+37, Y+33, Y+29, Y+25 (which are reading
32-bit values 214 (0xd6), 130 (0x82), 105 (0x69), 156 (0x9c)) that all seem
correct to me.
Notice that insn 853 reading SImode from Y+27 is using an awkward address that
has a strange overlap with insn 981 reading from Y+25. Reading from Y+27 looks
plain wrong.
Target: avr
Configured with: ../../source/gcc-master/configure --target=avr --disable-nls
--with-dwarf2 --with-gnu-as --with-gnu-ld --disable-shared
--with-long-double=64 --enable-languages=c,c++
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20241130 (experimental) (GCC)
git trunk fd1a2dc58f810ba756a10cefbc71547188859880