From c8ae0bec3e2b25d5663f10ad4627d0636db316d8 Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 18 Mar 2008 14:02:17 +0000 Subject: [PATCH] tree-gimple.h (is_gimple_invariant_address): Declare. 2008-03-18 Richard Guenther * tree-gimple.h (is_gimple_invariant_address): Declare. (is_gimple_constant): Likewise. * tree-gimple.c (is_gimple_constant): New function. (is_gimple_invariant_address): Likewise. (is_gimple_min_invariant): Implement in terms of is_gimple_constant and is_gimple_invariant_address. * tree-ssa-loop-niter.c (expand_simple_operations): Revert previous change. * tree-data-ref.c (get_references_in_stmt): A SSA_NAME is not an addressable base. * gcc.dg/tree-ssa/loop-19.c: Revert previous change. From-SVN: r133311 --- gcc/ChangeLog | 13 ++++ gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/gcc.dg/tree-ssa/loop-19.c | 2 +- gcc/tree-data-ref.c | 5 +- gcc/tree-gimple.c | 89 +++++++++++++++++++++++-- gcc/tree-gimple.h | 4 ++ gcc/tree-ssa-loop-niter.c | 4 -- 7 files changed, 109 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e5706fb97bea..8004991f92c2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2008-03-18 Richard Guenther + + * tree-gimple.h (is_gimple_invariant_address): Declare. + (is_gimple_constant): Likewise. + * tree-gimple.c (is_gimple_constant): New function. + (is_gimple_invariant_address): Likewise. + (is_gimple_min_invariant): Implement in terms of is_gimple_constant + and is_gimple_invariant_address. + * tree-ssa-loop-niter.c (expand_simple_operations): Revert + previous change. + * tree-data-ref.c (get_references_in_stmt): A SSA_NAME is not + an addressable base. + 2008-03-18 Jakub Jelinek PR middle-end/35611 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 964e62f7347e..d55438305325 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2008-03-18 Richard Guenther + + * gcc.dg/tree-ssa/loop-19.c: Revert previous change. + 2008-03-17 Jerry DeLisle PR libfortran/35617 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/loop-19.c b/gcc/testsuite/gcc.dg/tree-ssa/loop-19.c index 1614f7e4de14..748c6e814349 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/loop-19.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/loop-19.c @@ -6,7 +6,7 @@ /* { dg-do compile { target i?86-*-* x86_64-*-* powerpc*-*-*} } */ /* { dg-require-effective-target nonpic } */ -/* { dg-options "-O2 -fdump-tree-final_cleanup" } */ +/* { dg-options "-O3 -fdump-tree-final_cleanup" } */ # define N 2000000 static double a[N],c[N]; diff --git a/gcc/tree-data-ref.c b/gcc/tree-data-ref.c index 70266034aab5..f8faed813c78 100644 --- a/gcc/tree-data-ref.c +++ b/gcc/tree-data-ref.c @@ -3965,11 +3965,14 @@ get_references_in_stmt (tree stmt, VEC (data_ref_loc, heap) **references) if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT) { + tree base; op0 = &GIMPLE_STMT_OPERAND (stmt, 0); op1 = &GIMPLE_STMT_OPERAND (stmt, 1); if (DECL_P (*op1) - || (REFERENCE_CLASS_P (*op1) && get_base_address (*op1))) + || (REFERENCE_CLASS_P (*op1) + && (base = get_base_address (*op1)) + && TREE_CODE (base) != SSA_NAME)) { ref = VEC_safe_push (data_ref_loc, heap, *references, NULL); ref->pos = op1; diff --git a/gcc/tree-gimple.c b/gcc/tree-gimple.c index d1e47f65edab..93e99e6cbed1 100644 --- a/gcc/tree-gimple.c +++ b/gcc/tree-gimple.c @@ -167,17 +167,13 @@ is_gimple_addressable (tree t) || INDIRECT_REF_P (t)); } -/* Return true if T is a GIMPLE minimal invariant. It's a restricted - form of function invariant. */ +/* Return true if T is a valid gimple constant. */ bool -is_gimple_min_invariant (const_tree t) +is_gimple_constant (const_tree t) { switch (TREE_CODE (t)) { - case ADDR_EXPR: - return TREE_INVARIANT (t); - case INTEGER_CST: case REAL_CST: case FIXED_CST: @@ -198,6 +194,87 @@ is_gimple_min_invariant (const_tree t) } } +/* Return true if T is a gimple invariant address. */ + +bool +is_gimple_invariant_address (const_tree t) +{ + tree op; + + if (TREE_CODE (t) != ADDR_EXPR) + return false; + + op = TREE_OPERAND (t, 0); + while (handled_component_p (op)) + { + switch (TREE_CODE (op)) + { + case ARRAY_REF: + case ARRAY_RANGE_REF: + if (!is_gimple_constant (TREE_OPERAND (op, 1)) + || TREE_OPERAND (op, 2) != NULL_TREE + || TREE_OPERAND (op, 3) != NULL_TREE) + return false; + break; + + case COMPONENT_REF: + if (TREE_OPERAND (op, 2) != NULL_TREE) + return false; + break; + + default:; + } + op = TREE_OPERAND (op, 0); + } + + if (CONSTANT_CLASS_P (op)) + return true; + + if (INDIRECT_REF_P (op)) + return false; + + switch (TREE_CODE (op)) + { + case PARM_DECL: + case RESULT_DECL: + case LABEL_DECL: + case FUNCTION_DECL: + return true; + + case VAR_DECL: + if (((TREE_STATIC (op) || DECL_EXTERNAL (op)) + && ! DECL_DLLIMPORT_P (op)) + || DECL_THREAD_LOCAL_P (op) + || DECL_CONTEXT (op) == current_function_decl + || decl_function_context (op) == current_function_decl) + return true; + break; + + case CONST_DECL: + if ((TREE_STATIC (op) || DECL_EXTERNAL (op)) + || decl_function_context (op) == current_function_decl) + return true; + break; + + default: + gcc_unreachable (); + } + + return false; +} + +/* Return true if T is a GIMPLE minimal invariant. It's a restricted + form of function invariant. */ + +bool +is_gimple_min_invariant (const_tree t) +{ + if (TREE_CODE (t) == ADDR_EXPR) + return is_gimple_invariant_address (t); + + return is_gimple_constant (t); +} + /* Return true if T looks like a valid GIMPLE statement. */ bool diff --git a/gcc/tree-gimple.h b/gcc/tree-gimple.h index 2493b6b24198..b45b44b2bde3 100644 --- a/gcc/tree-gimple.h +++ b/gcc/tree-gimple.h @@ -62,6 +62,10 @@ extern bool is_gimple_addressable (tree); /* Returns true iff T is any valid GIMPLE lvalue. */ extern bool is_gimple_lvalue (tree); +/* Returns true iff T is a GIMPLE invariant address. */ +bool is_gimple_invariant_address (const_tree); +/* Returns true iff T is a valid GIMPLE constant. */ +bool is_gimple_constant (const_tree); /* Returns true iff T is a GIMPLE restricted function invariant. */ extern bool is_gimple_min_invariant (const_tree); /* Returns true iff T is a GIMPLE rvalue. */ diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 0696342bd1b4..40e7051c265b 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -1436,10 +1436,6 @@ expand_simple_operations (tree expr) return expr; e = GIMPLE_STMT_OPERAND (stmt, 1); - /* Do not expand random invariants. */ - if (TREE_INVARIANT (e) - && !is_gimple_min_invariant (e)) - return expr; if (/* Casts are simple. */ TREE_CODE (e) != NOP_EXPR && TREE_CODE (e) != CONVERT_EXPR