From 55cb4986a47acd7296c0a026bd53a507baeb03a7 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Mon, 26 Mar 2018 16:10:48 +0000 Subject: [PATCH] [Pipeliner] Fix calculation when reusing phis A schedule may require that a phi from the original loop is used in multiple iterations in the scheduled loop. When this occurs, we generate multiple phis in the pipelined loop to save the value across iterations. When we generate the new phis and update the register names in the pipelined loop, the pipeliner attempts to reuse a previously generated phi, when possible. The calculation for the name of the new phi needs to account for the version/iteration of the original phi. Also, in the epilog, the code only needs to check backwards for a previous iteration until reaching the first prolog block. Patch by Brendon Cahoon. llvm-svn: 328537 --- llvm/lib/CodeGen/MachinePipeliner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/CodeGen/MachinePipeliner.cpp b/llvm/lib/CodeGen/MachinePipeliner.cpp index 2573eaf..e968f3a 100644 --- a/llvm/lib/CodeGen/MachinePipeliner.cpp +++ b/llvm/lib/CodeGen/MachinePipeliner.cpp @@ -2730,7 +2730,7 @@ void SwingSchedulerDAG::generateExistingPhis( // references another Phi, and the other Phi is scheduled in an // earlier stage. We can try to reuse an existing Phi up until the last // stage of the current Phi. - if (LoopDefIsPhi && (int)PrologStage >= StageScheduled) { + if (LoopDefIsPhi && (int)(PrologStage - np) >= StageScheduled) { int LVNumStages = Schedule.getStagesForPhi(LoopVal); int StageDiff = (StageScheduled - LoopValStage); LVNumStages -= StageDiff; @@ -2742,8 +2742,8 @@ void SwingSchedulerDAG::generateExistingPhis( ReuseStage -= LVNumStages; // Check if the Phi to reuse has been generated yet. If not, then // there is nothing to reuse. - if (VRMap[ReuseStage].count(LoopVal)) { - NewReg = VRMap[ReuseStage][LoopVal]; + if (VRMap[ReuseStage - np].count(LoopVal)) { + NewReg = VRMap[ReuseStage - np][LoopVal]; rewriteScheduledInstr(NewBB, Schedule, InstrMap, CurStageNum, np, &*BBI, Def, NewReg); -- 2.7.4