public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] gimplify PHI args during inlining substitution (PR tree-optimization/33458)
@ 2007-11-05 15:30 Jakub Jelinek
  2007-11-05 22:00 ` Richard Guenther
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2007-11-05 15:30 UTC (permalink / raw)
  To: gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gimplify PHI args during inlining substitution (PR tree-optimization/33458)
  2007-11-05 15:30 [PATCH] gimplify PHI args during inlining substitution (PR tree-optimization/33458) Jakub Jelinek
@ 2007-11-05 22:00 ` Richard Guenther
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Guenther @ 2007-11-05 22:00 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On 11/5/07, Jakub Jelinek <jakub@redhat.com> wrote:
> 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?

Ok.

Thanks,
Richard.

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-11-05 22:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-05 15:30 [PATCH] gimplify PHI args during inlining substitution (PR tree-optimization/33458) Jakub Jelinek
2007-11-05 22:00 ` Richard Guenther

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).