From 78183a155b833ded168e9f72055a8a0f01a5ad46 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 28 Mar 2021 13:52:38 +0200 Subject: 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 --- flow.c | 21 +++++++++++++-------- 1 file 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; -- cgit 1.2.3-korg