This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] Improve gimplification/dominator optimizations
- From: law at redhat dot com
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 11 Aug 2003 11:16:17 -0600
- Subject: [tree-ssa] Improve gimplification/dominator optimizations
- Reply-to: law at redhat dot com
This patch fixes 20030708-1.c and 20030807-5.c.
In simplest terms, if we have something like
result = foo->code;
[ ... ]
result2 = foo->code;
Where "foo" is in static memory, addressable, or for some other reason is
not SSA renamed, then we will never detect the redundant load of ->code.
To expose the redundant load we rewrite that into
temp.1 = foo;
result = temp.1->code;
[ ... ]
temp.2 = foo;
result2 = temp.2->code;
Which is more easily optimized into
temp.1 = foo;
result = temp.1->code
[ ... ]
result2 = result;
* gimplify.c (gimplify_expr, case INDIRECT_REF): Copy the base
object into a temporary if it's in static memory or is addressable.
Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.68
diff -c -3 -p -r1.1.2.68 gimplify.c
*** gimplify.c 8 Aug 2003 23:15:56 -0000 1.1.2.68
--- gimplify.c 11 Aug 2003 16:23:49 -0000
*************** gimplify_expr (tree *expr_p, tree *pre_p
*** 499,504 ****
--- 499,517 ----
case INDIRECT_REF:
gimplify_expr (&TREE_OPERAND (*expr_p, 0), pre_p, post_p,
is_gimple_id, fb_rvalue);
+
+ /* If we are indirecting a variable in memory, load the
+ variable into a temporary and indirect the temporary. */
+ tmp = TREE_OPERAND (*expr_p, 0);
+ if (DECL_P (tmp)
+ && (decl_function_context (tmp) == NULL
+ || TREE_STATIC (tmp)
+ || TREE_ADDRESSABLE (tmp)))
+ {
+ tmp = get_formal_tmp_var (tmp, pre_p);
+ TREE_OPERAND (*expr_p, 0) = tmp;
+ }
+
recalculate_side_effects (*expr_p);
break;