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 to combine for simplify_comparision()


Hi Guys,

  Here is a little patch for your approval.  It fixes a bug in the
  combiner when it determines that it can replace a left shift
  followed by a comparision with an constant integer value with a
  comparision with the same value right shifted instead.  The bug was
  that the shifted value of the constant was being computed using a
  signed shift, when it should have been an unsigend shift.

  I have also included a new test case which reproduces this bug.  (At
  least it does for the thumb, I have not tried other toolchains).

Cheers
	Nick


Thu Sep 23 11:42:11 1999  Nick Clifton  <nickc@cygnus.com>

	* combine.c (simplify_comparison): Use an unsigned shift to adjust
	the constant.

Index: combine.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/combine.c,v
retrieving revision 1.77
diff -p -r1.77 combine.c
*** combine.c	1999/09/20 10:05:21	1.77
--- combine.c	1999/09/23 10:57:01
*************** simplify_comparison (code, pop0, pop1)
*** 10362,10369 ****
  		  & ~ (mask >> (INTVAL (XEXP (op0, 1))
  				+ ! equality_comparison_p))) == 0)
  	    {
! 	      const_op >>= INTVAL (XEXP (op0, 1));
! 	      op1 = GEN_INT (const_op);
  	      op0 = XEXP (op0, 0);
  	      continue;
  	    }
--- 10362,10371 ----
  		  & ~ (mask >> (INTVAL (XEXP (op0, 1))
  				+ ! equality_comparison_p))) == 0)
  	    {
! 	      unsigned HOST_WIDE_INT foo = const_op;
! 	      
! 	      foo >>= INTVAL (XEXP (op0, 1));
! 	      op1 = GEN_INT (foo);
  	      op0 = XEXP (op0, 0);
  	      continue;
  	    }

1999-09-23  Nick Clifton  <nickc@cygnus.com>

	* execute/990923-1.c: New test.


Index: testsuite/gcc.c-torture/execute/990923-1.c
===================================================================
RCS file: 990923-1.c
diff -N 990923-1.c
*** /dev/null	Sat Dec  5 20:30:03 1998
--- 990923-1.c	Thu Sep 23 04:03:12 1999
***************
*** 0 ****
--- 1,19 ----
+ #define mask  0xffff0000
+ #define value 0xabcd0000
+ 
+ short 
+ foo (int x)
+ {
+   if ((x & mask) == value)
+     return (short) x;
+   return 1;
+ }
+ 
+ int 
+ main (void)
+ {
+   if (foo (value) != 0 || foo (0) != 1)
+     abort ();
+   
+   exit (0);
+ }


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