Skip to content

Commit a310637

Browse files
committed
[RISCV] Disable SLP vectorization by default due to unresolved profitability issues
This change implements a TTI query with the goal of disabling slp vectorization on RISCV. The current default configuration disables SLP already, but its current tied to the ability to lower fixed length vectors. Over in D131508, I want to enable fixed length vectors for purposes of LoopVectorizer, but preliminary analysis has revealed a couple of SLP specific issues we need to resolve before enabling it by default. This change exists to allow us to enable LV without SLP. Differential Revision: https://reviews.llvm.org/D132680
1 parent 0e5813b commit a310637

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ static cl::opt<unsigned> RVVRegisterWidthLMUL(
2424
"by autovectorized code. Fractional LMULs are not supported."),
2525
cl::init(1), cl::Hidden);
2626

27+
static cl::opt<unsigned> SLPMaxVF(
28+
"riscv-v-slp-max-vf",
29+
cl::desc(
30+
"Result used for getMaximumVF query which is used exclusively by "
31+
"SLP vectorizer. Defaults to 1 which disables SLP."),
32+
cl::init(1), cl::Hidden);
33+
2734
InstructionCost RISCVTTIImpl::getIntImmCost(const APInt &Imm, Type *Ty,
2835
TTI::TargetCostKind CostKind) {
2936
assert(Ty->isIntegerTy() &&
@@ -999,3 +1006,12 @@ unsigned RISCVTTIImpl::getRegUsageForType(Type *Ty) {
9991006

10001007
return BaseT::getRegUsageForType(Ty);
10011008
}
1009+
1010+
unsigned RISCVTTIImpl::getMaximumVF(unsigned ElemWidth, unsigned Opcode) const {
1011+
// This interface is currently only used by SLP. Returning 1 (which is the
1012+
// default value for SLPMaxVF) disables SLP. We currently have a cost modeling
1013+
// problem w/ constant materialization which causes SLP to perform majorly
1014+
// unprofitable transformations.
1015+
// TODO: Figure out constant materialization cost modeling and remove.
1016+
return SLPMaxVF;
1017+
}

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class RISCVTTIImpl : public BasicTTIImplBase<RISCVTTIImpl> {
8383

8484
unsigned getRegUsageForType(Type *Ty);
8585

86+
unsigned getMaximumVF(unsigned ElemWidth, unsigned Opcode) const;
87+
8688
InstructionCost getMaskedMemoryOpCost(unsigned Opcode, Type *Src,
8789
Align Alignment, unsigned AddressSpace,
8890
TTI::TargetCostKind CostKind);

llvm/test/Transforms/SLPVectorizer/RISCV/load-store.ll

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; RUN: opt < %s -slp-vectorizer -mtriple=riscv64 -mattr=+v \
3-
; RUN: -riscv-v-vector-bits-min=-1 -S | FileCheck %s --check-prefixes=CHECK
3+
; RUN: -riscv-v-vector-bits-min=-1 -riscv-v-slp-max-vf=0 -S | FileCheck %s --check-prefixes=CHECK
4+
; RUN: opt < %s -slp-vectorizer -mtriple=riscv64 -mattr=+v -S | FileCheck %s --check-prefixes=DEFAULT
5+
46

57
define void @simple_copy(ptr %dest, ptr %p) {
68
; CHECK-LABEL: @simple_copy(
@@ -9,6 +11,16 @@ define void @simple_copy(ptr %dest, ptr %p) {
911
; CHECK-NEXT: store <2 x i16> [[TMP0]], ptr [[DEST:%.*]], align 4
1012
; CHECK-NEXT: ret void
1113
;
14+
; DEFAULT-LABEL: @simple_copy(
15+
; DEFAULT-NEXT: entry:
16+
; DEFAULT-NEXT: [[E0:%.*]] = load i16, ptr [[P:%.*]], align 4
17+
; DEFAULT-NEXT: [[INC:%.*]] = getelementptr inbounds i16, ptr [[P]], i64 1
18+
; DEFAULT-NEXT: [[E1:%.*]] = load i16, ptr [[INC]], align 2
19+
; DEFAULT-NEXT: store i16 [[E0]], ptr [[DEST:%.*]], align 4
20+
; DEFAULT-NEXT: [[INC2:%.*]] = getelementptr inbounds i16, ptr [[DEST]], i64 1
21+
; DEFAULT-NEXT: store i16 [[E1]], ptr [[INC2]], align 2
22+
; DEFAULT-NEXT: ret void
23+
;
1224
entry:
1325
%e0 = load i16, ptr %p, align 4
1426
%inc = getelementptr inbounds i16, ptr %p, i64 1
@@ -28,6 +40,18 @@ define void @vec_add(ptr %dest, ptr %p) {
2840
; CHECK-NEXT: store <2 x i16> [[TMP1]], ptr [[DEST:%.*]], align 4
2941
; CHECK-NEXT: ret void
3042
;
43+
; DEFAULT-LABEL: @vec_add(
44+
; DEFAULT-NEXT: entry:
45+
; DEFAULT-NEXT: [[E0:%.*]] = load i16, ptr [[P:%.*]], align 4
46+
; DEFAULT-NEXT: [[INC:%.*]] = getelementptr inbounds i16, ptr [[P]], i64 1
47+
; DEFAULT-NEXT: [[E1:%.*]] = load i16, ptr [[INC]], align 2
48+
; DEFAULT-NEXT: [[A0:%.*]] = add i16 [[E0]], 1
49+
; DEFAULT-NEXT: [[A1:%.*]] = add i16 [[E1]], 1
50+
; DEFAULT-NEXT: store i16 [[A0]], ptr [[DEST:%.*]], align 4
51+
; DEFAULT-NEXT: [[INC2:%.*]] = getelementptr inbounds i16, ptr [[DEST]], i64 1
52+
; DEFAULT-NEXT: store i16 [[A1]], ptr [[INC2]], align 2
53+
; DEFAULT-NEXT: ret void
54+
;
3155
entry:
3256
%e0 = load i16, ptr %p, align 4
3357
%inc = getelementptr inbounds i16, ptr %p, i64 1
@@ -52,6 +76,14 @@ define void @splat_store(ptr %dest, ptr %p) {
5276
; CHECK-NEXT: store i16 [[E0]], ptr [[INC2]], align 2
5377
; CHECK-NEXT: ret void
5478
;
79+
; DEFAULT-LABEL: @splat_store(
80+
; DEFAULT-NEXT: entry:
81+
; DEFAULT-NEXT: [[E0:%.*]] = load i16, ptr [[P:%.*]], align 4
82+
; DEFAULT-NEXT: store i16 [[E0]], ptr [[DEST:%.*]], align 4
83+
; DEFAULT-NEXT: [[INC2:%.*]] = getelementptr inbounds i16, ptr [[DEST]], i64 1
84+
; DEFAULT-NEXT: store i16 [[E0]], ptr [[INC2]], align 2
85+
; DEFAULT-NEXT: ret void
86+
;
5587
entry:
5688
%e0 = load i16, ptr %p, align 4
5789

llvm/test/Transforms/SLPVectorizer/RISCV/rvv-min-vector-size.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; RUN: opt < %s -slp-vectorizer -mtriple=riscv64 -mattr=+v \
3-
; RUN: -riscv-v-vector-bits-min=128 -S | FileCheck %s --check-prefixes=CHECK,CHECK-128
3+
; RUN: -riscv-v-vector-bits-min=128 -riscv-v-slp-max-vf=0 -S | FileCheck %s --check-prefixes=CHECK,CHECK-128
44
; RUN: opt < %s -slp-vectorizer -mtriple=riscv64 -mattr=+v \
5-
; RUN: -riscv-v-vector-bits-min=256 -S | FileCheck %s --check-prefixes=CHECK,CHECK-256
5+
; RUN: -riscv-v-vector-bits-min=256 -riscv-v-slp-max-vf=0 -S | FileCheck %s --check-prefixes=CHECK,CHECK-256
66
; RUN: opt < %s -slp-vectorizer -mtriple=riscv64 -mattr=+v \
7-
; RUN: -riscv-v-vector-bits-min=512 -S | FileCheck %s --check-prefixes=CHECK,CHECK-512
7+
; RUN: -riscv-v-vector-bits-min=512 -riscv-v-slp-max-vf=0 -S | FileCheck %s --check-prefixes=CHECK,CHECK-512
88

99
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n64-S128"
1010
target triple = "riscv64"

0 commit comments

Comments
 (0)