A phi-node is called 'trivial' if it only reference itself and a single other value. In this case the only possible value for the phi-node is this single other value which can thus replace the phi-node. However, the current code get this slightly wrong when the first referenced value is itself and not the other value. Fix this by moving up the test checking if it references itself. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- simplify.c | 4 ++-- validation/optim/trivial-phi01.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 validation/optim/trivial-phi01.c diff --git a/simplify.c b/simplify.c index de03d315ec33..5238d33f0040 100644 --- a/simplify.c +++ b/simplify.c @@ -204,14 +204,14 @@ static pseudo_t trivial_phi(pseudo_t pseudo, struct instruction *insn, struct ps src = def->phi_src; // bypass OP_PHISRC & get the real source if (src == VOID) continue; + if (src == target) + continue; if (!pseudo) { pseudo = src; continue; } if (src == pseudo) continue; - if (src == target) - continue; if (DEF_OPCODE(def, src) == OP_PHI) { if (pseudo_in_list(*list, src)) continue; diff --git a/validation/optim/trivial-phi01.c b/validation/optim/trivial-phi01.c new file mode 100644 index 000000000000..a22732e45d33 --- /dev/null +++ b/validation/optim/trivial-phi01.c @@ -0,0 +1,21 @@ +void foo(int a) +{ + if (a) { + while (a) { + switch (0) { + default: + a = 0; + case 0:; + } + } + } +} + +/* + * check-name: trivial-phi01 + * check-command: test-linearize -Wno-decl $file + * check-known-to-fail + * + * check-output-ignore + * check-output-excludes: phi\\. + */ -- 2.29.2