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]

[Committed] Skip double->float conversions on x87 with -ffast-math(take 2)


The following patch has been committed to mainline.  Many thanks to Jan
Hubicka for privately reviewing/checking my original patch submission:
http://gcc.gnu.org/ml/gcc-patches/2004-03/msg01584.html

Jan noticed that in the original patch, the change to get_true_reg in
reg-stack.c handled FLOAT_TRUNCATE like FLOAT_EXTEND even when the user
hadn't specified -fflag_unsafe_math_optimizations or -ffast-math.  This
has been corrected in version below, which should guarantee there are no
code changes unless the user explicitly requests faster math.

The following patch has been tested on i686-pc-linux-gnu with a complete
"make bootstrap", all languages except treelang, and regression tested
with a top-level "make -k check" with no new failures.



2004-03-23  Roger Sayle  <roger@eyesopen.com>

	* reg-stack.c (get_true_reg): Handle FLOAT_TRUNCATE like FLOAT_EXTEND
	if flag_unsafe_math_optimizations.
	* config/i386/i386.md (truncdfsf2): If flag_unsafe_math_optimizations
	and TARGET_80387 expand using truncdfsf2_noop pattern.
	(truncxfsf2): Likewise using truncxfsf2_noop.
	(truncxfdf2): Likewise using truncxfdf2_noop.
	(truncdfsf2_noop, truncxfsf2_noop, truncxfdf2_noop): New patterns.


Index: reg-stack.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/reg-stack.c,v
retrieving revision 1.144
diff -c -3 -p -r1.144 reg-stack.c
*** reg-stack.c	3 Mar 2004 08:34:33 -0000	1.144
--- reg-stack.c	22 Mar 2004 03:23:05 -0000
*************** get_true_reg (rtx *pat)
*** 574,579 ****
--- 574,586 ----
        case FIX:
        case FLOAT_EXTEND:
  	pat = & XEXP (*pat, 0);
+ 	break;
+
+       case FLOAT_TRUNCATE:
+ 	if (!flag_unsafe_math_optimizations)
+ 	  return pat;
+ 	pat = & XEXP (*pat, 0);
+ 	break;
        }
  }

Index: config/i386/i386.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.md,v
retrieving revision 1.520
diff -c -3 -p -r1.520 i386.md
*** config/i386/i386.md	16 Mar 2004 23:29:22 -0000	1.520
--- config/i386/i386.md	22 Mar 2004 03:23:11 -0000
***************
*** 3653,3667 ****
  	      (clobber (match_dup 2))])]
    "TARGET_80387 || TARGET_SSE2"
    "
!    if (TARGET_80387)
!      operands[2] = assign_386_stack_local (SFmode, 0);
!    else
       {
  	emit_insn (gen_truncdfsf2_sse_only (operands[0], operands[1]));
  	DONE;
       }
  ")

  (define_insn "*truncdfsf2_1"
    [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f#rx,?r#fx,?x#rf")
  	(float_truncate:SF
--- 3653,3681 ----
  	      (clobber (match_dup 2))])]
    "TARGET_80387 || TARGET_SSE2"
    "
!    if (!TARGET_80387)
       {
  	emit_insn (gen_truncdfsf2_sse_only (operands[0], operands[1]));
  	DONE;
       }
+    else if (flag_unsafe_math_optimizations)
+      {
+ 	rtx reg = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SFmode);
+ 	emit_insn (gen_truncdfsf2_noop (reg, operands[1]));
+ 	if (reg != operands[0])
+ 	  emit_move_insn (operands[0], reg);
+ 	DONE;
+      }
+    else
+      operands[2] = assign_386_stack_local (SFmode, 0);
  ")

+ (define_insn "truncdfsf2_noop"
+   [(set (match_operand:SF 0 "register_operand" "=f")
+ 	(float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
+   "TARGET_80387 && flag_unsafe_math_optimizations"
+   "#")
+
  (define_insn "*truncdfsf2_1"
    [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f#rx,?r#fx,?x#rf")
  	(float_truncate:SF
***************
*** 3886,3892 ****
  		    (match_operand:XF 1 "register_operand" "")))
  	      (clobber (match_dup 2))])]
    "TARGET_80387"
!   "operands[2] = assign_386_stack_local (SFmode, 0);")

  (define_insn "*truncxfsf2_1"
    [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f#rx,?r#fx,?x#rf")
--- 3900,3923 ----
  		    (match_operand:XF 1 "register_operand" "")))
  	      (clobber (match_dup 2))])]
    "TARGET_80387"
!   "
!   if (flag_unsafe_math_optimizations)
!     {
!       rtx reg = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (SFmode);
!       emit_insn (gen_truncxfsf2_noop (reg, operands[1]));
!       if (reg != operands[0])
! 	emit_move_insn (operands[0], reg);
!       DONE;
!     }
!   else
!     operands[2] = assign_386_stack_local (SFmode, 0);
!   ")
!
! (define_insn "truncxfsf2_noop"
!   [(set (match_operand:SF 0 "register_operand" "=f")
! 	(float_truncate:SF (match_operand:XF 1 "register_operand" "f")))]
!   "TARGET_80387 && flag_unsafe_math_optimizations"
!   "#")

  (define_insn "*truncxfsf2_1"
    [(set (match_operand:SF 0 "nonimmediate_operand" "=m,?f#rx,?r#fx,?x#rf")
***************
*** 3948,3954 ****
  		    (match_operand:XF 1 "register_operand" "")))
  	      (clobber (match_dup 2))])]
    "TARGET_80387"
!   "operands[2] = assign_386_stack_local (DFmode, 0);")

  (define_insn "*truncxfdf2_1"
    [(set (match_operand:DF 0 "nonimmediate_operand" "=m,?f#rY,?r#fY,?Y#rf")
--- 3979,4002 ----
  		    (match_operand:XF 1 "register_operand" "")))
  	      (clobber (match_dup 2))])]
    "TARGET_80387"
!   "
!   if (flag_unsafe_math_optimizations)
!     {
!       rtx reg = REG_P (operands[0]) ? operands[0] : gen_reg_rtx (DFmode);
!       emit_insn (gen_truncxfdf2_noop (reg, operands[1]));
!       if (reg != operands[0])
! 	emit_move_insn (operands[0], reg);
!       DONE;
!     }
!   else
!     operands[2] = assign_386_stack_local (DFmode, 0);
!   ")
!
! (define_insn "truncxfdf2_noop"
!   [(set (match_operand:DF 0 "register_operand" "=f")
! 	(float_truncate:DF (match_operand:XF 1 "register_operand" "f")))]
!   "TARGET_80387 && flag_unsafe_math_optimizations"
!   "#")

  (define_insn "*truncxfdf2_1"
    [(set (match_operand:DF 0 "nonimmediate_operand" "=m,?f#rY,?r#fY,?Y#rf")


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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