From b05dcd6a9af3601d3c07d73e8b563204f0a5c69b Mon Sep 17 00:00:00 2001 From: Martien de Jong Date: Mon, 9 Dec 2024 14:54:46 +0100 Subject: [PATCH] [AIE] fix resource off-by-one glitch --- llvm/lib/Target/AIE/AIEPostPipeliner.cpp | 20 +++++++++++--------- llvm/lib/Target/AIE/AIEPostPipeliner.h | 4 ++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/llvm/lib/Target/AIE/AIEPostPipeliner.cpp b/llvm/lib/Target/AIE/AIEPostPipeliner.cpp index 645e65dfa956..3d99c7bb25e2 100644 --- a/llvm/lib/Target/AIE/AIEPostPipeliner.cpp +++ b/llvm/lib/Target/AIE/AIEPostPipeliner.cpp @@ -221,6 +221,7 @@ void PostPipeliner::computeForward() { const int NewEarliest = Me.Earliest + Dep.getSignedLatency(); SInfo.Earliest = std::max(SInfo.Earliest, NewEarliest); } + Me.Slots = getSlotCounts(*SU.getInstr(), TII); } } @@ -270,24 +271,25 @@ bool PostPipeliner::computeLoopCarriedParameters() { /* EMPTY */; } - // Adjust Earliest and Latest with resource requirements + // Adjust Earliest and Latest with resource requirements. + // FIXME: We do not account for negative latencies here. This can lead to + // suboptimality, but we only include true dependences, where negative + // latencies are rare. for (int K = 0; K < NInstr; K++) { auto &Me = Info[K]; - SlotCounts ASlots; + SlotCounts ASlots(Me.Slots); for (int A : Me.Ancestors) { - auto &SU = DAG->SUnits[A]; - ASlots += getSlotCounts(*SU.getInstr(), TII); + ASlots += Info[A].Slots; } - SlotCounts OSlots; + SlotCounts OSlots(Me.Slots); for (int O : Me.Offspring) { - auto &SU = DAG->SUnits[O]; - OSlots += getSlotCounts(*SU.getInstr(), TII); + OSlots += Info[O].Slots; } LLVM_DEBUG(dbgs() << "SU" << K << " : " << Info[K].Earliest << " - " << Info[K].Latest << " " << ASlots << " " << OSlots << "\n"); - Me.Earliest = std::max(Me.Earliest, ASlots.max()); - Me.Latest = std::min(Me.Latest, -OSlots.max()); + Me.Earliest = std::max(Me.Earliest, 0 + (ASlots.max() - 1)); + Me.Latest = std::min(Me.Latest, -1 - (OSlots.max() - 1)); LLVM_DEBUG(dbgs() << " -> " << Info[K].Earliest << " - " << Info[K].Latest << "\n"); } diff --git a/llvm/lib/Target/AIE/AIEPostPipeliner.h b/llvm/lib/Target/AIE/AIEPostPipeliner.h index e16c654dcf9e..5fa8ca8d7f49 100644 --- a/llvm/lib/Target/AIE/AIEPostPipeliner.h +++ b/llvm/lib/Target/AIE/AIEPostPipeliner.h @@ -15,6 +15,7 @@ #define LLVM_LIB_TARGET_AIE_AIEPOSTPIPELINER_H #include "AIEHazardRecognizer.h" +#include "AIESlotCounts.h" #include "llvm/CodeGen/MachineScheduler.h" #include "llvm/CodeGen/ResourceScoreboard.h" #include @@ -64,6 +65,9 @@ class NodeInfo { int StaticEarliest = 0; int StaticLatest = -1; + // Slots necessary for this instruction. + SlotCounts Slots; + // Record critical path components // The Pred/Succ that pushed my Earliest/Latest std::optional LastEarliestPusher;