[Bug target/40983] New: The scheduler incorrectly swaps MMX and floating point instructions

View: New views
7 Messages — Rating Filter:   Alert me  

[Bug target/40983] New: The scheduler incorrectly swaps MMX and floating point instructions

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi

This example fails, because in function "f", the scheduler incorrectly swapped
floating point store to "c" and load of mmx registers.

Compile with -O2 -march=pentium-mmx


--
           Summary: The scheduler incorrectly swaps MMX and floating point
                    instructions
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mikulas at artax dot karlin dot mff dot cuni dot cz
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40983


[Bug target/40983] The scheduler incorrectly swaps MMX and floating point instructions

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #1 from mikulas at artax dot karlin dot mff dot cuni dot cz  2009-08-06 04:12 -------
Created an attachment (id=18310)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18310&action=view)
A failing example


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40983


[Bug target/40983] The scheduler incorrectly swaps MMX and floating point instructions

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #2 from mikulas at artax dot karlin dot mff dot cuni dot cz  2009-08-06 04:15 -------
Assembler output:

f:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $16, %esp
        movq    %mm0, -8(%ebp)
        movq    %mm1, -16(%ebp)
        emms
        fldl    a
        faddl   b
        movq    -8(%ebp), %mm0
        paddd   -16(%ebp), %mm0
        fstpl   c
        leave
        ret


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40983


[Bug target/40983] The scheduler incorrectly swaps MMX and floating point instructions

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #3 from ubizjak at gmail dot com  2009-08-06 10:47 -------
Hm, we can fix this by teaching scheduler that every access to %mm registers
clobbers FP state. Since scheduler already depend all x87 instructions on
Top-Of-Stack (TOS) register, we can perhaps extend this requirement for all
instructions that use %mm reg.

Something like the proof-of-concept patch bellow:

--cut here--
Index: sched-deps.c
===================================================================
--- sched-deps.c        (revision 150503)
+++ sched-deps.c        (working copy)
@@ -1898,7 +1898,12 @@
            sched_analyze_reg (deps, FIRST_STACK_REG, mode, code, insn);
          sched_analyze_reg (deps, FIRST_STACK_REG, mode, USE, insn);
        }
+
+#ifdef FIRST_MMX_REG
+      if (regno >= FIRST_MMX_REG && regno <= LAST_MMX_REG)
+       sched_analyze_reg (deps, FIRST_STACK_REG, VOIDmode, CLOBBER, insn);
 #endif
+#endif
     }
   else if (MEM_P (dest))
     {
@@ -2044,7 +2049,12 @@
            sched_analyze_reg (deps, FIRST_STACK_REG, mode, USE, insn);
          sched_analyze_reg (deps, FIRST_STACK_REG, mode, SET, insn);
        }
+
+#ifdef FIRST_MMX_REG
+      if (regno >= FIRST_MMX_REG && regno <= LAST_MMX_REG)
+       sched_analyze_reg (deps, FIRST_STACK_REG, VOIDmode, CLOBBER, insn);
 #endif
+#endif

        if (cslr_p && sched_deps_info->finish_rhs)
          sched_deps_info->finish_rhs ();
--cut here--

Otherwise, you can just add "asm volatile ("")" as a scheduling barrier.


--

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-08-06 10:47:08
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40983


[Bug target/40983] The scheduler incorrectly swaps MMX and floating point instructions

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #4 from mikulas at artax dot karlin dot mff dot cuni dot cz  2009-08-23 19:18 -------
The patch works fine.


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40983


[Bug target/40983] The scheduler incorrectly swaps MMX and floating point instructions

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #5 from sezeroz at gmail dot com  2009-10-16 19:45 -------
Any progress on this?


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40983


[Bug target/40983] The scheduler incorrectly swaps MMX and floating point instructions

by Bugzilla from gcc-bugzilla@gcc.gnu.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



------- Comment #6 from mikulas at artax dot karlin dot mff dot cuni dot cz  2009-11-11 23:06 -------
I think you can commit it to gcc. I don't see a reason why it shouldn't be
committed.


--


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40983