From 9a8f3b113d05d94d9aaacdf511365dde4e35ce4f Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Wed, 19 Oct 2022 16:05:39 -0700 Subject: [PATCH] [clang][RISCV] Set vscale_range attribute based on VLEN Follow up on D135894, restructure code to work in terms of minimum and maximum VLEN coming from RISCVISAInfo.cpp. In the original review, I'd mentioned that MinVLEN was sometimes zero. This turns out to be a case of human error, combined with really bad (lack of) error reporting. This patch adds appropriate tests for various vector extension combinations to show the mechanism works, but doesn't try to provide exhaustive coverage of the extension interactions. Presumably, that is already covered in existing tests elsewhere. Differential Revision: https://reviews.llvm.org/D136106 --- clang/lib/Basic/Targets/RISCV.cpp | 8 +++++--- clang/test/CodeGen/riscv-vector-bits-vscale-range.c | 10 ++++++++-- llvm/include/llvm/Support/RISCVISAInfo.h | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/clang/lib/Basic/Targets/RISCV.cpp b/clang/lib/Basic/Targets/RISCV.cpp index b94187f..08da016 100644 --- a/clang/lib/Basic/Targets/RISCV.cpp +++ b/clang/lib/Basic/Targets/RISCV.cpp @@ -252,9 +252,11 @@ RISCVTargetInfo::getVScaleRange(const LangOptions &LangOpts) const { return std::pair( LangOpts.VScaleMin ? LangOpts.VScaleMin : 1, LangOpts.VScaleMax); - if (hasFeature("v")) - // Minimum VLEN=128, Maximum VLEN=64k, and RISCV::RVVBitsPerBlock is 64. - return std::pair(2, 1024); + if (unsigned MinVLen = ISAInfo->getMinVLen()) { + unsigned MaxVLen = ISAInfo->getMaxVLen(); + // RISCV::RVVBitsPerBlock is 64. + return std::pair(MinVLen/64, MaxVLen/64); + } return None; } diff --git a/clang/test/CodeGen/riscv-vector-bits-vscale-range.c b/clang/test/CodeGen/riscv-vector-bits-vscale-range.c index 067669f..9fbb979 100644 --- a/clang/test/CodeGen/riscv-vector-bits-vscale-range.c +++ b/clang/test/CodeGen/riscv-vector-bits-vscale-range.c @@ -9,11 +9,17 @@ // RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=8 -S -emit-llvm -o - %s | FileCheck %s -D#VBITS=8 --check-prefix=CHECK-NOMAX // RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=16 -S -emit-llvm -o - %s | FileCheck %s -D#VBITS=16 --check-prefix=CHECK-NOMAX // RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +v -mvscale-min=1 -mvscale-max=0 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-UNBOUNDED -// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +v -S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-NONE +// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +v -S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-V +// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +v -target-feature +zvl512b -S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-ZVL +// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +zve64x -S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-ZVE64 +// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +zve64f -target-feature +f -S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-ZVE64 +// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +zve64d -target-feature +f -target-feature +d -S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-ZVE64 // CHECK-LABEL: @func() #0 // CHECK: attributes #0 = { {{.*}} vscale_range([[#VBITS]],[[#VBITS]]) {{.*}} } // CHECK-NOMAX: attributes #0 = { {{.*}} vscale_range([[#VBITS]],0) {{.*}} } // CHECK-UNBOUNDED: attributes #0 = { {{.*}} vscale_range(1,0) {{.*}} } -// CHECK-NONE: attributes #0 = { {{.*}} vscale_range(2,1024) {{.*}} } +// CHECK-V: attributes #0 = { {{.*}} vscale_range(2,1024) {{.*}} } +// CHECK-ZVL: attributes #0 = { {{.*}} vscale_range(8,1024) {{.*}} } +// CHECK-ZVE64: attributes #0 = { {{.*}} vscale_range(1,1024) {{.*}} } void func(void) {} diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h b/llvm/include/llvm/Support/RISCVISAInfo.h index eac6cc0..ced3baf4 100644 --- a/llvm/include/llvm/Support/RISCVISAInfo.h +++ b/llvm/include/llvm/Support/RISCVISAInfo.h @@ -60,6 +60,7 @@ public: unsigned getXLen() const { return XLen; }; unsigned getFLen() const { return FLen; }; unsigned getMinVLen() const { return MinVLen; } + unsigned getMaxVLen() const { return 65536; } unsigned getMaxELen() const { return MaxELen; } unsigned getMaxELenFp() const { return MaxELenFp; } -- 2.7.4