From 3f72a6b7a1c616ae4f3c46b2c89a9da53fd24a51 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Mon, 26 Mar 2018 16:37:55 +0000 Subject: [Pipeliner] Fix number of phis to generate in the epilog The pipeliner was generating too many phis in the epilog blocks, which caused incorrect code generation when rewriting an instruction that uses the phi. In this case, there 3 prolog and epilog stages. An existing phi was scheduled at stage 1. When generating the code for the 2nd epilog an extra new phi was generated. To fix this, we need to update the code that calculates the maximum number of phis that can be generated, which is based upon the current prolog stage and the stage of the original phi. In this case, when the prolog stage is 1 and the original phi stage is 1, the maximum number of phis to generate is 2. Patch by Brendon Cahoon. llvm-svn: 328543 --- llvm/lib/CodeGen/MachinePipeliner.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'llvm/lib/CodeGen/MachinePipeliner.cpp') diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp index 6f3440b661d..2a438eca92e 100644 --- a/llvm/lib/CodeGen/MachinePipeliner.cpp +++ b/llvm/lib/CodeGen/MachinePipeliner.cpp @@ -2629,16 +2629,13 @@ void SwingSchedulerDAG::generateExistingPhis( VRMap[CurStageNum][Def] = VRMap[CurStageNum][LoopVal]; } // Adjust the number of Phis needed depending on the number of prologs left, - // and the distance from where the Phi is first scheduled. - unsigned NumPhis = NumStages; - if (!InKernel && (int)PrologStage < LoopValStage) - // The NumPhis is the maximum number of new Phis needed during the steady - // state. If the Phi has not been scheduled in current prolog, then we - // need to generate less Phis. - NumPhis = std::max((int)NumPhis - (int)(LoopValStage - PrologStage), 1); - // The number of Phis cannot exceed the number of prolog stages. Each - // stage can potentially define two values. - NumPhis = std::min(NumPhis, PrologStage + 2); + // and the distance from where the Phi is first scheduled. The number of + // Phis cannot exceed the number of prolog stages. Each stage can + // potentially define two values. + unsigned MaxPhis = PrologStage + 2; + if (!InKernel && (int)PrologStage <= LoopValStage) + MaxPhis = std::max((int)MaxPhis - (int)LoopValStage, 1); + unsigned NumPhis = std::min(NumStages, MaxPhis); unsigned NewReg = 0; -- cgit v1.2.3