Skip to content

Commit f037e70

Browse files
preameslukel97
andauthored
[RISCV][TTI] Cost a subvector extract at a register boundary with exact vlen (#82405)
If we have exact vlen knowledge, we can figure out which indices correspond to register boundaries. Our lowering uses this knowledge to replace the vslidedown.vi with a sub-register extract. Our costs can reflect that as well. This is another piece split off #80164 --------- Co-authored-by: Luke Lau <[email protected]>
1 parent b49f155 commit f037e70

File tree

2 files changed

+245
-0
lines changed

2 files changed

+245
-0
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,22 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
436436
if (Index == 0)
437437
return TTI::TCC_Free;
438438

439+
// If we're extracting a subvector of at most m1 size at a sub-register
440+
// boundary - which unfortunately we need exact vlen to identify - this is
441+
// a subregister extract at worst and thus won't require a vslidedown.
442+
// TODO: Extend for aligned m2, m4 subvector extracts
443+
// TODO: Extend for misalgined (but contained) extracts
444+
// TODO: Extend for scalable subvector types
445+
if (std::pair<InstructionCost, MVT> SubLT = getTypeLegalizationCost(SubTp);
446+
SubLT.second.isValid() && SubLT.second.isFixedLengthVector()) {
447+
const unsigned MinVLen = ST->getRealMinVLen();
448+
const unsigned MaxVLen = ST->getRealMaxVLen();
449+
if (MinVLen == MaxVLen &&
450+
SubLT.second.getScalarSizeInBits() * Index % MinVLen == 0 &&
451+
SubLT.second.getSizeInBits() <= MinVLen)
452+
return TTI::TCC_Free;
453+
}
454+
439455
// Example sequence:
440456
// vsetivli zero, 4, e8, mf2, tu, ma (ignored)
441457
// vslidedown.vi v8, v9, 2

0 commit comments

Comments
 (0)