* [PATCH] Fix PR68017
@ 2015-10-20 12:41 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2015-10-20 12:41 UTC (permalink / raw)
To: gcc-patches
The usual stmt removing vs. debug stmts thing.
Bootstrapped and tested on x86_64-linux-gnu, applied to trunk.
Richard.
2015-10-20 Richard Biener <rguenther@suse.de>
PR tree-optimization/68017
* tree-tailcall.c (eliminate_tail_call): Remove stmts backwards.
* gcc.dg/torture/pr68017.c: New testcase.
Index: gcc/tree-tailcall.c
===================================================================
--- gcc/tree-tailcall.c (revision 228971)
+++ gcc/tree-tailcall.c (working copy)
@@ -847,17 +847,21 @@ eliminate_tail_call (struct tailcall *t)
possibly unreachable code in other blocks is removed later in
cfg cleanup. */
gsi = t->call_gsi;
- gsi_next (&gsi);
- while (!gsi_end_p (gsi))
+ gimple_stmt_iterator gsi2 = gsi_last_bb (gimple_bb (gsi_stmt (gsi)));
+ while (gsi_stmt (gsi2) != gsi_stmt (gsi))
{
- gimple *t = gsi_stmt (gsi);
+ gimple *t = gsi_stmt (gsi2);
/* Do not remove the return statement, so that redirect_edge_and_branch
sees how the block ends. */
- if (gimple_code (t) == GIMPLE_RETURN)
- break;
-
- gsi_remove (&gsi, true);
- release_defs (t);
+ if (gimple_code (t) != GIMPLE_RETURN)
+ {
+ gimple_stmt_iterator gsi3 = gsi2;
+ gsi_prev (&gsi2);
+ gsi_remove (&gsi3, true);
+ release_defs (t);
+ }
+ else
+ gsi_prev (&gsi2);
}
/* Number of executions of function has reduced by the tailcall. */
Index: gcc/testsuite/gcc.dg/torture/pr68017.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr68017.c (revision 0)
+++ gcc/testsuite/gcc.dg/torture/pr68017.c (working copy)
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+/* { dg-options "-g" } */
+
+long long a;
+
+short
+fn1 (short p1, unsigned short p2)
+{
+ return p1 + p2;
+}
+
+short
+fn2 ()
+{
+ int b = a ? fn1 (fn2 (), a) : 0;
+ return b;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-10-20 12:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-20 12:41 [PATCH] Fix PR68017 Richard Biener
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).