gimplify.c (gimplify_expr): Don't replace with DECL_INITIAL if fb_lvalue.

* gimplify.c (gimplify_expr) <case CONST_DECL>: 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 <Cxxx>.
        * 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
This commit is contained in:
Richard Henderson 2004-07-30 15:55:30 -07:00 committed by Richard Henderson
parent 782700d4f2
commit 0534fa5652
10 changed files with 61 additions and 12 deletions

View File

@ -1,3 +1,12 @@
2004-07-30 Richard Henderson <rth@redhat.com>
* gimplify.c (gimplify_expr) <case CONST_DECL>: 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 <Cxxx>.
* tree-ssa-ccp.c (maybe_fold_stmt_indirect): Fold CONST_DECL.
2004-07-30 Diego Novillo <dnovillo@redhat.com>
* tree-ssa-alias.c (compute_points_to_and_addr_escape): If a

View File

@ -1,3 +1,8 @@
2004-07-30 Richard Henderson <rth@redhat.com>
* trans-expr.c (gfc_conv_expr_reference): Create a CONST_DECL
for TREE_CONSTANTs.
2004-07-25 Richard Henderson <rth@redhat.com>
* trans-decl.c (gfc_build_function_decl): Set DECL_ARTIFICIAL

View File

@ -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. */

View File

@ -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:

View File

@ -1,3 +1,9 @@
2004-07-30 Richard Henderson <rth@redhat.com>
* 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 <rth@redhat.com>
* gfortran.fortran-torture/execute/intrinsic_nearest.f90: Disable

View File

@ -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)

View File

@ -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

View File

@ -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);
}

View File

@ -165,7 +165,10 @@ dump_decl_name (pretty_printer *buffer, tree node, int flags)
pp_printf (buffer, "<L" HOST_WIDE_INT_PRINT_DEC ">",
LABEL_DECL_UID (node));
else
pp_printf (buffer, "<D%u>", DECL_UID (node));
{
char c = TREE_CODE (node) == CONST_DECL ? 'C' : 'D';
pp_printf (buffer, "<%c%u>", c, DECL_UID (node));
}
}
}

View File

@ -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)