Bug 117910

Summary: [avr][lra] Wrong code with -mlra in cmpdi-1.c
Product: gcc Reporter: Georg-Johann Lay <gjl>
Component: rtl-optimizationAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: normal CC: denisc
Priority: P3 Keywords: ra, wrong-code
Version: 15.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117868
Host: Target: avr
Build: Known to work:
Known to fail: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 56183, 113934    
Attachments: Reduced C test case from cmpdi-1.c

Description Georg-Johann Lay 2024-12-04 11:37:35 UTC
Created attachment 59782 [details]
Reduced C test case from cmpdi-1.c

There is yet another fail with -mlra with the attached cmpdi-1.c that produces wrong code.

$avr-gcc -mmcu=atmega128 -dumpbase "" -save-temps -dp -Os -o cmpdi-1.elf -mlra -fverbose-asm cmpdi-1.c

Notice the following load / stores involving Y+12 and X+12 in cmpdi-1.s:

   std Y+13,r25	 ;  %sfp, _51	 ;  685	[c=4 l=2]  *movhi/3
   std Y+12,r24	 ;  %sfp, _51
...
   std Y+12,r25	 ;  %sfp, tmp162 ;  588	[c=4 l=2]  *movhi/3
   std Y+11,r24	 ;  %sfp, tmp162
...
   std Y+11,r24	 ;  %sfp, arg1	 ;  615	[c=4 l=1]  movqi_insn/2
...
   ldd r16,Y+11	 ; , %sfp	 ;  640	[c=4 l=1]  movqi_insn/3
...
   std Y+12,r9	 ;  %sfp, res	 ;  439	[c=4 l=2]  *movhi/3
   std Y+11,r8	 ;  %sfp, res
...
   ldd r24,Y+12	 ;  _51, %sfp	 ;  435	[c=8 l=2]  *movhi/2
   ldd r25,Y+13	 ;  _51, %sfp

So it seems LRA is trampling some values / is using wrong offsets.

Target: avr
Configured with: ../../source/gcc-master/configure --target=avr --disable-nls --with-dwarf2 --with-gnu-as --with-gnu-ld --with-long-double=64 --enable-languages=c,c++
Thread model: single
Supported LTO compression algorithms: zlib
gcc version 15.0.0 20241203 (experimental) (GCC)
Comment 1 Georg-Johann Lay 2024-12-04 12:24:46 UTC
(In reply to Georg-Johann Lay from comment #0)
> ...involving Y+12 and X+12 in cmpdi-1.s
Meant "Y+12 and Y+11".
Comment 2 Georg-Johann Lay 2025-01-12 13:27:54 UTC
Dup

*** This bug has been marked as a duplicate of bug 117868 ***