From 7b5cc7b6135733cbbce121cc94fdc4a5400f46b5 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Fri, 19 Feb 2021 07:25:33 +0100 Subject: fix phisources during SWITCH-BR conversion Like for CBR-BR conversion, when a target BB containing one or several phi-nodes is removed from an OP_SWITCH, the corresponding phi-source must be removed from the phi-node. However this is not done yet. Changing this by adding some code to convert_to_jump() to remove all phi-sources from the discarded targets if the converted instruction is an OP_SWITCH. Signed-off-by: Luc Van Oostenryck --- flow.c | 20 ++++++++++++++++++++ validation/optim/bad-phisrc3.c | 1 - 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/flow.c b/flow.c index 69d95a98..cb94fcf2 100644 --- a/flow.c +++ b/flow.c @@ -65,6 +65,23 @@ next: ; return changed; } +/// +// remove all phisources but the one corresponding to the given target +static int remove_other_phisources(struct basic_block *bb, struct multijmp_list *list, struct basic_block *target) +{ + struct multijmp *jmp; + int changed = 0; + + FOR_EACH_PTR(list, jmp) { + if (jmp->target == target) { + target = NULL; + continue; + } + changed |= remove_phisources(bb, jmp->target); + } END_FOR_EACH_PTR(jmp); + return changed; +} + /* * Dammit, if we have a phi-node followed by a conditional * branch on that phi-node, we should damn well be able to @@ -764,6 +781,9 @@ int convert_to_jump(struct instruction *insn, struct basic_block *target) case OP_CBR: changed |= remove_phisources(insn->bb, insn->bb_true == target ? insn->bb_false : insn->bb_true); break; + case OP_SWITCH: + changed |= remove_other_phisources(insn->bb, insn->multijmp_list, target); + break; } kill_use(&insn->cond); insn->bb_true = target; diff --git a/validation/optim/bad-phisrc3.c b/validation/optim/bad-phisrc3.c index 6e437771..41537420 100644 --- a/validation/optim/bad-phisrc3.c +++ b/validation/optim/bad-phisrc3.c @@ -13,7 +13,6 @@ void foo(void) /* * check-name: bad-phisrc3 * check-command: test-linearize -Wno-decl $file - * check-known-to-fail * * check-output-ignore * check-output-pattern(2): phisrc\\. -- cgit 1.2.3-korg