Skip to content

Commit 3a62693

Browse files
authored
[RISCV][TTI] Extract subvector at index zero is free (llvm#81751)
Extracing a subvector at index zero corresponds to a type conversion and possibly a subregister operation. We will not emit a vslidedown. As such, they are free. As an aside, it looks like we're not passing an index in for cases where the subvec type is scalable. For at least index zero, we probably should be.
1 parent 630548a commit 3a62693

File tree

3 files changed

+42
-38
lines changed

3 files changed

+42
-38
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind,
432432
// must be implemented here.
433433
break;
434434
case TTI::SK_ExtractSubvector:
435+
// Extract at zero is always a subregister extract
436+
if (Index == 0)
437+
return TTI::TCC_Free;
438+
435439
// Example sequence:
436440
// vsetivli zero, 4, e8, mf2, tu, ma (ignored)
437441
// vslidedown.vi v8, v9, 2

llvm/test/Analysis/CostModel/RISCV/rvv-shuffle.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ define void @vector_broadcast() {
5252

5353
define void @vector_insert_extract(<vscale x 4 x i32> %v0, <vscale x 16 x i32> %v1, <16 x i32> %v2) {
5454
; CHECK-LABEL: 'vector_insert_extract'
55-
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %extract_fixed_from_scalable = call <16 x i32> @llvm.vector.extract.v16i32.nxv4i32(<vscale x 4 x i32> %v0, i64 0)
55+
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %extract_fixed_from_scalable = call <16 x i32> @llvm.vector.extract.v16i32.nxv4i32(<vscale x 4 x i32> %v0, i64 0)
5656
; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: %insert_fixed_into_scalable = call <vscale x 4 x i32> @llvm.vector.insert.nxv4i32.v16i32(<vscale x 4 x i32> %v0, <16 x i32> %v2, i64 0)
5757
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %extract_scalable_from_scalable = call <vscale x 4 x i32> @llvm.vector.extract.nxv4i32.nxv16i32(<vscale x 16 x i32> %v1, i64 0)
5858
; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %insert_scalable_into_scalable = call <vscale x 16 x i32> @llvm.vector.insert.nxv16i32.nxv4i32(<vscale x 16 x i32> %v1, <vscale x 4 x i32> %v0, i64 0)
5959
; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: ret void
6060
;
6161
; SIZE-LABEL: 'vector_insert_extract'
62-
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %extract_fixed_from_scalable = call <16 x i32> @llvm.vector.extract.v16i32.nxv4i32(<vscale x 4 x i32> %v0, i64 0)
62+
; SIZE-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %extract_fixed_from_scalable = call <16 x i32> @llvm.vector.extract.v16i32.nxv4i32(<vscale x 4 x i32> %v0, i64 0)
6363
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %insert_fixed_into_scalable = call <vscale x 4 x i32> @llvm.vector.insert.nxv4i32.v16i32(<vscale x 4 x i32> %v0, <16 x i32> %v2, i64 0)
6464
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %extract_scalable_from_scalable = call <vscale x 4 x i32> @llvm.vector.extract.nxv4i32.nxv16i32(<vscale x 16 x i32> %v1, i64 0)
6565
; SIZE-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %insert_scalable_into_scalable = call <vscale x 16 x i32> @llvm.vector.insert.nxv16i32.nxv4i32(<vscale x 16 x i32> %v1, <vscale x 4 x i32> %v0, i64 0)

0 commit comments

Comments
 (0)