diff --git a/llvm/lib/Target/RISCV/RISCVSubtarget.cpp b/llvm/lib/Target/RISCV/RISCVSubtarget.cpp --- a/llvm/lib/Target/RISCV/RISCVSubtarget.cpp +++ b/llvm/lib/Target/RISCV/RISCVSubtarget.cpp @@ -28,16 +28,18 @@ #define GET_SUBTARGETINFO_CTOR #include "RISCVGenSubtargetInfo.inc" -static cl::opt RVVVectorBitsMax( +static cl::opt RVVVectorBitsMax( "riscv-v-vector-bits-max", cl::desc("Assume V extension vector registers are at most this big, " "with zero meaning no maximum size is assumed."), cl::init(0), cl::Hidden); -static cl::opt RVVVectorBitsMin( +static cl::opt RVVVectorBitsMin( "riscv-v-vector-bits-min", cl::desc("Assume V extension vector registers are at least this big, " - "with zero meaning no minimum size is assumed."), + "with zero meaning no minimum size is assumed. A value of -1 " + "means use Zvl*b extension. This is primarily used to enable " + "autovectorization with fixed width vectors."), cl::init(0), cl::Hidden); static cl::opt RVVVectorLMULMax( @@ -136,7 +138,7 @@ // ZvlLen specifies the minimum required vlen. The upper bound provided by // riscv-v-vector-bits-max should be no less than it. - if (RVVVectorBitsMax < ZvlLen) + if (RVVVectorBitsMax < (int)ZvlLen) report_fatal_error("riscv-v-vector-bits-max specified is lower " "than the Zvl*b limitation"); @@ -154,14 +156,18 @@ } unsigned RISCVSubtarget::getMinRVVVectorSizeInBits() const { + assert(hasVInstructions() && + "Tried to get vector length without Zve or V extension support!"); + + if (RVVVectorBitsMin == -1) + return ZvlLen; + // ZvlLen specifies the minimum required vlen. The lower bound provided by // riscv-v-vector-bits-min should be no less than it. - if (RVVVectorBitsMin != 0 && RVVVectorBitsMin < ZvlLen) + if (RVVVectorBitsMin != 0 && RVVVectorBitsMin < (int)ZvlLen) report_fatal_error("riscv-v-vector-bits-min specified is lower " "than the Zvl*b limitation"); - assert(hasVInstructions() && - "Tried to get vector length without Zve or V extension support!"); // FIXME: Change to >= 32 when VLEN = 32 is supported assert( (RVVVectorBitsMin == 0 || diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll --- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll +++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll @@ -3,6 +3,8 @@ ; RUN: llc -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-min=128 -riscv-v-fixed-length-vector-lmul-max=2 -verify-machineinstrs < %s | FileCheck %s --check-prefixes=CHECK,RV64,LMULMAX2,LMULMAX2-RV64 ; RUN: llc -mtriple=riscv32 -mattr=+v -riscv-v-vector-bits-min=128 -riscv-v-fixed-length-vector-lmul-max=1 -verify-machineinstrs < %s | FileCheck %s --check-prefixes=CHECK,RV32,LMULMAX1,LMULMAX1-RV32 ; RUN: llc -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-min=128 -riscv-v-fixed-length-vector-lmul-max=1 -verify-machineinstrs < %s | FileCheck %s --check-prefixes=CHECK,RV64,LMULMAX1,LMULMAX1-RV64 +; RUN: llc -mtriple=riscv32 -mattr=+v,+zvl128b -riscv-v-vector-bits-min=-1 -riscv-v-fixed-length-vector-lmul-max=1 -verify-machineinstrs < %s | FileCheck %s --check-prefixes=CHECK,RV32,LMULMAX1,LMULMAX1-RV32 +; RUN: llc -mtriple=riscv64 -mattr=+v,+zvl128b -riscv-v-vector-bits-min=-1 -riscv-v-fixed-length-vector-lmul-max=1 -verify-machineinstrs < %s | FileCheck %s --check-prefixes=CHECK,RV64,LMULMAX1,LMULMAX1-RV64 define void @add_v16i8(<16 x i8>* %x, <16 x i8>* %y) { ; CHECK-LABEL: add_v16i8: