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]

[tree-ssa] fix gcc.c-torture/execute/builtins/string-4.c


Fixes this test case by allowing 

	T.3 = (const char *)((char *)"vwxyz" + 1B);
	T.1 = stpcpy (&p + 16B, T.3);

to fold to 

	T.1 = stpcpy (&p + 16B, (const char *)"vwxyz" + 1B);



r~



        * fold-const.c (fold): Fold (T1)((T2)X op Y) into (T1)X op Y,
        for suitable values of T1 & T2.

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.213.2.49
diff -c -p -d -r1.213.2.49 fold-const.c
*** fold-const.c	6 Oct 2003 17:36:32 -0000	1.213.2.49
--- fold-const.c	6 Oct 2003 23:03:46 -0000
*************** fold (tree expr)
*** 5447,5452 ****
--- 5447,5472 ----
  				convert (TREE_TYPE (t), and1)));
  	}
  
+       /* Convert (T1)((T2)X op Y) into (T1)X op Y, for pointer types T1 and
+ 	 T2 being pointers to types of the same size.  */
+       if (POINTER_TYPE_P (TREE_TYPE (t))
+ 	  && TREE_CODE_CLASS (TREE_CODE (arg0)) == '2'
+ 	  && TREE_CODE (TREE_OPERAND (arg0, 0)) == NOP_EXPR
+ 	  && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (arg0, 0))))
+ 	{
+ 	  tree arg00 = TREE_OPERAND (arg0, 0);
+ 	  tree t0 = TREE_TYPE (t);
+ 	  tree t1 = TREE_TYPE (arg00);
+ 	  tree tt0 = TREE_TYPE (t0);
+ 	  tree tt1 = TREE_TYPE (t1);
+ 	  tree s0 = TYPE_SIZE (tt0);
+ 	  tree s1 = TYPE_SIZE (tt1);
+ 
+ 	  if (s0 && s1 && operand_equal_p (s0, s1, 1))
+ 	    return build (TREE_CODE (arg0), t0, convert (t0, arg00),
+ 		          TREE_OPERAND (arg0, 1));
+ 	}
+ 
        if (!wins)
  	{
  	  if (TREE_CONSTANT (t) != TREE_CONSTANT (arg0))


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