https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88284

            Bug ID: 88284
           Summary: nios2: pessimistic ldw-to-stwio scheduling
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: already5chosen at yahoo dot com
  Target Milestone: ---

Created attachment 45131
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45131&action=edit
demonstration of bad scheduling

Compiler generates bad scheduling for memory-to-io copy loops.
It seems that Nios2 instruction scheduler somehow don't understand that stwio
instruction depends on the value it is going to store.

I have no idea why, instead of producing random schedule, the compiler
consistently generates the worst possible schedule. Possibly, it is a result of
unfortunate interaction with one of the middle-end heuristics (attempt of
prefetch?). 
But the reason is less important than the outcome.

My demonstration code consists of four examples of good scheduling for cases of
memory-to-memory copies and four examples of bad scheduling for cases of
memory-to-io copies. An optimal scheduling for memory-to-io copies (ldw
followed by stwio) is exactly the same as for memory-to-memory copies (ldw
followed by stw).
In both cases in order to avoid pipeline stall ldw and an instruction that
depends on loaded values shell be separated by at least two unrelated
instructions.

Compiled with 'nios2-elf-gcc -c -Wall -ffreestanding -O2 --save-temps'
gcc version 8.2.0

Reply via email to