[llvm] [llvm-opt-report] Show scalable vectorization factors (PR #123367)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 17 08:31:05 PST 2025
https://github.com/iamlouk created https://github.com/llvm/llvm-project/pull/123367
Scalable vectorization factors are printed as "vscale x VF" where VF is the known minimum number of elements, a integer. Currently, llvm-opt-report always expects a integer (like for vectorization with fixed-sized vectors), and does not display any vectorization factor in the output (just 'V', but without a number).
This patch adds support for scalable vectorization factors and prints them as "VNx<VF>", so for example "VNx4". The "Nx" is used to differentiate between fixed-sized and scalable factors, and is consistent with the way LLVM mangles scalable vectors in other places.
>From f97e2208c1015c7a46f9c29e9e302746a24035bc Mon Sep 17 00:00:00 2001
From: Lou Knauer <lou.knauer at sipearl.com>
Date: Fri, 17 Jan 2025 18:55:18 +0100
Subject: [PATCH] [llvm-opt-report] Show scalable vectorization factors
Scalable vectorization factors are printed as "vscale x VF" where VF is
the known minimum number of elements, a integer. Currently,
llvm-opt-report always expects a integer (like for vectorization with
fixed-sized vectors), and does not display any vectorization factor
in the output (just 'V', but without a number).
This patch adds support for scalable vectorization factors and prints
them as "VNx<VF>", so for example "VNx4". The "Nx" is used to
differentiate between fixed-sized and scalable factors, and is
consistent with the way LLVM mangles scalable vectors in other places.
---
.../tools/llvm-opt-report/Inputs/scalable.c | 9 ++++
.../llvm-opt-report/Inputs/scalable.yaml | 12 +++++
llvm/test/tools/llvm-opt-report/scalabe.test | 12 +++++
llvm/tools/llvm-opt-report/OptReport.cpp | 44 ++++++++++++++-----
4 files changed, 65 insertions(+), 12 deletions(-)
create mode 100644 llvm/test/tools/llvm-opt-report/Inputs/scalable.c
create mode 100644 llvm/test/tools/llvm-opt-report/Inputs/scalable.yaml
create mode 100644 llvm/test/tools/llvm-opt-report/scalabe.test
diff --git a/llvm/test/tools/llvm-opt-report/Inputs/scalable.c b/llvm/test/tools/llvm-opt-report/Inputs/scalable.c
new file mode 100644
index 00000000000000..d2fa6fb879c1f6
--- /dev/null
+++ b/llvm/test/tools/llvm-opt-report/Inputs/scalable.c
@@ -0,0 +1,9 @@
+#include <stddef.h>
+
+void foo(size_t N, float A[restrict N], float B[N]) {
+ #pragma clang loop vectorize_width(4, scalable)
+ for (size_t i = 0; i < N; i++) {
+ A[i] = B[i] * 42.f;
+ }
+}
+
diff --git a/llvm/test/tools/llvm-opt-report/Inputs/scalable.yaml b/llvm/test/tools/llvm-opt-report/Inputs/scalable.yaml
new file mode 100644
index 00000000000000..7f248c57faa6ce
--- /dev/null
+++ b/llvm/test/tools/llvm-opt-report/Inputs/scalable.yaml
@@ -0,0 +1,12 @@
+--- !Passed
+Pass: loop-vectorize
+Name: Vectorized
+DebugLoc: { File: './Inputs/scalable.c', Line: 5, Column: 3 }
+Function: foo
+Args:
+ - String: 'vectorized loop (vectorization width: '
+ - VectorizationFactor: vscale x 4
+ - String: ', interleaved count: '
+ - InterleaveCount: '2'
+ - String: ')'
+...
diff --git a/llvm/test/tools/llvm-opt-report/scalabe.test b/llvm/test/tools/llvm-opt-report/scalabe.test
new file mode 100644
index 00000000000000..c853c57c46b2b3
--- /dev/null
+++ b/llvm/test/tools/llvm-opt-report/scalabe.test
@@ -0,0 +1,12 @@
+RUN: llvm-opt-report -r %p %p/Inputs/scalable.yaml | FileCheck -strict-whitespace %s
+
+; CHECK: < {{.*[/\]}}scalable.c
+; CHECK-NEXT: 1 | #include <stddef.h>
+; CHECK-NEXT: 2 |
+; CHECK-NEXT: 3 | void foo(size_t N, float A[restrict N], float B[N]) {
+; CHECK-NEXT: 4 | #pragma clang loop vectorize_width(4, scalable)
+; CHECK-NEXT: 5 VNx4,2 | for (size_t i = 0; i < N; i++) {
+; CHECK-NEXT: 6 | A[i] = B[i] * 42.f;
+; CHECK-NEXT: 7 | }
+; CHECK-NEXT: 8 | }
+; CHECK-NEXT: 9 |
diff --git a/llvm/tools/llvm-opt-report/OptReport.cpp b/llvm/tools/llvm-opt-report/OptReport.cpp
index cee9abcb494196..68ed92c8bacea6 100644
--- a/llvm/tools/llvm-opt-report/OptReport.cpp
+++ b/llvm/tools/llvm-opt-report/OptReport.cpp
@@ -29,6 +29,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
+#include "llvm/Support/TypeSize.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
@@ -100,7 +101,7 @@ struct OptReportLocationInfo {
OptReportLocationItemInfo Unrolled;
OptReportLocationItemInfo Vectorized;
- int VectorizationFactor = 1;
+ ElementCount VectorizationFactor = ElementCount::getFixed(1);
int InterleaveCount = 1;
int UnrollCount = 1;
@@ -109,8 +110,9 @@ struct OptReportLocationInfo {
Unrolled |= RHS.Unrolled;
Vectorized |= RHS.Vectorized;
- VectorizationFactor =
- std::max(VectorizationFactor, RHS.VectorizationFactor);
+ if (ElementCount::isKnownLT(VectorizationFactor, RHS.VectorizationFactor))
+ VectorizationFactor = RHS.VectorizationFactor;
+
InterleaveCount = std::max(InterleaveCount, RHS.InterleaveCount);
UnrollCount = std::max(UnrollCount, RHS.UnrollCount);
@@ -130,9 +132,11 @@ struct OptReportLocationInfo {
return true;
else if (RHS.Vectorized < Vectorized || Succinct)
return false;
- else if (VectorizationFactor < RHS.VectorizationFactor)
+ else if (ElementCount::isKnownLT(VectorizationFactor,
+ RHS.VectorizationFactor))
return true;
- else if (VectorizationFactor > RHS.VectorizationFactor)
+ else if (ElementCount::isKnownGT(VectorizationFactor,
+ RHS.VectorizationFactor))
return false;
else if (InterleaveCount < RHS.InterleaveCount)
return true;
@@ -197,17 +201,26 @@ static bool readLocationInfo(LocationInfoTy &LocationInfo) {
bool Transformed = Remark.RemarkType == remarks::Type::Passed;
- int VectorizationFactor = 1;
+ ElementCount VectorizationFactor = ElementCount::getFixed(1);
int InterleaveCount = 1;
int UnrollCount = 1;
for (const remarks::Argument &Arg : Remark.Args) {
- if (Arg.Key == "VectorizationFactor")
- Arg.Val.getAsInteger(10, VectorizationFactor);
- else if (Arg.Key == "InterleaveCount")
+ if (Arg.Key == "VectorizationFactor") {
+ int MinValue = 1;
+ bool IsScalable = false;
+ if (Arg.Val.starts_with("vscale x ")) {
+ Arg.Val.drop_front(9).getAsInteger(10, MinValue);
+ IsScalable = true;
+ } else {
+ Arg.Val.getAsInteger(10, MinValue);
+ }
+ VectorizationFactor = ElementCount::get(MinValue, IsScalable);
+ } else if (Arg.Key == "InterleaveCount") {
Arg.Val.getAsInteger(10, InterleaveCount);
- else if (Arg.Key == "UnrollCount")
+ } else if (Arg.Key == "UnrollCount") {
Arg.Val.getAsInteger(10, UnrollCount);
+ }
}
const std::optional<remarks::RemarkLocation> &Loc = Remark.Loc;
@@ -292,7 +305,11 @@ static bool writeReport(LocationInfoTy &LocationInfo) {
bool NothingUnrolled = !MaxLI.Unrolled.Transformed;
bool NothingVectorized = !MaxLI.Vectorized.Transformed;
- unsigned VFDigits = llvm::utostr(MaxLI.VectorizationFactor).size();
+ unsigned VFDigits =
+ llvm::utostr(MaxLI.VectorizationFactor.getKnownMinValue()).size();
+ if (MaxLI.VectorizationFactor.isScalable())
+ VFDigits += 2; // For "Nx..."
+
unsigned ICDigits = llvm::utostr(MaxLI.InterleaveCount).size();
unsigned UCDigits = llvm::utostr(MaxLI.UnrollCount).size();
@@ -382,7 +399,10 @@ static bool writeReport(LocationInfoTy &LocationInfo) {
raw_string_ostream RS(R);
if (!Succinct) {
- RS << LLI.VectorizationFactor << "," << LLI.InterleaveCount;
+ if (LLI.VectorizationFactor.isScalable())
+ RS << "Nx";
+ RS << LLI.VectorizationFactor.getKnownMinValue() << ","
+ << LLI.InterleaveCount;
RS << std::string(VFDigits + ICDigits + 1 - R.size(), ' ');
}
More information about the llvm-commits
mailing list