diff options
author | Luke <luke957@foxmail.com> | 2021-02-26 22:10:30 +0800 |
---|---|---|
committer | Luke <luke957@foxmail.com> | 2021-03-05 10:54:51 +0800 |
commit | d28297ff68eeecc381426416ff92a466953cd93d (patch) | |
tree | 3e62834fa03bbec180904cf940eda36f57248ed5 | |
parent | 2357d29335f293ac0333dd86a0118856d586922f (diff) | |
download | llvm-d28297ff68eeecc381426416ff92a466953cd93d.zip llvm-d28297ff68eeecc381426416ff92a466953cd93d.tar.gz llvm-d28297ff68eeecc381426416ff92a466953cd93d.tar.bz2 |
[RISCV] Enable fixed-length vectorization of LoopVectorizer for RISC-V Vector
By implementing the method "unsigned RISCVTTIImpl::getRegisterBitWidth(bool Vector)",
fixed-length vectorization is enabled when possible. Without this method, the
"#pragma clang loop" directive is needed to enable vectorization(or the cost model
may inform LLVM that "Vectorization is possible but not beneficial").
Reviewed By: frasercrmck
Differential Revision: https://reviews.llvm.org/D97549
-rw-r--r-- | llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h | 9 | ||||
-rw-r--r-- | llvm/test/Transforms/LoopVectorize/RISCV/riscv-unroll.ll | 38 |
2 files changed, 47 insertions, 0 deletions
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h index 5177f81..ad9c1b6 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.h @@ -51,6 +51,15 @@ public: bool shouldExpandReduction(const IntrinsicInst *II) const; bool supportsScalableVectors() const { return ST->hasStdExtV(); } Optional<unsigned> getMaxVScale() const; + + unsigned getRegisterBitWidth(bool Vector) const { + if (Vector) { + if (ST->hasStdExtV()) + return ST->getMinRVVVectorSizeInBits(); + return 0; + } + return ST->getXLen(); + } }; } // end namespace llvm diff --git a/llvm/test/Transforms/LoopVectorize/RISCV/riscv-unroll.ll b/llvm/test/Transforms/LoopVectorize/RISCV/riscv-unroll.ll new file mode 100644 index 0000000..efbdc3a --- /dev/null +++ b/llvm/test/Transforms/LoopVectorize/RISCV/riscv-unroll.ll @@ -0,0 +1,38 @@ +; RUN: opt < %s -loop-vectorize -mtriple=riscv64 -mattr=+experimental-v -riscv-v-vector-bits-min=128 -S | FileCheck %s +; RUN: opt < %s -loop-vectorize -mtriple=riscv32 -mattr=+experimental-v -riscv-v-vector-bits-min=128 -S | FileCheck %s + +; Function Attrs: nounwind +define i32* @array_add(i32* noalias nocapture readonly %a, i32* noalias nocapture readonly %b, i32* %c, i32 %size) { +;CHECK-LABEL: array_add +;CHECK: load <4 x i32> +;CHECK: load <4 x i32> +;CHECK: add nsw <4 x i32> +;CHECK: store <4 x i32> +;CHECK: ret +entry: + %cmp10 = icmp sgt i32 %size, 0 + br i1 %cmp10, label %for.body.preheader, label %for.end + +for.body.preheader: ; preds = %entry + br label %for.body + +for.body: ; preds = %for.body.preheader, %for.body + %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ] + %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv + %0 = load i32, i32* %arrayidx, align 4 + %arrayidx2 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv + %1 = load i32, i32* %arrayidx2, align 4 + %add = add nsw i32 %1, %0 + %arrayidx4 = getelementptr inbounds i32, i32* %c, i64 %indvars.iv + store i32 %add, i32* %arrayidx4, align 4 + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 + %lftr.wideiv = trunc i64 %indvars.iv.next to i32 + %exitcond = icmp eq i32 %lftr.wideiv, %size + br i1 %exitcond, label %for.end.loopexit, label %for.body + +for.end.loopexit: ; preds = %for.body + br label %for.end + +for.end: ; preds = %for.end.loopexit, %entry + ret i32* %c +} |