From 62bc00e258331aeba39f47e9fee275f4ba5b7956 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Thu, 27 Mar 2008 16:32:28 +0000 Subject: [PATCH] re PR tree-optimization/32810 (Not folding of const element for goto) 2008-03-27 Richard Guenther 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. From-SVN: r133645 --- gcc/ChangeLog | 7 +++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-18.c | 20 ++++++++++++++++++++ gcc/tree-ssa-ccp.c | 19 ++++++++++++++----- 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-18.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 337716a7356..215f0b26728 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2008-03-27 Richard Guenther + + 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. + 2008-03-27 Zdenek Dvorak * tree-affine.h (aff_combination_expand): Declare. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 42b5dcd80e9..abaed69e399 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-03-27 Richard Guenther + + PR tree-optimization/32810 + * gcc.dg/tree-ssa/ssa-ccp-18.c: New testcase. + 2008-03-27 Douglas Gregor * g++.dg/cpp0x/variadic91.C: New. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-18.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-18.c new file mode 100644 index 00000000000..cbe12598b46 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-18.c @@ -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" } } */ diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index 8dcc759eb7d..9bba5053e60 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -278,9 +278,12 @@ get_symbol_constant_value (tree sym) && !MTAG_P (sym)) { tree val = DECL_INITIAL (sym); - if (val - && is_gimple_min_invariant (val)) - return val; + 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. */ @@ -1104,7 +1107,10 @@ fold_const_aggregate_ref (tree t) /* 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; + { + STRIP_USELESS_TYPE_CONVERSION (cval); + return cval; + } break; case COMPONENT_REF: @@ -1144,7 +1150,10 @@ fold_const_aggregate_ref (tree t) if (cfield == field /* FIXME: Handle bit-fields. */ && ! DECL_BIT_FIELD (cfield)) - return cval; + { + STRIP_USELESS_TYPE_CONVERSION (cval); + return cval; + } break; case REALPART_EXPR: -- 2.30.2