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]

[Committed] PR opt/14669: Unwidening integer comparisons


I've approved and committed to mainline, Kazu Hirata's patch to resolve
PR optimization/14669 as attached to that PR in bugzilla.  Many thanks
also to Eric Botcazou (and the Ada folks) for analyzing the conditions
on which this transformation was safe.

The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all languages except treelang, and regression tested
with a top-level "make -k check" with no new failures.


2004-03-23  Kazu Hirata  <kazu@cs.umass.edu>

	PR optimization/14669
	* fold-const.c (fold): Only unwiden integer comparisons for equality
	or inequality operators, or when the signedness is the same.

	* g++.dg/opt/fold2.C: New test case.


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.354
diff -c -3 -p -r1.354 fold-const.c
*** fold-const.c	20 Mar 2004 22:12:17 -0000	1.354
--- fold-const.c	22 Mar 2004 18:29:14 -0000
*************** fold (tree expr)
*** 7546,7551 ****
--- 7546,7554 ----
        else if (TREE_CODE (TREE_TYPE (arg0)) == INTEGER_TYPE
  	       && TREE_CODE (arg0) == NOP_EXPR
  	       && (tem = get_unwidened (arg0, NULL_TREE)) != arg0
+ 	       && (code == EQ_EXPR || code == NE_EXPR
+ 		   || TREE_UNSIGNED (TREE_TYPE (arg0))
+ 		      == TREE_UNSIGNED (TREE_TYPE (tem)))
  	       && (t1 = get_unwidened (arg1, TREE_TYPE (tem))) != 0
  	       && (TREE_TYPE (t1) == TREE_TYPE (tem)
  		   || (TREE_CODE (t1) == INTEGER_CST


// PR optimization/14669
// { dg-do run }
// { dg-options "-O2" }

extern "C" void abort (void);
extern "C" void exit (int);

enum ActionType { EE=-1, E0=0, E1, E2 };

int main(void)
{
  ActionType t = E0;

  if (E1 <= t && t <= E2)
    abort ();

  exit (0);
}


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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