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]: Fix float_extend load of x87 constants


Hello!

There were problems w.r.t. to float_extend of x87 constants, where no fldz, fld1 & co. constants were produced. This problem was somehow fixed by my rtx_cost patch from August:

       * config/i386/i386.c (ix86_rtx_costs) [FLOAT_EXTEND]: For
       standard 80387 constants, raise the cost to prevent
       compress_float_constant() to generate load from memory.

that raised the cost of float extend. However, the "collateral damage" from this patch can be seen in FP operators (fadd{s,l} and fsub{s,l} ) with memory operators. For following testcase:

double test(double a)
{
       return sqrt(a) + 1.0;
}

we produced:

       fsqrt
       faddl   .LC0

sequence, but "fadds .LCO" would be better. Please note, that operand with memory operator is always faster than "fld1, faddp" sequence.

Attached patch reverts the above patch (barking at wrong tree, apparently) and fixes the problem in its core. The problem is simply forgotten splitter pattern, that would split float_extend patterns into valid x87 (and SSE FWIW) constant loads. The infrastructure for the transformation is already in place.

2006-11-26 Uros Bizjak <ubizjak@gmail.com>

       Revert:
       2006-05-08  Uros Bizjak  <uros@kss-loka.si>
       * config/i386/i386.c (ix86_rtx_costs) [FLOAT_EXTEND]: For
       standard 80387 constants, raise the cost to prevent
       compress_float_constant() to generate load from memory.

       * config/i386/i386.md: Add new splitter pattern to split
       float_extended load of constant from constant pool into
       pure constant load.

Patch was bootstrapped on x86_64-pc-linux-gnu and regression tested for c, c++ and fortran.

OK for mainline?

Uros.
Index: i386.md
===================================================================
--- i386.md	(revision 119218)
+++ i386.md	(working copy)
@@ -2906,6 +2906,38 @@
   operands[1] = c;
 })
 
+(define_split
+  [(set (match_operand 0 "register_operand" "")
+	(float_extend (match_operand 1 "memory_operand" "")))]
+  "reload_completed
+   && GET_CODE (operands[1]) == MEM
+   && (GET_MODE (operands[0]) == XFmode
+       || GET_MODE (operands[0]) == SFmode || GET_MODE (operands[0]) == DFmode)
+   && constant_pool_reference_p (operands[1])"
+  [(set (match_dup 0) (match_dup 1))]
+{
+  rtx c = avoid_constant_pool_reference (SET_SRC (PATTERN (curr_insn)));
+  rtx r = operands[0];
+
+  if (GET_CODE (r) == SUBREG)
+    r = SUBREG_REG (r);
+
+  if (SSE_REG_P (r))
+    {
+      if (!standard_sse_constant_p (c))
+	FAIL;
+    }
+  else if (FP_REG_P (r))
+    {
+      if (!standard_80387_constant_p (c))
+	FAIL;
+    }
+  else if (MMX_REG_P (r))
+    FAIL;
+
+  operands[1] = c;
+})
+
 (define_insn "swapxf"
   [(set (match_operand:XF 0 "register_operand" "+f")
 	(match_operand:XF 1 "register_operand" "+f"))
Index: i386.c
===================================================================
--- i386.c	(revision 119218)
+++ i386.c	(working copy)
@@ -17705,22 +17705,7 @@
       if (!TARGET_SSE_MATH
 	  || mode == XFmode
 	  || (mode == DFmode && !TARGET_SSE2))
-	/* For standard 80387 constants, raise the cost to prevent
-	   compress_float_constant() to generate load from memory.  */
-	switch (standard_80387_constant_p (XEXP (x, 0)))
-	  {
-	  case -1:
-	  case 0:
-	    *total = 0;
-	    break;
-	  case 1: /* 0.0 */
-	    *total = 1;
-	    break;
-	  default:
-	    *total = (x86_ext_80387_constants & TUNEMASK
-		      || optimize_size
-		      ? 1 : 0);
-	  }
+	*total = 0;
       return false;
 
     case ABS:

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