[llvm] [MCA] Parameterize variant scheduling classes by explicit variable (PR #92849)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 28 07:38:15 PDT 2024
================
@@ -185,3 +188,49 @@ TEST_F(X86TestBase, TestInstructionRecycling) {
ASSERT_EQ(*BV, *V) << "Value of '" << F << "' does not match";
}
}
+
+// Test that we do not depend upon the MCInst address for variant description
+// construction. This test creates two instructions that will use variant
+// description as they are both zeroing idioms, but write to different
+// registers. If the key used to access the variant instruction description is
+// the same between the descriptions (like the MCInst pointer), we will run into
+// an assertion failure due to the different writes.
----------------
boomanaiden154 wrote:
Were you building with assertions enabled? The test would pass if assertions are not enabled. I hit an assertion with the following diff:
```patch
diff --git a/llvm/include/llvm/MCA/InstrBuilder.h b/llvm/include/llvm/MCA/InstrBuilder.h
index 9bfb8c0d2fca..e514b2afe584 100644
--- a/llvm/include/llvm/MCA/InstrBuilder.h
+++ b/llvm/include/llvm/MCA/InstrBuilder.h
@@ -74,7 +74,7 @@ class InstrBuilder {
// Key is a hash of the MCInstruction and a SchedClassID that describe the
// value InstrDesc
- DenseMap<std::pair<hash_code, unsigned>, std::unique_ptr<const InstrDesc>>
+ DenseMap<std::pair<uint64_t, unsigned>, std::unique_ptr<const InstrDesc>>
VariantDescriptors;
bool FirstCallInst;
diff --git a/llvm/lib/MCA/InstrBuilder.cpp b/llvm/lib/MCA/InstrBuilder.cpp
index 8222d4a2d8e5..0194aeece4f7 100644
--- a/llvm/lib/MCA/InstrBuilder.cpp
+++ b/llvm/lib/MCA/InstrBuilder.cpp
@@ -624,7 +624,7 @@ InstrBuilder::createInstrDescImpl(const MCInst &MCI,
return *Descriptors[DKey];
}
- auto VDKey = std::make_pair(hashMCInst(MCI), SchedClassID);
+ auto VDKey = std::make_pair(reinterpret_cast<uint64_t>(&MCI), SchedClassID);
VariantDescriptors[VDKey] = std::move(ID);
return *VariantDescriptors[VDKey];
}
@@ -641,7 +641,7 @@ InstrBuilder::getOrCreateInstrDesc(const MCInst &MCI,
unsigned CPUID = STI.getSchedModel().getProcessorID();
SchedClassID = STI.resolveVariantSchedClass(SchedClassID, &MCI, &MCII, CPUID);
- auto VDKey = std::make_pair(hashMCInst(MCI), SchedClassID);
+ auto VDKey = std::make_pair(reinterpret_cast<uint64_t>(&MCI), SchedClassID);
if (VariantDescriptors.contains(VDKey))
return *VariantDescriptors[VDKey];
```
https://github.com/llvm/llvm-project/pull/92849
More information about the llvm-commits
mailing list