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 PR target/26915: -1 should be loaded as fld1;fchs


Hello!

This patch implements optimization, suggested in PR target/26915. A sequence of fld1;fchs is always shorter than load of constant from memory. In addition to data space, code size decreases by 2 bytes for every load of -1, so IMO is this valid optimization for -Os.

Patch was bootstrapped and regression tested on x86_64-pc-linux-gnu.

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

PR target/26915
* config/i386/i386.c (standard_80387_constant_p): When optimizing for
size, treat -1 as a valid 80387 constant.
(standard_80387_constant_opcode): Return "#" for constant -1.
* config/i386/i386.md (unnamed splitter): When optimizing for size,
split load of constant -1 into load of 1 and negation sequence.


testsuite/ChangeLog:

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

       PR target/26915
       * gcc.target/i386/387-12.c: New test.

OK for mainline?

Uros.
Index: config/i386/i386.md
===================================================================
--- config/i386/i386.md	(revision 118458)
+++ config/i386/i386.md	(working copy)
@@ -2912,6 +2912,17 @@
   [(set_attr "type" "fxch")
    (set_attr "mode" "XF")])
 
+;; When optimizing for size, split load of -1 into fld1;fchs
+(define_split
+  [(set (match_operand:X87MODEF 0 "register_operand" "")
+	(match_operand:X87MODEF 1 "immediate_operand" ""))]
+  "reload_completed && FP_REGNO_P (REGNO (operands[0]))
+   && standard_80387_constant_p (operands[1]) == 8"
+  [(set (match_dup 0)(match_dup 1))
+   (set (match_dup 0)
+	(neg:X87MODEF (match_dup 0)))]
+  "operands[1] = CONST1_RTX (<MODE>mode);")
+
 (define_expand "movtf"
   [(set (match_operand:TF 0 "nonimmediate_operand" "")
 	(match_operand:TF 1 "nonimmediate_operand" ""))]
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 118458)
+++ config/i386/i386.c	(working copy)
@@ -4600,6 +4600,11 @@
 	  return i + 3;
     }
 
+  /* When optimizing for size, generate -1 as fld1;fchs.  */
+  if (optimize_size
+      && real_identical (CONST_DOUBLE_REAL_VALUE (x), &dconstm1))
+    return 8;
+
   return 0;
 }
 
@@ -4625,6 +4630,8 @@
       return "fldl2t";
     case 7:
       return "fldpi";
+    case 8:
+      return "#";
     default:
       gcc_unreachable ();
     }
Index: testsuite/gcc.target/i386/387-12.c
===================================================================
--- testsuite/gcc.target/i386/387-12.c	(revision 0)
+++ testsuite/gcc.target/i386/387-12.c	(revision 0)
@@ -0,0 +1,11 @@
+/* PR target/26915 */
+/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
+/* { dg-require-effective-target ilp32 } */
+/* { dg-options "-Os" } */
+
+double test(void)
+{
+	return -1.0;
+}
+
+/* { dg-final { scan-assembler "fld1" } } */

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