[PATCH] Fix PR32810, missed CCP with array of label addresses

Richard Guenther rguenther@suse.de
Thu Mar 27 16:48:00 GMT 2008


This fixes the mentioned PR where CCP is confused by (void *) casts
in the constant initializer.  Fixed thus.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2008-03-27  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/32810
	* tree-ssa-ccp.c (get_symbol_constant_value): Strip useless
	conversions from DECL_INITIAL.
	(fold_const_aggregate_ref): Likewise from constructor elements.

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

Index: tree-ssa-ccp.c
===================================================================
*** tree-ssa-ccp.c	(revision 133613)
--- tree-ssa-ccp.c	(working copy)
*************** get_symbol_constant_value (tree sym)
*** 278,286 ****
        && !MTAG_P (sym))
      {
        tree val = DECL_INITIAL (sym);
!       if (val
! 	  && is_gimple_min_invariant (val))
! 	return val;
        /* Variables declared 'const' without an initializer
  	 have zero as the intializer if they may not be
  	 overridden at link or run time.  */
--- 278,289 ----
        && !MTAG_P (sym))
      {
        tree val = DECL_INITIAL (sym);
!       if (val)
! 	{
! 	  STRIP_USELESS_TYPE_CONVERSION (val);
! 	  if (is_gimple_min_invariant (val))
! 	    return val;
! 	}
        /* Variables declared 'const' without an initializer
  	 have zero as the intializer if they may not be
  	 overridden at link or run time.  */
*************** fold_const_aggregate_ref (tree t)
*** 1104,1110 ****
        /* Whoo-hoo!  I'll fold ya baby.  Yeah!  */
        FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), cnt, cfield, cval)
  	if (tree_int_cst_equal (cfield, idx))
! 	  return cval;
        break;
  
      case COMPONENT_REF:
--- 1107,1116 ----
        /* Whoo-hoo!  I'll fold ya baby.  Yeah!  */
        FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), cnt, cfield, cval)
  	if (tree_int_cst_equal (cfield, idx))
! 	  {
! 	    STRIP_USELESS_TYPE_CONVERSION (cval);
! 	    return cval;
! 	  }
        break;
  
      case COMPONENT_REF:
*************** fold_const_aggregate_ref (tree t)
*** 1144,1150 ****
  	if (cfield == field
  	    /* FIXME: Handle bit-fields.  */
  	    && ! DECL_BIT_FIELD (cfield))
! 	  return cval;
        break;
  
      case REALPART_EXPR:
--- 1150,1159 ----
  	if (cfield == field
  	    /* FIXME: Handle bit-fields.  */
  	    && ! DECL_BIT_FIELD (cfield))
! 	  {
! 	    STRIP_USELESS_TYPE_CONVERSION (cval);
! 	    return cval;
! 	  }
        break;
  
      case REALPART_EXPR:
Index: testsuite/gcc.dg/tree-ssa/ssa-ccp-18.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/ssa-ccp-18.c	(revision 0)
--- testsuite/gcc.dg/tree-ssa/ssa-ccp-18.c	(revision 0)
***************
*** 0 ****
--- 1,20 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-ccp1" } */
+ 
+ /* Check that we constant propagate &&c into the goto and remove
+    the unreachable BBs.  */
+ 
+ void a(int*);  void b(int*);  void c(int*);  void d(int*);
+ void func2(int* val)
+ {
+   const void *const labels[] = { &&a, &&b, &&c, &&d };
+   goto *labels[2];
+   a: a(val);
+   b: b(val);
+   c: c(val);
+   d: d(val);
+ }
+ 
+ /* { dg-final { scan-tree-dump-not "a \\\(" "ccp1" } } */
+ /* { dg-final { scan-tree-dump-not "b \\\(" "ccp1" } } */
+ /* { dg-final { cleanup-tree-dump "ccp1" } } */



More information about the Gcc-patches mailing list