This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa][attn: fortran] propagate addresses of local variables
- From: Richard Henderson <rth at redhat dot com>
- To: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- Cc: Richard Henderson <rth at twiddle dot net>, gcc-patches at gcc dot gnu dot org
- Date: Sun, 12 Oct 2003 16:19:10 -0700
- Subject: Re: [tree-ssa][attn: fortran] propagate addresses of local variables
- References: <20031012203554.GA18348@twiddle.net> <3F89C54E.6070204@moene.indiv.nluug.nl>
On Sun, Oct 12, 2003 at 11:19:10PM +0200, Toon Moene wrote:
> Richard Henderson wrote:
> ../../gcc/gcc/tree-cfg.c: In function `build_tree_cfg':
> ../../gcc/gcc/tree-cfg.c:225: internal compiler error: tree check:
> expected class `t', have `d' (field_decl) in fold_indirect_refs_r, at
> trees-ssa-ccp.c:1574
Argh! I should have known better. A last minute change that
"could only affect fortran", didn't. Sigh.
While indeed fortran is the only language (in tree-ssa) that
supports non-zero array base indicies, it seems C doesn't fill
in the minimum index sometimes. That seems like a bug...
Still re-bootstrapping from scratch, but I think this'll do.
r~
* gimplify.c (gimplify_array_ref_to_plus): Be prepared for
null TYPE_DOMAIN or TYPE_MIN_VALUE for the array.
* tree-ssa-ccp.c (fold_indirect_refs_r): Likewise.
Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.91
diff -u -p -r1.1.2.91 gimplify.c
--- gimplify.c 12 Oct 2003 19:43:32 -0000 1.1.2.91
+++ gimplify.c 12 Oct 2003 23:09:33 -0000
@@ -1349,16 +1349,20 @@ gimplify_array_ref_to_plus (tree *expr_p
tree elttype = TREE_TYPE (arrtype);
tree size = size_in_bytes (elttype);
tree ptrtype = build_pointer_type (elttype);
- tree minidx = TYPE_MIN_VALUE (TYPE_DOMAIN (arrtype));
enum tree_code add_code = PLUS_EXPR;
tree idx = TREE_OPERAND (*expr_p, 1);
- tree offset, addr, result;
+ tree minidx, offset, addr, result;
/* If the array domain does not start at zero, apply the offset. */
- if (!integer_zerop (minidx))
+ minidx = TYPE_DOMAIN (arrtype);
+ if (minidx)
{
- idx = convert (TREE_TYPE (minidx), idx);
- idx = fold (build (MINUS_EXPR, TREE_TYPE (minidx), idx, minidx));
+ minidx = TYPE_MIN_VALUE (minidx);
+ if (minidx && !integer_zerop (minidx))
+ {
+ idx = convert (TREE_TYPE (minidx), idx);
+ idx = fold (build (MINUS_EXPR, TREE_TYPE (minidx), idx, minidx));
+ }
}
/* If the index is negative -- a technically invalid situation now
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.100
diff -u -p -r1.1.2.100 tree-ssa-ccp.c
--- tree-ssa-ccp.c 12 Oct 2003 19:43:33 -0000 1.1.2.100
+++ tree-ssa-ccp.c 12 Oct 2003 23:09:35 -0000
@@ -1570,8 +1570,14 @@ fold_indirect_refs_r (tree *expr_p, int
if (TREE_CODE (TREE_TYPE (base)) == ARRAY_TYPE
&& (TYPE_MAIN_VARIANT (TREE_TYPE (expr))
== TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (base)))))
- t = build (ARRAY_REF, TREE_TYPE (expr), base,
- TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (expr))));
+ {
+ t = TYPE_DOMAIN (TREE_TYPE (base));
+ if (t)
+ t = TYPE_MIN_VALUE (t);
+ if (!t)
+ t = offset;
+ t = build (ARRAY_REF, TREE_TYPE (expr), base, t);
+ }
else
t = base;
}
@@ -1605,10 +1611,18 @@ fold_indirect_refs_r (tree *expr_p, int
idx = build_int_2_wide (lquo, hquo);
/* Re-bias the index by the min index of the array type. */
- min_idx = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (base)));
- idx = convert (TREE_TYPE (min_idx), idx);
- if (!integer_zerop (min_idx))
- idx = fold (build (PLUS_EXPR, TREE_TYPE (min_idx), idx, min_idx));
+ min_idx = TYPE_DOMAIN (TREE_TYPE (base));
+ if (min_idx)
+ {
+ min_idx = TYPE_MIN_VALUE (min_idx);
+ if (min_idx)
+ {
+ idx = convert (TREE_TYPE (min_idx), idx);
+ if (!integer_zerop (min_idx))
+ idx = fold (build (PLUS_EXPR, TREE_TYPE (min_idx),
+ idx, min_idx));
+ }
+ }
t = build (ARRAY_REF, TREE_TYPE (expr), base, idx);
}