This is the mail archive of the gcc-bugs@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]

[Bug tree-optimization/15791] fold misses that two ADDR_EXPR of an arrary obvious not equal


------- Additional Comments From rguenth at tat dot physik dot uni-tuebingen dot de  2005-01-26 14:54 -------
Subject: Re:  fold misses that two ADDR_EXPR of
 an arrary obvious not equal

On 26 Jan 2005, pinskia at gcc dot gnu dot org wrote:

> (In reply to comment #5)
> > Could we, in general, fold  &a[i] TRUTHOP &a[j] to i TRUTHOP j?  I guess the
> > only special case would be for sizeof(a[i]) == 0 -- but that is not allowed
> > by the standard?  I'll be wading through fold tomorrow and look where to add
> > this transformation.
> sizeof(a[i]) can be zero for other languages besides C++ (C for an example).
> I gave you an hint where this can be fixed by the coment :).

Apart from this, the following should fix it (while bootstrapping I'll
search for truthcode_p() and a way to test the type size):

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.497
diff -u -r1.497 fold-const.c
--- fold-const.c	23 Jan 2005 15:05:29 -0000	1.497
+++ fold-const.c	26 Jan 2005 14:53:38 -0000
@@ -8245,6 +8245,15 @@
 				      ? code == EQ_EXPR : code != EQ_EXPR,
 				      type);

+      /* If this is a comparison of two ADDR_EXPRs of the same object
+         and the objects size is not zero, then we can fold this to
+	 a comparison of the two offsets.  */
+      if ((code == EQ_EXPR || code == NE_EXPR /* FIXME: rest */)
+	  && TREE_CODE (arg0) == ADDR_EXPR
+	  && TREE_CODE (arg1) == ADDR_EXPR
+	  && operand_equal_p (arg0, arg1, 0))
+	return fold (build2 (code, type, TREE_OPERAND (arg0, 1), TREE_OPERAND (arg1, 0)));
+
       if (FLOAT_TYPE_P (TREE_TYPE (arg0)))
 	{
 	  tree targ0 = strip_float_extensions (arg0);



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15791


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