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] Annotate FP comparisons in ix86_expand_setcc


The following patch tweaks ix86_expand_setcc to annotate the complex
instruction sequence used to store floating point flags on x87 with
a REG_EQUAL note.

To demonstrate the effects, consider the following example:

int foo()
{
  double x = 2.0;
  double y = 3.0;
  return x < y;
}

when compiled on i686-pc-linux-gnu with -O2, mainline currently generates:

foo:    flds    .LC1
        flds    .LC0
        fxch    %st(1)
        fucompp
        fnstsw  %ax
        pushl   %ebp
        testb   $69, %ah
        movl    %esp, %ebp
        sete    %al
        movzbl  %al, %eax
        leave
        ret

which mysteriously the RTL optimizers can't deduce is constant :>
With the patch below, we now generate:

foo:    pushl   %ebp
        movl    %esp, %ebp
        movl    $1, %eax
        leave
        ret



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.

Ok for mainline?


2003-10-06  Roger Sayle  <roger@eyesopen.com>

	* config/i386/i386.c (ix86_expand_setcc): Annotate the floating
	point comparison sequence with a REG_EQUAL note that describes
	the comparison's semantics.


Index: i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.603
diff -c -3 -p -r1.603 i386.c
*** i386.c	26 Sep 2003 03:46:05 -0000	1.603
--- i386.c	6 Oct 2003 17:08:25 -0000
*************** ix86_split_fp_branch (enum rtx_code code
*** 9334,9340 ****
  int
  ix86_expand_setcc (enum rtx_code code, rtx dest)
  {
!   rtx ret, tmp, tmpreg;
    rtx second_test, bypass_test;

    if (GET_MODE (ix86_compare_op0) == DImode
--- 9334,9340 ----
  int
  ix86_expand_setcc (enum rtx_code code, rtx dest)
  {
!   rtx ret, tmp, tmpreg, equiv;
    rtx second_test, bypass_test;

    if (GET_MODE (ix86_compare_op0) == DImode
*************** ix86_expand_setcc (enum rtx_code code, r
*** 9372,9377 ****
--- 9372,9383 ----
        else
  	emit_insn (gen_iorqi3 (tmp, tmpreg, tmp2));
      }
+
+   /* Attach a REG_EQUAL note describing the comparison result.  */
+   equiv = simplify_gen_relational (code, QImode,
+ 				   GET_MODE (ix86_compare_op0),
+ 				   ix86_compare_op0, ix86_compare_op1);
+   set_unique_reg_note (get_last_insn (), REG_EQUAL, equiv);

    return 1; /* DONE */
  }


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]