Skip to content

Commit 31ec413

Browse files
committed
tree-optimization/110924 - fix vop liveness for noreturn const CFG parts
The virtual operand live problem used by sinking assumes we have virtual uses at each end point of the CFG but as shown in the PR this isn't true for parts for example ending in __builtin_unreachable. The following removes the optimization made possible by this and now requires marking backedges. PR tree-optimization/110924 * tree-ssa-live.h (virtual_operand_live): Update comment. * tree-ssa-live.cc (virtual_operand_live::get_live_in): Remove optimization, look at each predecessor. * tree-ssa-sink.cc (pass_sink_code::execute): Mark backedges. * gcc.dg/torture/pr110924.c: New testcase.
1 parent 25c4b16 commit 31ec413

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* { dg-do compile } */
2+
3+
int a[1], b, c, d, e, f, g;
4+
void h(int i, int j) {
5+
int *k = 0;
6+
if (*k)
7+
h(0, 0);
8+
g = i && d;
9+
}
10+
int main() {
11+
if (c)
12+
goto l;
13+
if (!a)
14+
while (1) {
15+
f = 1;
16+
while (f)
17+
h(b && main(), e);
18+
while (1)
19+
;
20+
l:;
21+
}
22+
return 0;
23+
}

gcc/tree-ssa-live.cc

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,23 +1676,27 @@ virtual_operand_live::get_live_in (basic_block bb)
16761676
if (!liveout)
16771677
init ();
16781678

1679-
/* Since we don't have a virtual PHI we can now pick any of the
1680-
incoming edges liveout value. All returns from the function have
1681-
a virtual use forcing generation of virtual PHIs. */
1679+
/* Since we don't have a virtual PHI and we don't know whether there's
1680+
a downstream virtual use (and thus PHIs are inserted where necessary)
1681+
we now have to check each incoming edge live-out. */
16821682
edge_iterator ei;
16831683
edge e;
1684+
tree livein = NULL_TREE;
16841685
FOR_EACH_EDGE (e, ei, bb->preds)
1685-
if (liveout[e->src->index])
1686-
{
1687-
if (EDGE_PRED (bb, 0) != e)
1688-
liveout[EDGE_PRED (bb, 0)->src->index] = liveout[e->src->index];
1689-
return liveout[e->src->index];
1690-
}
1691-
1692-
/* Since virtuals are in SSA form at most the immediate dominator can
1693-
contain the definition of the live version. Skipping to that deals
1694-
with CFG cycles as well. */
1695-
return get_live_out (get_immediate_dominator (CDI_DOMINATORS, bb));
1686+
if (e->flags & EDGE_DFS_BACK)
1687+
/* We can ignore backedges since if there's a def there it would
1688+
have forced a PHI in the source because it also acts as use
1689+
downstream. */
1690+
continue;
1691+
else if (!livein)
1692+
livein = get_live_out (e->src);
1693+
else if (get_live_out (e->src) != livein)
1694+
/* When there's no virtual use downstream this indicates a point
1695+
where we'd insert a PHI merging the different live virtual
1696+
operands. */
1697+
return NULL_TREE;
1698+
1699+
return livein;
16961700
}
16971701

16981702
/* Compute live-out of BB. */

gcc/tree-ssa-live.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ make_live_on_entry (tree_live_info_p live, basic_block bb , int p)
332332
/* On-demand virtual operand global live analysis. There is at most
333333
a single virtual operand live at a time, the following computes and
334334
caches the virtual operand live at the exit of a basic block
335-
supporting related live-in and live-on-edge queries. */
335+
supporting related live-in and live-on-edge queries. It requires
336+
up-to-date marked backedges. */
336337

337338
class virtual_operand_live
338339
{

gcc/tree-ssa-sink.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ pass_sink_code::execute (function *fun)
822822
/* Arrange for the critical edge splitting to be undone if requested. */
823823
unsigned todo = unsplit_edges ? TODO_cleanup_cfg : 0;
824824
connect_infinite_loops_to_exit ();
825+
mark_dfs_back_edges (fun);
825826
memset (&sink_stats, 0, sizeof (sink_stats));
826827
calculate_dominance_info (CDI_DOMINATORS);
827828

0 commit comments

Comments
 (0)