https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118591
--- Comment #2 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
(In reply to Georg-Johann Lay from comment #1)
> Created attachment 60230 [details]
> reduced C99 test case
In that test case:
__attribute__((noipa))
void func2 (long a, long b)
{
static unsigned char count = 0;
if (b != count++)
__builtin_abort ();
}
int main (void)
{
for (long b = 0; b < 5; ++b)
func2 (0, b);
return 0;
}
With -mlra -Os -mmcu=attiny40 -dp, main prepares argument b as follows (it
lives in Y[1]:SI):
subi r28,-4 ; 48 [c=8 l=2] *addhi3/3
sbci r29,-1
ld r20,Y ; 49 [c=4 l=1] movqi_insn/3
push r20 ; 8 [c=4 l=1] pushqi1/0
ld r20,Y ; 53 [c=4 l=1] movqi_insn/3
push r20 ; 10 [c=4 l=1] pushqi1/0
ld r20,Y ; 57 [c=4 l=1] movqi_insn/3
push r20 ; 12 [c=4 l=1] pushqi1/0
ld r20,Y+ ; 96 [c=4 l=1] movqi_insn/3
push r20 ; 14 [c=4 l=1] pushqi1/0
which is complete garbage and looks like elimination going bananas. With
-mno-lra, all is fine:
subi r28,-4 ; 47 [c=8 l=2] *addhi3/3
sbci r29,-1
ld r20,Y ; 48 [c=4 l=1] movqi_insn/3
push r20 ; 8 [c=4 l=1] pushqi1/0
ld r21,-Y ; 91 [c=4 l=1] movqi_insn/3
push r21 ; 10 [c=4 l=1] pushqi1/0
ld r22,-Y ; 93 [c=4 l=1] movqi_insn/3
push r22 ; 12 [c=4 l=1] pushqi1/0
ld r23,-Y ; 95 [c=4 l=1] movqi_insn/3
push r23 ; 14 [c=4 l=1] pushqi1/0
(FYI, the FP in Y is adjusted later (after the call) due to -mfuse-add, which
also tidies the byte loads to LD -Y.)