Bug 28618 - The scheduler extends the lifetime of CLASS_LIKELY_SPILLED registers
Summary: The scheduler extends the lifetime of CLASS_LIKELY_SPILLED registers
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: ice-on-valid-code, patch
Depends on:
Blocks: 29842 29845
  Show dependency treegraph
 
Reported: 2006-08-06 03:58 UTC by Jorn Wolfgang Rennecke
Modified: 2008-01-11 12:12 UTC (History)
5 users (show)

See Also:
Host:
Target: sh-elf (modified)
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-09-13 08:18:57


Attachments
soft-fp patch for SH (under development) (33.43 KB, text/plain)
2006-08-06 04:00 UTC, Jorn Wolfgang Rennecke
Details
testcase (4.74 KB, text/plain)
2006-08-06 04:04 UTC, Jorn Wolfgang Rennecke
Details
patch to address the scheduler problem (proof of concept) (707 bytes, patch)
2006-08-06 04:32 UTC, Jorn Wolfgang Rennecke
Details | Diff
current patch incarnation (still testing) (874 bytes, patch)
2006-09-14 18:03 UTC, Jorn Wolfgang Rennecke
Details | Diff
patch using reg_last[regno+i].sets (775 bytes, patch)
2006-09-15 19:27 UTC, Jorn Wolfgang Rennecke
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jorn Wolfgang Rennecke 2006-08-06 03:58:03 UTC
Currently, the only check for CLASS_LIKELY_SPILLED registers is for instuctions
at the end of a basic block; this is insufficient, since a set/use pair of
a CLASS_LIKELY_SPILLED register can be in the middle of the block.  When
the scheduler inserts an instruction between into this pair which needs
a reload with the same class as the likely spilled register, a reload failure
is inevitable for calsses of size 1.
Comment 1 Andrew Pinski 2006-08-06 04:00:14 UTC
The scheduler should not know anything about if a register is likely to spill or not, that is the job of the RA.
Comment 2 Jorn Wolfgang Rennecke 2006-08-06 04:00:36 UTC
Created attachment 12023 [details]
soft-fp patch for SH (under development)

I found the scheduler bug while testing this patch.
Comment 3 Jorn Wolfgang Rennecke 2006-08-06 04:04:18 UTC
Created attachment 12024 [details]
testcase

To reproduce the problem, build an sh-elf targeted cc1 with sources
patched according to the previous attachment, and compile the testcase
with:
./cc1 -fpreprocessed k_rem_pio2.i -quiet -dumpbase k_rem_pio2.c -m4-nofpu -auxbase-strip lib_a-k_rem_pio2.o -g -O2 -O2 -O2 -version -fno-builtin -o k_rem_pio2.s
Comment 4 Jorn Wolfgang Rennecke 2006-08-06 04:32:42 UTC
Created attachment 12025 [details]
patch to address the scheduler problem (proof of concept)

This patch allows the testcase to compile.  I haven't had opportunity to
do further testing yet.
There might be problems if no matching set can be found in the current
basic block.  I'll have to think about how to best check for this.
I'm currently leaning to add a field in struct deps for the head of the
current basic block, and setting that field in sched_analyze.
Comment 5 Andrew Pinski 2006-08-06 04:46:57 UTC
Also one comment about your patch for soft-fp:
+  /* Wrap the sequence in REG_LIBCALL / REG_RETVAL notes so that loop
+     invariant code motion can move it.  */

The tree level loop invariant motion should have moved it already.  Why use LIBCALL here when we are already trying to remove it?
Comment 6 Jorn Wolfgang Rennecke 2006-08-06 07:22:47 UTC
(In reply to comment #1)
> The scheduler should not know anything about if a register is likely to spill
> or not, that is the job of the RA.

CLASS_LIKELY_SPIULLED is special because there is simply no way for reload to
fix this up when a single-register class is overcommitted, unless you want
to add code to reload to be able to undo any code transformation that the optimizers are capable of, which would also include the analysis to see what is possible - that would be more expensive then running all the optimizers. 
Therefore, there is a convention that the lifetime of CLASS_LIKELY_SPILLED registers must not be extended - just like you may not move a cc0_setter from a cc0_user, or a function call from the return value copy.
Note that there is some half-hearted code in sched-rgn.c whcih preserves cc0_setter / cc0_user pairs, call/return value copies, and CLASS_LIKELY_SPILLED
registers, but only if they appear at the end of the basic block.
For cc0 there is already the more thorough code in sched-deps.c, but it was missing for CLASS_LIKELY_SPILLED.

A historical note: the code to preserve CLASS_LIKELY_SPILLED registers originally applied to all hard registers, but only on targets that defined the SMALL_REGISTER_CLASSES target macro.
Comment 7 Jorn Wolfgang Rennecke 2006-08-06 07:24:21 UTC
(In reply to comment #5)
> Also one comment about your patch for soft-fp:
> +  /* Wrap the sequence in REG_LIBCALL / REG_RETVAL notes so that loop
> +     invariant code motion can move it.  */
> 
> The tree level loop invariant motion should have moved it already.  Why use
> LIBCALL here when we are already trying to remove it?

That bit is from 2004.
Comment 8 Eric Botcazou 2006-09-13 08:18:57 UTC
> There might be problems if no matching set can be found in the current
> basic block.  I'll have to think about how to best check for this.
> I'm currently leaning to add a field in struct deps for the head of the
> current basic block, and setting that field in sched_analyze.

Why not use reg_last->sets?
Comment 9 Jorn Wolfgang Rennecke 2006-09-14 17:54:43 UTC
(In reply to comment #8)
> > There might be problems if no matching set can be found in the current
> > basic block.  I'll have to think about how to best check for this.
> > I'm currently leaning to add a field in struct deps for the head of the
> > current basic block, and setting that field in sched_analyze.
> 
> Why not use reg_last->sets?
> 
AFAICT, reg_last[0].sets is live at that point.
Comment 10 Jorn Wolfgang Rennecke 2006-09-14 18:03:26 UTC
Created attachment 12267 [details]
current patch incarnation (still testing)

At any rate, I must not set SCHED_GROUP_P on the first insn of a scheduling
group.
Comment 11 Jorn Wolfgang Rennecke 2006-09-14 21:43:31 UTC
(In reply to comment #10)
> Created an attachment (id=12267) [edit]
> current patch incarnation (still testing)
> 
> At any rate, I must not set SCHED_GROUP_P on the first insn of a scheduling
> group.
> 
I forgot a succ = prev; here.
Comment 12 Eric Botcazou 2006-09-15 07:31:01 UTC
> > Why not use reg_last->sets?
> > 
> AFAICT, reg_last[0].sets is live at that point.

Sorry, I don't understand your answer.  I was suggesting to use reg_last->sets
to get the last set of the reg instead of privately re-scanning the RTL.
Comment 13 Jorn Wolfgang Rennecke 2006-09-15 19:27:01 UTC
Created attachment 12278 [details]
patch using reg_last[regno+i].sets