https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87944
Bug ID: 87944
Summary: Wrong code with LRA pushing stack local variable
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: pkoning at gcc dot gnu.org
Target Milestone: ---
Created attachment 44977
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44977&action=edit
Dump file before reload
I see this on pdp11, I haven't found a mainline target yet that reproduces it.
The issue is on a call that passes the address of a local variable, with
arguments pushed on the stack so effectively we get a push(frame_pointer).
With frame pointer elimination, that becomes push(stack_pointer).
But that's not a legal instruction on this machine, and I created constraints
that say so. With the old reload, I see the intended result: copy SP to
another register, then push that register.
LRA instead adjusts the stack pointer by a word to make room for the argument,
then copies the stack pointer to that spot. The result is that the argument is
off by one word because it copied the SP after adjustment rather than
generating the value before. The offending pdp11 code looks like this:
add $-02,sp
mov sp,(sp)
jsr pc,_strlen
what's wanted is something like this:
mov sp,r0
mov r0,-(sp)
I've seen variations of this issue in LRA; the common thread is that it doesn't
aways account for changes in SP when calculating the SP offset for a local
variable.
I'll attach dump files that show the issue. The issue is with insn 12.