From d8f2814c913847b1d0e9167dce5973eea3600c7e Mon Sep 17 00:00:00 2001 From: Hendrik Greving Date: Wed, 27 May 2020 17:12:58 -0700 Subject: [PATCH] [ModuloSchedule] Allow illegal phis to be moved across stages. Fixes a trivial but impactful bug where we did not move illegal phis across stages. This led to incorrect mappings in certain cases. --- llvm/lib/CodeGen/ModuloSchedule.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/llvm/lib/CodeGen/ModuloSchedule.cpp b/llvm/lib/CodeGen/ModuloSchedule.cpp index aa35996..a4b994b 100644 --- a/llvm/lib/CodeGen/ModuloSchedule.cpp +++ b/llvm/lib/CodeGen/ModuloSchedule.cpp @@ -1629,18 +1629,21 @@ void PeelingModuloScheduleExpander::moveStageBetweenBlocks( MachineInstr *MI = &*I++; if (MI->isPHI()) { // This is an illegal PHI. If we move any instructions using an illegal - // PHI, we need to create a legal Phi - Register PhiR = MI->getOperand(0).getReg(); - auto RC = MRI.getRegClass(PhiR); - Register NR = MRI.createVirtualRegister(RC); - MachineInstr *NI = BuildMI(*DestBB, DestBB->getFirstNonPHI(), DebugLoc(), - TII->get(TargetOpcode::PHI), NR) - .addReg(PhiR) - .addMBB(SourceBB); - BlockMIs[{DestBB, CanonicalMIs[MI]}] = NI; - CanonicalMIs[NI] = CanonicalMIs[MI]; - Remaps[PhiR] = NR; - continue; + // PHI, we need to create a legal Phi. + if (getStage(MI) != Stage) { + // The legal Phi is not necessary if the illegal phi's stage + // is being moved. + Register PhiR = MI->getOperand(0).getReg(); + auto RC = MRI.getRegClass(PhiR); + Register NR = MRI.createVirtualRegister(RC); + MachineInstr *NI = BuildMI(*DestBB, DestBB->getFirstNonPHI(), + DebugLoc(), TII->get(TargetOpcode::PHI), NR) + .addReg(PhiR) + .addMBB(SourceBB); + BlockMIs[{DestBB, CanonicalMIs[MI]}] = NI; + CanonicalMIs[NI] = CanonicalMIs[MI]; + Remaps[PhiR] = NR; + } } if (getStage(MI) != Stage) continue; -- 2.7.4