This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] gimplify PHI args during inlining substitution (PR tree-optimization/33458)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 5 Nov 2007 10:29:59 -0500
- Subject: [PATCH] gimplify PHI args during inlining substitution (PR tree-optimization/33458)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
As shown on the attached testcase on x86_64-linux -m32, tree-inline.c
substitutions during inlining can create non-GIMPLE PHI arguments, if
e.g. TREE_INVARIANT &<result> is replaced by something else.
In copy_bb the code already copes with that:
/* With return slot optimization we can end up with
non-gimple (foo *)&this->m, fix that here. */
if (TREE_CODE (stmt) == GIMPLE_MODIFY_STMT
&& TREE_CODE (GIMPLE_STMT_OPERAND (stmt, 1)) == NOP_EXPR
&& !is_gimple_val (TREE_OPERAND (GIMPLE_STMT_OPERAND (stmt, 1), 0)))
gimplify_stmt (&stmt);
but copy_phis_for_bb did not.
Tested on x86_64-linux, ok for trunk?
2007-11-05 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/33458
* tree-inline.c (copy_phis_for_bb): If PHI arg substitution creates
!is_gimple_val PHI argument, gimplify it and insert it on edge.
* g++.dg/opt/inline12.C: New test.
--- gcc/tree-inline.c.jj 2007-11-05 15:36:28.000000000 +0100
+++ gcc/tree-inline.c 2007-11-05 15:34:47.000000000 +0100
@@ -1193,6 +1193,17 @@ copy_phis_for_bb (basic_block bb, copy_b
walk_tree (&new_arg, copy_body_r, id, NULL);
gcc_assert (new_arg);
+ /* With return slot optimization we can end up with
+ non-gimple (foo *)&this->m, fix that here. */
+ if (TREE_CODE (new_arg) != SSA_NAME
+ && TREE_CODE (new_arg) != FUNCTION_DECL
+ && !is_gimple_val (new_arg))
+ {
+ tree stmts = NULL_TREE;
+ new_arg = force_gimple_operand (new_arg, &stmts,
+ true, NULL);
+ bsi_insert_on_edge_immediate (new_edge, stmts);
+ }
add_phi_arg (new_phi, new_arg, new_edge);
}
}
--- gcc/testsuite/g++.dg/opt/inline12.C.jj 2007-11-05 15:57:21.000000000 +0100
+++ gcc/testsuite/g++.dg/opt/inline12.C 2007-11-05 15:56:46.000000000 +0100
@@ -0,0 +1,32 @@
+// PR tree-optimization/33458
+// { dg-do compile }
+// { dg-options "-O" }
+
+inline void
+foo (int *p, int n)
+{
+ for (; n > 0; --n, ++p)
+ *p = 0;
+}
+
+struct A
+{
+ int x[2];
+ A () { foo (x, 2); }
+};
+
+inline A
+getA ()
+{
+ return A ();
+}
+
+struct B
+{
+ A a;
+ B ();
+};
+
+B::B () : a (getA ())
+{
+}
Jakub