aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-03-28 13:52:38 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2021-03-28 16:07:29 +0200
commit78183a155b833ded168e9f72055a8a0f01a5ad46 (patch)
treeb0dc9f4b34dc0de74d84b30d79c7c9c5ace1ab42
parentdcb199646134ae0d264c72175a9ad8314f7836c8 (diff)
downloadsparse-78183a155b833ded168e9f72055a8a0f01a5ad46.tar.gz
better check validity of phi-sources
Transformations made by try_to_simplify_bb() are invalid if there isn't a one-to-one correspondence between the BB's parents and the phi-sources of the phi-node(s) in the BB. This correspondence is currently checked by checking if the number of phi-sources and the number of parent are equal, but this is only an approximation. Change this check into an exact one, using the fact that BBs in the parent list and phi-sources in the phi_list are in the same order. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--flow.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/flow.c b/flow.c
index 58807432..c866dec8 100644
--- a/flow.c
+++ b/flow.c
@@ -190,19 +190,24 @@ out:
}
///
-// count the true number of argument of a phi-node
-// VOID arguments must be ignored, so pseudo_list_size() can't be used for this.
-static int phi_count(struct instruction *node)
+// check if the sources of a phi-node match with the parent BBs
+static bool phi_check(struct instruction *node)
{
+ struct basic_block *bb;
pseudo_t phi;
- int n = 0;
+ PREPARE_PTR_LIST(node->bb->parents, bb);
FOR_EACH_PTR(node->phi_list, phi) {
- if (phi == VOID)
+ if (phi == VOID || !phi->def)
continue;
- n++;
+ if (phi->def->bb != bb)
+ return false;
+ NEXT_PTR_LIST(bb);
} END_FOR_EACH_PTR(phi);
- return n;
+ if (bb)
+ return false;
+ FINISH_PTR_LIST(bb);
+ return true;
}
/*
@@ -227,7 +232,7 @@ static int try_to_simplify_bb(struct basic_block *bb, struct instruction *first,
* simplify_symbol_usage()/conversion to SSA form.
* No sane simplification can be done when we have this.
*/
- bogus = bb_list_size(bb->parents) != phi_count(first);
+ bogus = !phi_check(first);
FOR_EACH_PTR(first->phi_list, phi) {
struct instruction *def = phi->def;