This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, i386] Avoid FP constants in wrong register set


Hello!

This patch fixes the problems with SSE constants loaded to x87 register and vice versa.

2005-01-25 Uros Bizjak <uros@kss-loka.si>

   * config/i386/i386.c (standard_80387_constant_p): Do not put
   SSE constants into x87 register for TARGET_SSE_MATH.
   (standard_sse_constant_p): Do not put x87 constants into SSE
   register for !TARGET_SSE_MATH.
   (ix86_preferred_reload_class): Use standard_sse_constant_p
   for CONST_VECTOR operand.  Fix loading of SSE constants into
   SSE registers for TARGET_SSE_MATH.

Patch is bootstrapped on i686-pc-linux-gnu, regtested with c,c++.

These are the results for various -mfpmath povray-3.50c builds:

       pxor        fldz        fld1
binary    :
sse    :    743        0        0
387    :    0        1049        780
387,sse    :    475        265        399

The results of PovRay were checked for correctnes.

However, there are still some incosistencies with SFmode and DFmode moves in SSE mode. gcc prefers x87 registers for "useless" moves. These are illustrated in following asm snippet:

...
804bed1:    f2 0f 59 84 24 c0 00     mulsd  0xc0(%esp,1),%xmm0
804bed8:    00 00
804beda:    f2 0f 11 84 24 c0 00     movsd  %xmm0,0xc0(%esp,1)
804bee1:    00 00
804bee3:    dd 84 24 c0 00 00 00     fldl   0xc0(%esp,1)
804beea:    dd 1c 24                 fstpl  (%esp,1)
804beed:    e8 42 ed ff ff           call   804ac34 <_init+0x6f8>
804bef2:    dd 5c 24 28              fstpl  0x28(%esp,1)
804bef6:    f2 0f 10 44 24 28        movsd  0x28(%esp,1),%xmm0
....

The result from %xmm0 goes thru memory at 0xc0(%esp) to x87 reg and back to (%esp). Why such a creative approach, when simple "movsd %xmm0,(%esp,1)" would be enough?

Uros.

? i387.md
Index: i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.789
diff -u -p -r1.789 i386.c
--- i386.c	22 Jan 2005 23:07:53 -0000	1.789
+++ i386.c	25 Jan 2005 09:23:27 -0000
@@ -3669,6 +3669,11 @@ standard_80387_constant_p (rtx x)
   if (GET_CODE (x) != CONST_DOUBLE || !FLOAT_MODE_P (GET_MODE (x)))
     return -1;
 
+  /* Do not put SSE constants into x87 register for TARGET_SSE_MATH.  */
+  if (TARGET_SSE_MATH && SSE_FLOAT_MODE_P (GET_MODE (x))
+      && !TARGET_MIX_SSE_I387)
+    return 0;
+
   if (x == CONST0_RTX (GET_MODE (x)))
     return 1;
   if (x == CONST1_RTX (GET_MODE (x)))
@@ -3755,6 +3760,10 @@ standard_80387_constant_rtx (int idx)
 int
 standard_sse_constant_p (rtx x)
 {
+  /* Do not put x87 constants into SSE register for !TARGET_SSE_MATH.  */
+  if (!TARGET_SSE_MATH && SSE_FLOAT_MODE_P (GET_MODE (x)))
+    return 0;
+
   if (x == const0_rtx)
     return 1;
   return (x == CONST0_RTX (GET_MODE (x)));
@@ -14668,14 +14677,22 @@ ix86_preferred_reload_class (rtx x, enum
 {
   if (class == NO_REGS)
     return NO_REGS;
-  if (GET_CODE (x) == CONST_VECTOR && x != CONST0_RTX (GET_MODE (x)))
+  if (GET_CODE (x) == CONST_VECTOR && !standard_sse_constant_p (x))
     return NO_REGS;
+
   if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) != VOIDmode)
     {
-      /* SSE can't load any constant directly yet.  */
-      if (SSE_CLASS_P (class))
-	return NO_REGS;
-      /* Floats can load 0 and 1.  */
+      /* SSE can load zero directly.  */
+      if (MAYBE_SSE_CLASS_P (class)
+	  && TARGET_SSE_MATH && SSE_FLOAT_MODE_P (GET_MODE(x)))
+	{
+	  if (standard_sse_constant_p (x))
+	    return SSE_REGS;
+	  if (!TARGET_MIX_SSE_I387)
+	    return NO_REGS;
+	}
+
+      /* x87 can load various constants.  */
       if (MAYBE_FLOAT_CLASS_P (class) && standard_80387_constant_p (x))
 	{
 	  /* Limit class to non-SSE.  Use GENERAL_REGS if possible.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]