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]

PATCH: Small combine glitch, testcase, and patch.



In the testcase below, combine was erroneously deleting an smax operation
because it concluded that the value of the operation under the if_then_else
it fed (with the same operands) was always zero. This is due to incorrect
handling of NE/EQ by known_cond.

Bootstrapped on i686-linux (the testcase originally failed on hppa, but 
bootstrapping there is agonizingly slow).


2001-02-21  Jason Eckhardt  <jle@redhat.com>

	* combine.c (known_cond): Do not reverse the condition when
	SMAX/UMAX is being considered and the condition is for equality 
	or inequality.

	* testsuite/gcc.c-torture/execute/20010221-1.c: New test.

Index: combine.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/combine.c,v
retrieving revision 1.185
diff -c -3 -p -r1.185 combine.c
*** combine.c	2001/02/18 20:24:09	1.185
--- combine.c	2001/02/22 02:19:16
*************** known_cond (x, cond, reg, val)
*** 7512,7518 ****
  	    {
  	      int unsignedp = (code == UMIN || code == UMAX);
  
! 	      if (code == SMAX || code == UMAX)
  		cond = reverse_condition (cond);
  
  	      switch (cond)
--- 7512,7523 ----
  	    {
  	      int unsignedp = (code == UMIN || code == UMAX);
  
! 	      /* Do not reverse the condition when it is NE or EQ.
! 		 This is because we cannot conclude anything about
! 		 the value of 'SMAX (x, y)' when x is not equal to y,
! 		 but we can when x equals y.  */ 
! 	      if ((code == SMAX || code == UMAX)
! 		  && ! (cond == EQ || cond == NE))
  		cond = reverse_condition (cond);
  
  	      switch (cond)
*** /dev/null	Tue May  5 15:32:27 1998
--- testsuite/gcc.c-torture/execute/20010221-1.c	Wed Feb 21 21:41:39 2001
***************
*** 0 ****
--- 1,17 ----
+ 
+ int n = 2;
+ 
+ main ()
+ {
+   int i, x = 45;
+ 
+   for (i = 0; i < n; i++)
+     {
+       if (i != 0)
+ 	x = ( i > 0 ) ? i : 0;
+     }
+ 
+   if (x != 1)
+     abort ();
+   exit (0);
+ }



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