From a999669982d0cedacbb7371c96fce95682d582e1 Mon Sep 17 00:00:00 2001 From: Valery Pykhtin Date: Thu, 27 Oct 2022 08:55:16 +0200 Subject: [PATCH] [AMDGPU] Scheduler: fix RP calculation for a MBB with one successor We reuse live registers after tracking one MBB as live-ins to the successor MBB if the successor is only one but we don't check if the successor has other predecessors. `A B` ` \ /` ` C` A and B have one successor but C has live-ins defined by A and B and therefore should be initialized using LIS. This fixes 83 lit tests out if 420 with EXPENSIVE_CHECK enabled. Reviewed By: rampitec Differential Revision: https://reviews.llvm.org/D136918 --- llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp index f9c58e8..7f7d6e5 100644 --- a/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp +++ b/llvm/lib/Target/AMDGPU/GCNSchedStrategy.cpp @@ -511,11 +511,19 @@ void GCNScheduleDAGMILive::computeBlockPressure(unsigned RegionIdx, // If the block has the only successor then live-ins of that successor are // live-outs of the current block. We can reuse calculated live set if the // successor will be sent to scheduling past current block. + + // However, due to the bug in LiveInterval analysis it may happen that two + // predecessors of the same successor block have different lane bitmasks for + // a live-out register. Workaround that by sticking to one-to-one relationship + // i.e. one predecessor with one successor block. const MachineBasicBlock *OnlySucc = nullptr; - if (MBB->succ_size() == 1 && !(*MBB->succ_begin())->empty()) { - SlotIndexes *Ind = LIS->getSlotIndexes(); - if (Ind->getMBBStartIdx(MBB) < Ind->getMBBStartIdx(*MBB->succ_begin())) - OnlySucc = *MBB->succ_begin(); + if (MBB->succ_size() == 1) { + auto *Candidate = *MBB->succ_begin(); + if (!Candidate->empty() && Candidate->pred_size() == 1) { + SlotIndexes *Ind = LIS->getSlotIndexes(); + if (Ind->getMBBStartIdx(MBB) < Ind->getMBBStartIdx(Candidate)) + OnlySucc = Candidate; + } } // Scheduler sends regions from the end of the block upwards. -- 2.7.4