From 74676da6f122bd7abfd2ba47c5291bc9092cee55 Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Fri, 13 Dec 2002 11:55:59 +0000 Subject: [PATCH] Need to insert all moves due to PHI nodes before *ALL* jumps in a predecessor basic block, as there could be multiple. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5016 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/RegAllocSimple.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/CodeGen/RegAllocSimple.cpp b/lib/CodeGen/RegAllocSimple.cpp index 3a58b5abeed..6def3a178ad 100644 --- a/lib/CodeGen/RegAllocSimple.cpp +++ b/lib/CodeGen/RegAllocSimple.cpp @@ -92,21 +92,6 @@ namespace { regs = Desc.ImplicitDefs; while (*regs) RegsUsed[*regs++] = 1; - - - /* - for (int i = MI->getNumOperands() - 1; i >= 0; --i) { - const MachineOperand &op = MI->getOperand(i); - if (op.isMachineRegister()) - RegsUsed[op.getAllocatedRegNum()] = 1; - } - - for (int i = MI->getNumImplicitRefs() - 1; i >= 0; --i) { - const MachineOperand &op = MI->getImplicitOp(i); - if (op.isMachineRegister()) - RegsUsed[op.getAllocatedRegNum()] = 1; - } - */ } void cleanupAfterFunction() { @@ -297,6 +282,16 @@ bool RegAllocSimple::runOnMachineFunction(MachineFunction &Fn) { MachineBasicBlock::iterator opI = opBlock->end(); MachineInstr *opMI = *(--opI); const MachineInstrInfo &MII = TM.getInstrInfo(); + // must backtrack over ALL the branches in the previous block, until no more + while ((MII.isBranch(opMI->getOpcode()) || MII.isReturn(opMI->getOpcode())) + && opI != opBlock->begin()) + { + opMI = *(--opI); + } + // move back to the first branch instruction so new instructions + // are inserted right in front of it and not in front of a non-branch + ++opI; + // insert the move just before the return/branch if (MII.isReturn(opMI->getOpcode()) || MII.isBranch(opMI->getOpcode())) -- 2.34.1