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]

[3.4-BIB] fix min/max instructions


Hi,
We do not generate min instructions at all and sometimes lose track and
kill max instruction.  This patch should fix that and adds testcases.
Bootstrapped/regtested i386.  OK for BIB branch?

Honza

/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
/* { dg-options "-O2 -msse2 -march=athlon" } */
/* { dg-final { scan-assembler "maxsd" } } */
/* { dg-final { scan-assembler "minsd" } } */
double x;
t()
{
  x=x>5?x:5;
}

double x;
q()
{
  x=x<5?x:5;
}


/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
/* { dg-options "-O2 -msse2 -march=athlon" } */
/* { dg-final { scan-assembler "maxsd" } } */
/* { dg-final { scan-assembler "minsd" } } */
double x;
q()
{
  x=x<5?5:x;
}

double x;
q1()
{
  x=x>5?5:x;
}

Thu Nov  7 18:26:31 CET 2002  Jan Hubicka  <jh@suse.cz>
	* i386.md (sse_movdfcc, sse_movsfcc): Avoid overactive matching.
	* i386.c (ix86_expand_fp_movcc): Match the reversed cases.
Index: i386.md
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.md,v
retrieving revision 1.380.2.6
diff -c -3 -p -r1.380.2.6 i386.md
*** i386.md	31 Oct 2002 15:12:50 -0000	1.380.2.6
--- i386.md	7 Nov 2002 17:25:35 -0000
***************
*** 16908,16913 ****
--- 17039,17050 ----
     (clobber (reg:CC 17))]
    "TARGET_SSE
     && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)
+    /* Avoid combine from being smart and converting min/max
+       instruction patterns into conditional moves.  */
+    && ((GET_CODE (operands[1]) != LT && GET_CODE (operands[1]) != GT
+ 	&& GET_CODE (operands[1]) != UNLE && GET_CODE (operands[1]) != UNGE)
+        || !rtx_equal_p (operands[4], operands[2])
+        || !rtx_equal_p (operands[5], operands[5]))
     && (!TARGET_IEEE_FP
         || (GET_CODE (operands[1]) != EQ && GET_CODE (operands[1]) != NE))"
    "#")
***************
*** 16935,16940 ****
--- 17072,17083 ----
     (clobber (reg:CC 17))]
    "TARGET_SSE2
     && (GET_CODE (operands[2]) != MEM || GET_CODE (operands[3]) != MEM)
+    /* Avoid combine from being smart and converting min/max
+       instruction patterns into conditional moves.  */
+    && ((GET_CODE (operands[1]) != LT && GET_CODE (operands[1]) != GT
+ 	&& GET_CODE (operands[1]) != UNLE && GET_CODE (operands[1]) != UNGE)
+        || !rtx_equal_p (operands[4], operands[2])
+        || !rtx_equal_p (operands[5], operands[5]))
     && (!TARGET_IEEE_FP
         || (GET_CODE (operands[1]) != EQ && GET_CODE (operands[1]) != NE))"
    "#")
Index: i386.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/config/i386/i386.c,v
retrieving revision 1.446.2.4
diff -c -3 -p -r1.446.2.4 i386.c
*** i386.c	1 Nov 2002 01:12:28 -0000	1.446.2.4
--- i386.c	7 Nov 2002 17:26:04 -0000
*************** ix86_expand_fp_movcc (operands)
*** 9615,9622 ****
        if (rtx_equal_p (operands[2], op0) && rtx_equal_p (operands[3], op1))
  	{
  	  /* Check for min operation.  */
! 	  if (code == LT)
  	    {
  	       operands[0] = force_reg (GET_MODE (operands[0]), operands[0]);
  	       if (memory_operand (op0, VOIDmode))
  		 op0 = force_reg (GET_MODE (operands[0]), op0);
--- 9615,9628 ----
        if (rtx_equal_p (operands[2], op0) && rtx_equal_p (operands[3], op1))
  	{
  	  /* Check for min operation.  */
! 	  if (code == LT || code == UNLE)
  	    {
+ 	       if (code == UNLE)
+ 		{
+ 		  rtx tmp = op0;
+ 		  op0 = op1;
+ 		  op1 = tmp;
+ 		}
  	       operands[0] = force_reg (GET_MODE (operands[0]), operands[0]);
  	       if (memory_operand (op0, VOIDmode))
  		 op0 = force_reg (GET_MODE (operands[0]), op0);
*************** ix86_expand_fp_movcc (operands)
*** 9627,9634 ****
  	       return 1;
  	    }
  	  /* Check for max operation.  */
! 	  if (code == GT)
  	    {
  	       operands[0] = force_reg (GET_MODE (operands[0]), operands[0]);
  	       if (memory_operand (op0, VOIDmode))
  		 op0 = force_reg (GET_MODE (operands[0]), op0);
--- 9633,9646 ----
  	       return 1;
  	    }
  	  /* Check for max operation.  */
! 	  if (code == GT || code == UNGE)
  	    {
+ 	       if (code == UNGE)
+ 		{
+ 		  rtx tmp = op0;
+ 		  op0 = op1;
+ 		  op1 = tmp;
+ 		}
  	       operands[0] = force_reg (GET_MODE (operands[0]), operands[0]);
  	       if (memory_operand (op0, VOIDmode))
  		 op0 = force_reg (GET_MODE (operands[0]), op0);


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