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] Fix PR38359, wrong folding of -1 >> x


This fixes an ICE during CCP where we run into the issue that const_binop
folds differently than fold_binary for -1 >> -130 vs. -1 >> n.  Fixed
by making sure we fold -1 >> x to -1 only if x is non-negative.

Bootstrap/regtest running on x86_64-unknown-linux-gnu, I'll commit after
that succeeded.

Richard.

2008-12-02  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/38359
	* fold-const.c (fold_binary): Fold -1 >> x to -1 only for
	non-negative x.

	* gcc.c-torture/compile/pr38359.c: New testcase.

Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c	(revision 142317)
--- gcc/fold-const.c	(working copy)
*************** fold_binary (enum tree_code code, tree t
*** 11457,11463 ****
  
      case RSHIFT_EXPR:
        /* Optimize -1 >> x for arithmetic right shifts.  */
!       if (integer_all_onesp (arg0) && !TYPE_UNSIGNED (type))
  	return omit_one_operand (type, arg0, arg1);
        /* ... fall through ...  */
  
--- 11457,11464 ----
  
      case RSHIFT_EXPR:
        /* Optimize -1 >> x for arithmetic right shifts.  */
!       if (integer_all_onesp (arg0) && !TYPE_UNSIGNED (type)
! 	  && tree_expr_nonnegative_p (arg1))
  	return omit_one_operand (type, arg0, arg1);
        /* ... fall through ...  */
  
Index: gcc/testsuite/gcc.c-torture/compile/pr38359.c
===================================================================
*** gcc/testsuite/gcc.c-torture/compile/pr38359.c	(revision 0)
--- gcc/testsuite/gcc.c-torture/compile/pr38359.c	(revision 0)
***************
*** 0 ****
--- 1,17 ----
+ unsigned _ov_64_seek_lap (_Bool x1, _Bool x2, _Bool x3)
+ {
+   unsigned ltmp_3978_7__PHI_TEMPORARY;
+   signed ltmp_4011_7;
+ 
+   if (!x1 || !x2)
+     while (1) ;
+ 
+   if (x3)
+     ltmp_3978_7__PHI_TEMPORARY = 0xffffff7e;
+   else
+     ltmp_3978_7__PHI_TEMPORARY = 1;
+ 
+   ltmp_4011_7 = -1;
+   return ltmp_4011_7 >> ltmp_3978_7__PHI_TEMPORARY;
+ }
+ 


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