diff mbox

Fix SH port failure in delay slot scheduling

Message ID 39407793-4668-f15f-facb-3cd7ecda1c9e@redhat.com
State New
Headers show

Commit Message

Jeff Law April 12, 2017, 4:10 p.m. UTC
The SH port has this delay slot description like this:

;; Conditional branches with delay slots are available starting with SH2.
;; If zero displacement conditional branches are fast, disable the delay
;; slot if the branch jumps over only one 2-byte insn.
(define_delay
   (and (eq_attr "type" "cbranch")
        (match_test "TARGET_SH2")
        (not (and (match_test "TARGET_ZDCBRANCH")
                  (match_test "sh_cbranch_distance (insn, 4) == 2"))))
   [(eq_attr "cond_delay_slot" "yes") (nil) (nil)])



What's interesting here is whether or not a particular insn has a delay 
slot is dependent on nearby insns *and* it can change within the reorg 
pass itself.  This can cause assert failures within 
write_eligible_for_delay.

It's been 20+ years since I was deep into the delay slot scheduler, but 
my recollection is this doesn't consistently work and I could argue that 
this delay slot description is fundamentally broken.

While I can fix this specific assertion failure, I would not at all be 
surprised if there's other issues lurking.  The port maintainers should 
be on notice that this description may need to be adjusted in the future 
to remove the distance test.

Addressing this specific failure can be done by verifying the given insn 
still has a delay slot in eligible_for_delay*.   That's enough to get 
the SH to build libgcc/newlib.  I've also verified other ports that use 
delay slots such as the PA & Sparc can build glibc and newlib as 
appropriate.

Installing on the trunk.

Jeff
commit 294e866ca9e7e59f5cd637e5b746828c614e6bc5
Author: law <law@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Apr 12 16:08:18 2017 +0000

    	* genattrtab.c (write_eligible_delay): Verify DELAY_INSN still
    	has a delay slot in the generated code.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@246879 138bc75d-0d04-0410-961f-82ee72b054a4
diff mbox

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index fc0becf..89af9cc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,8 @@ 
 2017-04-12  Jeff Law  <law@redhat.com>
 
+	* genattrtab.c (write_eligible_delay): Verify DELAY_INSN still
+	has a delay slot in the generated code.
+
 	* config/cris/cris.md (cris_preferred_reload_class): Return
 	GENNONACR_REGS rather than GENERAL_REGS.
 
diff --git a/gcc/genattrtab.c b/gcc/genattrtab.c
index cd4e668..3629b5f 100644
--- a/gcc/genattrtab.c
+++ b/gcc/genattrtab.c
@@ -4416,6 +4416,9 @@  write_eligible_delay (FILE *outf, const char *kind)
   fprintf (outf, "{\n");
   fprintf (outf, "  rtx_insn *insn ATTRIBUTE_UNUSED;\n");
   fprintf (outf, "\n");
+  fprintf (outf, "  if (num_delay_slots (delay_insn) == 0)\n");
+  fprintf (outf, "    return 0;");
+  fprintf (outf, "\n");
   fprintf (outf, "  gcc_assert (slot < %d);\n", max_slots);
   fprintf (outf, "\n");
   /* Allow dbr_schedule to pass labels, etc.  This can happen if try_split