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 PR44748


CCP when folding possibly constant MEM_REF refs wasn't honoring the
embedded conversion when dispatching to get_symbol_constant_value.

Fixed as follows, bootstrap and regtest running on 
x86_64-unknown-linux-gnu.  Will apply when that succeeded and the
freeze is over.

Richard.

2010-07-01  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/44748
	* tree-ssa-ccp.c (fold_const_aggregate_ref): Properly handle
	the embedded conversion in MEM_REFs.

	* gcc.dg/tree-ssa/ssa-ccp-29.c: New testcase.

Index: gcc/tree-ssa-ccp.c
===================================================================
*** gcc/tree-ssa-ccp.c	(revision 161672)
--- gcc/tree-ssa-ccp.c	(working copy)
*************** fold_const_aggregate_ref (tree t)
*** 1317,1323 ****
  	  if (DECL_P (base)
  	      && !AGGREGATE_TYPE_P (TREE_TYPE (base))
  	      && integer_zerop (TREE_OPERAND (t, 1)))
! 	    return get_symbol_constant_value (base);
  
  	  if (!TREE_READONLY (base)
  	      || TREE_CODE (TREE_TYPE (base)) != ARRAY_TYPE
--- 1317,1330 ----
  	  if (DECL_P (base)
  	      && !AGGREGATE_TYPE_P (TREE_TYPE (base))
  	      && integer_zerop (TREE_OPERAND (t, 1)))
! 	    {
! 	      tree res = get_symbol_constant_value (base);
! 	      if (res
! 		  && !useless_type_conversion_p
! 		        (TREE_TYPE (t), TREE_TYPE (res)))
! 		res = fold_unary (VIEW_CONVERT_EXPR, TREE_TYPE (t), res);
! 	      return res;
! 	    }
  
  	  if (!TREE_READONLY (base)
  	      || TREE_CODE (TREE_TYPE (base)) != ARRAY_TYPE
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-29.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-29.c	(revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-29.c	(revision 0)
***************
*** 0 ****
--- 1,11 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-ccp2" } */
+ 
+ static double num;
+ int foo (void)
+ {
+   return *(unsigned *)&num;
+ }
+ 
+ /* { dg-final { scan-tree-dump "return 0;" "ccp2" } } */
+ /* { dg-final { cleanup-tree-dump "ccp2" } } */


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