Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CodeGenSchedule] Don't allow invalid ReadAdvances to be formed (#82685) #13

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions llvm/lib/Target/AArch64/AArch64SchedExynosM4.td
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ def M4WriteFMAC3H : SchedWriteRes<[M4UnitFMACH]> { let Latency = 3; }
def M4WriteFMAC3 : SchedWriteRes<[M4UnitFMAC]> { let Latency = 3; }
def M4WriteFMAC4 : SchedWriteRes<[M4UnitFMAC]> { let Latency = 4; }
def M4WriteFMAC4H : SchedWriteRes<[M4UnitFMACH]> { let Latency = 4; }
def M4WriteFMAC5 : SchedWriteRes<[M4UnitFMAC]> { let Latency = 5; }

def M4WriteFSQR7H : SchedWriteRes<[M4UnitFSQRH]> { let Latency = 7;
let ReleaseAtCycles = [6]; }
Expand Down Expand Up @@ -495,8 +494,7 @@ def M4WriteMOVI : SchedWriteVariant<[SchedVar<IsZeroFPIdiomPred, [M4WriteZ0]>
// Fast forwarding.
def M4ReadAESM1 : SchedReadAdvance<+1, [M4WriteNCRY1]>;
def M4ReadFMACM1 : SchedReadAdvance<+1, [M4WriteFMAC4,
M4WriteFMAC4H,
M4WriteFMAC5]>;
M4WriteFMAC4H]>;
def M4ReadNMULM1 : SchedReadAdvance<+1, [M4WriteNMUL3]>;
def M4ReadNMULP2 : SchedReadAdvance<-2, [M4WriteNMUL3]>;

Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/Target/AArch64/AArch64SchedExynosM5.td
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ def M5WriteFDIV12 : SchedWriteRes<[M5UnitFDIV]> { let Latency = 12;

def M5WriteFMAC3 : SchedWriteRes<[M5UnitFMAC]> { let Latency = 3; }
def M5WriteFMAC4 : SchedWriteRes<[M5UnitFMAC]> { let Latency = 4; }
def M5WriteFMAC5 : SchedWriteRes<[M5UnitFMAC]> { let Latency = 5; }

def M5WriteFSQR5 : SchedWriteRes<[M5UnitFSQR]> { let Latency = 5;
let ReleaseAtCycles = [2]; }
Expand Down Expand Up @@ -530,8 +529,7 @@ def M5WriteMOVI : SchedWriteVariant<[SchedVar<IsZeroFPIdiomPred, [M5WriteZ0]>
// Fast forwarding.
def M5ReadFM1 : SchedReadAdvance<+1, [M5WriteF2]>;
def M5ReadAESM2 : SchedReadAdvance<+2, [M5WriteNCRY2]>;
def M5ReadFMACM1 : SchedReadAdvance<+1, [M5WriteFMAC4,
M5WriteFMAC5]>;
def M5ReadFMACM1 : SchedReadAdvance<+1, [M5WriteFMAC4]>;
def M5ReadNMULM1 : SchedReadAdvance<+1, [M5WriteNMUL3]>;

//===----------------------------------------------------------------------===//
Expand Down
29 changes: 29 additions & 0 deletions llvm/test/TableGen/ReadAdvanceInvalidWrite.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: not llvm-tblgen -gen-subtarget -I %p/../../include %s 2>&1 | FileCheck %s

// Make sure we don't form ReadAdvances with ValidWrites entries that are not
// associated with any instructions.

include "llvm/Target/Target.td"

def TargetX : Target;

def WriteX : SchedWrite;
def WriteY : SchedWrite;
def ReadX : SchedRead;

def InstX : Instruction {
let OutOperandList = (outs);
let InOperandList = (ins);
let SchedRW = [WriteX, ReadX];
}

def SchedModelX: SchedMachineModel {
let CompleteModel = 0;
}

let SchedModel = SchedModelX in {
def : ReadAdvance<ReadX, 1, [WriteX, WriteY]>;
// CHECK: error: ReadAdvance referencing a ValidWrite that is not used by any instruction (WriteY)
}

def ProcessorX: ProcessorModel<"ProcessorX", SchedModelX, []>;
12 changes: 6 additions & 6 deletions llvm/test/tools/llvm-mca/AArch64/Exynos/float-divide-multiply.s
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ fsqrt d11, d12
# EM3-NEXT: Total uOps: 800

# EM4-NEXT: Instructions: 1200
# EM4-NEXT: Total Cycles: 575
# EM4-NEXT: Total Cycles: 572
# EM4-NEXT: Total uOps: 1200

# EM5-NEXT: Instructions: 1200
# EM5-NEXT: Total Cycles: 433
# EM5-NEXT: Total Cycles: 434
# EM5-NEXT: Total uOps: 1200

# ALL: Dispatch Width: 6
Expand All @@ -39,12 +39,12 @@ fsqrt d11, d12
# EM3-NEXT: IPC: 0.18
# EM3-NEXT: Block RThroughput: 45.0

# EM4-NEXT: uOps Per Cycle: 2.09
# EM4-NEXT: IPC: 2.09
# EM4-NEXT: uOps Per Cycle: 2.10
# EM4-NEXT: IPC: 2.10
# EM4-NEXT: Block RThroughput: 4.0

# EM5-NEXT: uOps Per Cycle: 2.77
# EM5-NEXT: IPC: 2.77
# EM5-NEXT: uOps Per Cycle: 2.76
# EM5-NEXT: IPC: 2.76
# EM5-NEXT: Block RThroughput: 4.0

# ALL: Instruction Info:
Expand Down
9 changes: 9 additions & 0 deletions llvm/utils/TableGen/CodeGenSchedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,15 @@ void CodeGenSchedModels::addWriteRes(Record *ProcWriteResDef, unsigned PIdx) {
// Add resources for a ReadAdvance to this processor if they don't exist.
void CodeGenSchedModels::addReadAdvance(Record *ProcReadAdvanceDef,
unsigned PIdx) {
for (const Record *ValidWrite :
ProcReadAdvanceDef->getValueAsListOfDefs("ValidWrites"))
if (getSchedRWIdx(ValidWrite, /*IsRead=*/false) == 0)
PrintFatalError(
ProcReadAdvanceDef->getLoc(),
"ReadAdvance referencing a ValidWrite that is not used by "
"any instruction (" +
ValidWrite->getName() + ")");

RecVec &RADefs = ProcModels[PIdx].ReadAdvanceDefs;
if (is_contained(RADefs, ProcReadAdvanceDef))
return;
Expand Down
5 changes: 4 additions & 1 deletion llvm/utils/TableGen/SubtargetEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,10 @@ void SubtargetEmitter::GenSchedClassTables(const CodeGenProcModel &ProcModel,
WriteIDs.push_back(0);
else {
for (Record *VW : ValidWrites) {
WriteIDs.push_back(SchedModels.getSchedRWIdx(VW, /*IsRead=*/false));
unsigned WriteID = SchedModels.getSchedRWIdx(VW, /*IsRead=*/false);
assert(WriteID != 0 &&
"Expected a valid SchedRW in the list of ValidWrites");
WriteIDs.push_back(WriteID);
}
}
llvm::sort(WriteIDs);
Expand Down