[PATCH] Fix PR27743

Richard Guenther rguenther@suse.de
Wed May 24 14:28:00 GMT 2006


This fixes PR27743, a wrong-code 4.1/4.2 regression wrt combining shifts.

Bootstrapped and regtested on ia64-unknown-linux-gnu.

Ok for mainline and 4.1.2?

Thanks,
Richard.

:ADDPATCH middle-end:

2006-05-24  Richard Guenther  <rguenther@suse.de>

	PR middle-end/27743
	* fold-const.c (fold_binary): Do not look at the stripped
	op0 for (a OP c1) OP c2 to a OP (c1+c2) shift optimization.

	* gcc.dg/torture/pr27743.c: New testcase.

Index: fold-const.c
===================================================================
*** fold-const.c	(revision 114040)
--- fold-const.c	(working copy)
*************** fold_binary (enum tree_code code, tree t
*** 9786,9792 ****
  	return NULL_TREE;
  
        /* Turn (a OP c1) OP c2 into a OP (c1+c2).  */
!       if (TREE_CODE (arg0) == code && host_integerp (arg1, false)
  	  && TREE_INT_CST_LOW (arg1) < TYPE_PRECISION (type)
  	  && host_integerp (TREE_OPERAND (arg0, 1), false)
  	  && TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)) < TYPE_PRECISION (type))
--- 9786,9792 ----
  	return NULL_TREE;
  
        /* Turn (a OP c1) OP c2 into a OP (c1+c2).  */
!       if (TREE_CODE (op0) == code && host_integerp (arg1, false)
  	  && TREE_INT_CST_LOW (arg1) < TYPE_PRECISION (type)
  	  && host_integerp (TREE_OPERAND (arg0, 1), false)
  	  && TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)) < TYPE_PRECISION (type))
Index: testsuite/gcc.dg/torture/pr27743.c
===================================================================
*** testsuite/gcc.dg/torture/pr27743.c	(revision 0)
--- testsuite/gcc.dg/torture/pr27743.c	(revision 0)
***************
*** 0 ****
--- 1,15 ----
+ /* { dg-do run } */
+ 
+ extern void abort(void);
+ 
+ int bar(int a)
+ {
+   return ((unsigned) ((a) >> 2)) >> 15;
+ }
+ 
+ int main()
+ {
+   if (bar (0xffff3000) != 0x1ffff)
+     abort ();
+   return 0;
+ }



More information about the Gcc-patches mailing list