Skip to content

Commit 58f1640

Browse files
[RISCV][llvm-mca] Use correct LMUL and SEW for strided loads and stores (#76869)
The pseudos for strided loads and stores use the SEW coming from the name. For example, vlse8 has SEW=8 and vlse16 has SEW=16. When llvm-mca tries to lookup (VLSE8_V, SEW=S, LMUL=L) in the inverse pseudo table, a result will only be found when S=8, where S was set from the previous vsetvli instruction. Instead, for a match to be found, we must lookup (VLSE8_V, SEW=8, LMUL=L') where L' is the EMUL which was calculated by scaling the LMUL and SEW from the previous vsetvli and the SEW=8.
1 parent 2ab5c47 commit 58f1640

File tree

2 files changed

+385
-9
lines changed

2 files changed

+385
-9
lines changed

llvm/lib/Target/RISCV/MCA/RISCVCustomBehaviour.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,30 +186,37 @@ RISCVInstrumentManager::createInstruments(const MCInst &Inst) {
186186
}
187187

188188
static std::pair<uint8_t, uint8_t>
189-
getEEWAndEMULForUnitStrideLoadStore(unsigned Opcode, RISCVII::VLMUL LMUL,
190-
uint8_t SEW) {
189+
getEEWAndEMUL(unsigned Opcode, RISCVII::VLMUL LMUL, uint8_t SEW) {
191190
uint8_t EEW;
192191
switch (Opcode) {
193192
case RISCV::VLM_V:
194193
case RISCV::VSM_V:
195194
case RISCV::VLE8_V:
196195
case RISCV::VSE8_V:
196+
case RISCV::VLSE8_V:
197+
case RISCV::VSSE8_V:
197198
EEW = 8;
198199
break;
199200
case RISCV::VLE16_V:
200201
case RISCV::VSE16_V:
202+
case RISCV::VLSE16_V:
203+
case RISCV::VSSE16_V:
201204
EEW = 16;
202205
break;
203206
case RISCV::VLE32_V:
204207
case RISCV::VSE32_V:
208+
case RISCV::VLSE32_V:
209+
case RISCV::VSSE32_V:
205210
EEW = 32;
206211
break;
207212
case RISCV::VLE64_V:
208213
case RISCV::VSE64_V:
214+
case RISCV::VLSE64_V:
215+
case RISCV::VSSE64_V:
209216
EEW = 64;
210217
break;
211218
default:
212-
llvm_unreachable("Opcode is not a vector unit stride load nor store");
219+
llvm_unreachable("Could not determine EEW from Opcode");
213220
}
214221

215222
auto EMUL = RISCVVType::getSameRatioLMUL(SEW, LMUL, EEW);
@@ -218,6 +225,18 @@ getEEWAndEMULForUnitStrideLoadStore(unsigned Opcode, RISCVII::VLMUL LMUL,
218225
return std::make_pair(EEW, *EMUL);
219226
}
220227

228+
bool opcodeHasEEWAndEMULInfo(unsigned short Opcode) {
229+
return Opcode == RISCV::VLM_V || Opcode == RISCV::VSM_V ||
230+
Opcode == RISCV::VLE8_V || Opcode == RISCV::VSE8_V ||
231+
Opcode == RISCV::VLE16_V || Opcode == RISCV::VSE16_V ||
232+
Opcode == RISCV::VLE32_V || Opcode == RISCV::VSE32_V ||
233+
Opcode == RISCV::VLE64_V || Opcode == RISCV::VSE64_V ||
234+
Opcode == RISCV::VLSE8_V || Opcode == RISCV::VSSE8_V ||
235+
Opcode == RISCV::VLSE16_V || Opcode == RISCV::VSSE16_V ||
236+
Opcode == RISCV::VLSE32_V || Opcode == RISCV::VSSE32_V ||
237+
Opcode == RISCV::VLSE64_V || Opcode == RISCV::VSSE64_V;
238+
}
239+
221240
unsigned RISCVInstrumentManager::getSchedClassID(
222241
const MCInstrInfo &MCII, const MCInst &MCI,
223242
const llvm::SmallVector<Instrument *> &IVec) const {
@@ -249,13 +268,9 @@ unsigned RISCVInstrumentManager::getSchedClassID(
249268
uint8_t SEW = SI ? SI->getSEW() : 0;
250269

251270
const RISCVVInversePseudosTable::PseudoInfo *RVV = nullptr;
252-
if (Opcode == RISCV::VLM_V || Opcode == RISCV::VSM_V ||
253-
Opcode == RISCV::VLE8_V || Opcode == RISCV::VSE8_V ||
254-
Opcode == RISCV::VLE16_V || Opcode == RISCV::VSE16_V ||
255-
Opcode == RISCV::VLE32_V || Opcode == RISCV::VSE32_V ||
256-
Opcode == RISCV::VLE64_V || Opcode == RISCV::VSE64_V) {
271+
if (opcodeHasEEWAndEMULInfo(Opcode)) {
257272
RISCVII::VLMUL VLMUL = static_cast<RISCVII::VLMUL>(LMUL);
258-
auto [EEW, EMUL] = getEEWAndEMULForUnitStrideLoadStore(Opcode, VLMUL, SEW);
273+
auto [EEW, EMUL] = getEEWAndEMUL(Opcode, VLMUL, SEW);
259274
RVV = RISCVVInversePseudosTable::getBaseInfo(Opcode, EMUL, EEW);
260275
} else {
261276
// Check if it depends on LMUL and SEW

0 commit comments

Comments
 (0)