From bfa65168e27005b685e6085ee1f3a0a10a7cd01e Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 29 Oct 2016 10:55:48 +0200 Subject: [PATCH] Don't generate phis if unnecessary (because this breaks the critical-edge-splitting guarantee and causes insertion of phi copies to fail). --- mach/proto/mcg/pass_convertstackops.c | 30 ++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/mach/proto/mcg/pass_convertstackops.c b/mach/proto/mcg/pass_convertstackops.c index 59290d376..49da42226 100644 --- a/mach/proto/mcg/pass_convertstackops.c +++ b/mach/proto/mcg/pass_convertstackops.c @@ -95,15 +95,31 @@ static void convert_block(struct basicblock* bb) { struct basicblock* outbb = pops.item[i].left; struct ir* ir = pops.item[i].right; - struct ir* phi = new_ir0(IR_PHI, ir->size); - for (j=0; ju.phivalue, - pushes.item[j].left, - pushes.item[j].right); - phi->root = phi; + assert(pushes.count > 0); + if (pushes.count == 1) + { + /* The push happened in exactly one place; that means we don't need a phi and can + * just import the value directly. */ - *ir = *phi; + struct ir* src = pushes.item[0].right; + ir->opcode = IR_NOP; + ir->left = src; + } + else + { + /* The push could have happened in one of several places; we need a phi. */ + + struct ir* phi = new_ir0(IR_PHI, ir->size); + for (j=0; ju.phivalue, + pushes.item[j].left, + pushes.item[j].right); + } + phi->root = phi; + *ir = *phi; + } } } } -- 2.34.1