]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[genoutput] mark scratch outputs as eliminable [PR120424]
authorAlexandre Oliva <oliva@adacore.com>
Fri, 27 Jun 2025 00:01:21 +0000 (21:01 -0300)
committerAlexandre Oliva <oliva@gnu.org>
Fri, 27 Jun 2025 00:01:21 +0000 (21:01 -0300)
acats' fdd2a00.read is miscompiled on arm-linux-gnu with -O2
-fstack-clash-protection -march=armv7-a -marm: a clobbered scratch
register in a *iorsi3_compare0_scratch pattern gets initially assigned
to the frame pointer register, but at some point during lra the frame
size grows to nonzero, arm_frame_pointer_required flips to true, and
the fp2sp elimination has to be disabled, so the scratch register gets
spilled to a stack slot.

It needs to get the sfp elimination at that point, because later
rounds of elimination will assume the previous round's offset has
already been applied.  But since scratch matches are not regarded as
eliminable by genoutput, we don't attempt elimination in the clobbered
stack slot MEM rtx.

Later on, lra issues a reload for that slot, using a new pseudo
allocated to a hardware register, that gets stored in the stack slot
after the original insn.  Elimination in that reload store insn
eventually updates the elimination offset, but it's an incremental
update, assuming that the offset so far has already been applied.

Without applying the initial offset, the store ends up overlapping
with the function's register save area, corrupting a caller's
call-saved register.

AFAICT the old reload's elimination wouldn't be harmed by allowing
elimination in scratch operands, so I'm enabling eliminable for them
regardless.  Should it be found to make a difference, we could
presumably set a different bit in eliminable to enable reload and lra
to tell them apart and behave accordingly.

for  gcc/ChangeLog

PR rtl-optimization/120424
* genoutput.cc (scan_operands): Make MATCH_SCRATCHes eliminable.

gcc/genoutput.cc

index dd4e7b80c2a91ccd1ace8f9223387d4ac6b55647..25d0b8b8646763c81c24b5924ed91468b8d820f3 100644 (file)
@@ -478,7 +478,7 @@ scan_operands (class data *d, rtx part, int this_address_p,
       d->operand[opno].n_alternatives
        = n_occurrences (',', d->operand[opno].constraint) + 1;
       d->operand[opno].address_p = 0;
-      d->operand[opno].eliminable = 0;
+      d->operand[opno].eliminable = 1;
       return;
 
     case MATCH_OPERATOR: