From 0534fa565255cf56d5771ea92522403947d4bbd4 Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Fri, 30 Jul 2004 15:55:30 -0700 Subject: [PATCH] gimplify.c (gimplify_expr): Don't replace with DECL_INITIAL if fb_lvalue. * gimplify.c (gimplify_expr) : Don't replace with DECL_INITIAL if fb_lvalue. * tree-gimple.c (is_gimple_id): Add CONST_DECL. * tree-pretty-print.c (dump_decl_name): Dump unnamed CONST_DECL with . * tree-ssa-ccp.c (maybe_fold_stmt_indirect): Fold CONST_DECL. fortran/ * trans-expr.c (gfc_conv_expr_reference): Create a CONST_DECL for TREE_CONSTANTs. testsuite/ * gfortran.fortran-torture/execute/intrinsic_rrspacing.f90: Fix write to constant argument. * gfortran.fortran-torture/execute/intrinsic_scale.f90: Likewise. From-SVN: r85365 --- gcc/ChangeLog | 9 +++++++++ gcc/fortran/ChangeLog | 5 +++++ gcc/fortran/trans-expr.c | 13 +++++++++++-- gcc/gimplify.c | 9 ++++++++- gcc/testsuite/ChangeLog | 6 ++++++ .../execute/intrinsic_rrspacing.f90 | 10 ++++++---- .../execute/intrinsic_scale.f90 | 10 ++++++---- gcc/tree-gimple.c | 1 + gcc/tree-pretty-print.c | 5 ++++- gcc/tree-ssa-ccp.c | 5 +++++ 10 files changed, 61 insertions(+), 12 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b36cc87ae2f..e46f01bd706 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2004-07-30 Richard Henderson + + * gimplify.c (gimplify_expr) : Don't replace + with DECL_INITIAL if fb_lvalue. + * tree-gimple.c (is_gimple_id): Add CONST_DECL. + * tree-pretty-print.c (dump_decl_name): Dump unnamed CONST_DECL + with . + * tree-ssa-ccp.c (maybe_fold_stmt_indirect): Fold CONST_DECL. + 2004-07-30 Diego Novillo * tree-ssa-alias.c (compute_points_to_and_addr_escape): If a diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 1e0d825cf68..677342764c3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2004-07-30 Richard Henderson + + * trans-expr.c (gfc_conv_expr_reference): Create a CONST_DECL + for TREE_CONSTANTs. + 2004-07-25 Richard Henderson * trans-decl.c (gfc_build_function_decl): Set DECL_ARTIFICIAL diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index 4745f0cc3be..81d879e5dde 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -1612,8 +1612,17 @@ gfc_conv_expr_reference (gfc_se * se, gfc_expr * expr) gfc_conv_expr (se, expr); /* Create a temporary var to hold the value. */ - var = gfc_create_var (TREE_TYPE (se->expr), NULL); - gfc_add_modify_expr (&se->pre, var, se->expr); + if (TREE_CONSTANT (se->expr)) + { + var = build_decl (CONST_DECL, NULL, TREE_TYPE (se->expr)); + DECL_INITIAL (var) = se->expr; + pushdecl (var); + } + else + { + var = gfc_create_var (TREE_TYPE (se->expr), NULL); + gfc_add_modify_expr (&se->pre, var, se->expr); + } gfc_add_block_to_block (&se->pre, &se->post); /* Take the address of that value. */ diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 304a20b1082..53cf1feac32 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -3576,7 +3576,14 @@ gimplify_expr (tree *expr_p, tree *pre_p, tree *post_p, break; case CONST_DECL: - *expr_p = DECL_INITIAL (*expr_p); + /* If we require an lvalue, such as for ADDR_EXPR, retain the + CONST_DECL node. Otherwise the decl is replacable by its + value. */ + /* ??? Should be == fb_lvalue, but ADDR_EXPR passes fb_either. */ + if (fallback & fb_lvalue) + ret = GS_ALL_DONE; + else + *expr_p = DECL_INITIAL (*expr_p); break; case DECL_EXPR: diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index aaa540cc2bd..7280c2da478 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2004-07-30 Richard Henderson + + * gfortran.fortran-torture/execute/intrinsic_rrspacing.f90: Fix + write to constant argument. + * gfortran.fortran-torture/execute/intrinsic_scale.f90: Likewise. + 2004-07-30 Richard Henderson * gfortran.fortran-torture/execute/intrinsic_nearest.f90: Disable diff --git a/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_rrspacing.f90 b/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_rrspacing.f90 index 0f411a633b2..e74cf6494fc 100644 --- a/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_rrspacing.f90 +++ b/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_rrspacing.f90 @@ -8,18 +8,20 @@ program test_rrspacing call test_real8(33.0_8) call test_real8(-33.0_8) end -subroutine test_real4(x) - real x,y +subroutine test_real4(orig) + real x,y,orig integer p + x = orig p = 24 y = abs (x * 2.0 ** (- exponent (x))) * (2.0 ** p) x = rrspacing(x) if (abs (x - y) .gt. abs(x * 1e-6)) call abort end -subroutine test_real8(x) - real*8 x,y,t +subroutine test_real8(orig) + real*8 x,y,t,orig integer p + x = orig p = 53 y = abs (x * 2.0 ** (- exponent (x))) * (2.0 ** p) x = rrspacing(x) diff --git a/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_scale.f90 b/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_scale.f90 index 09acda5261c..775c4d7b4b5 100644 --- a/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_scale.f90 +++ b/gcc/testsuite/gfortran.fortran-torture/execute/intrinsic_scale.f90 @@ -10,17 +10,19 @@ program test_scale call test_real8 (33.0_8, -4) call test_real8 (-33._8, 4) end -subroutine test_real4 (x, i) - real x,y +subroutine test_real4 (orig, i) + real x,y,orig integer i + x = orig y = x * (2.0 ** i) x = scale (x, i) if (abs (x - y) .gt. abs(x * 1e-6)) call abort end -subroutine test_real8 (x, i) - real*8 x,y +subroutine test_real8 (orig, i) + real*8 x,y,orig integer i + x = orig y = x * (2.0 ** i) x = scale (x, i) if (abs (x - y) .gt. abs(x * 1e-6)) call abort diff --git a/gcc/tree-gimple.c b/gcc/tree-gimple.c index 4f26a084fc0..413395ae531 100644 --- a/gcc/tree-gimple.c +++ b/gcc/tree-gimple.c @@ -413,6 +413,7 @@ is_gimple_id (tree t) return (is_gimple_variable (t) || TREE_CODE (t) == FUNCTION_DECL || TREE_CODE (t) == LABEL_DECL + || TREE_CODE (t) == CONST_DECL /* Allow string constants, since they are addressable. */ || TREE_CODE (t) == STRING_CST); } diff --git a/gcc/tree-pretty-print.c b/gcc/tree-pretty-print.c index d1479e4869d..a3a3a01d75e 100644 --- a/gcc/tree-pretty-print.c +++ b/gcc/tree-pretty-print.c @@ -165,7 +165,10 @@ dump_decl_name (pretty_printer *buffer, tree node, int flags) pp_printf (buffer, "", LABEL_DECL_UID (node)); else - pp_printf (buffer, "", DECL_UID (node)); + { + char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D'; + pp_printf (buffer, "<%c%u>", c, DECL_UID (node)); + } } } diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index c8ab92a896b..f883e373cc4 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -1868,6 +1868,11 @@ maybe_fold_stmt_indirect (tree expr, tree base, tree offset) /* Strip the ADDR_EXPR. */ base = TREE_OPERAND (base, 0); + /* Fold away CONST_DECL to its value, if the type is scalar. */ + if (TREE_CODE (base) == CONST_DECL + && is_gimple_min_invariant (DECL_INITIAL (base))) + return DECL_INITIAL (base); + /* Try folding *(&B+O) to B[X]. */ t = maybe_fold_offset_to_array_ref (base, offset, TREE_TYPE (expr)); if (t) -- 2.30.2