[llvm] [SandboxVec] Early return checks (PR #107465)

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 15:08:59 PDT 2024


https://github.com/vporpo updated https://github.com/llvm/llvm-project/pull/107465

>From 01399859987a976a2729ad18ed9d46bc3d9c126c Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Thu, 5 Sep 2024 14:12:24 -0700
Subject: [PATCH 1/2] [SandboxVec] Early return checks

This patch implements a couple of early return checks.
---
 .../Vectorize/SandboxVectorizer/SandboxVectorizer.cpp | 11 +++++++++++
 .../SandboxVectorizer/X86/no_vector_regs.ll           |  9 +++++++++
 .../Transforms/SandboxVectorizer/no_implicit_float.ll |  9 +++++++++
 3 files changed, 29 insertions(+)
 create mode 100644 llvm/test/Transforms/SandboxVectorizer/X86/no_vector_regs.ll
 create mode 100644 llvm/test/Transforms/SandboxVectorizer/no_implicit_float.ll

diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
index ec4bfbb56ecb48..1ac11dba08fbd6 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
@@ -29,7 +29,18 @@ PreservedAnalyses SandboxVectorizerPass::run(Function &F,
 }
 
 bool SandboxVectorizerPass::runImpl(Function &F) {
+  // If the target claims to have no vector registers early return.
+  if (!TTI->getNumberOfRegisters(TTI->getRegisterClassForType(true))) {
+    LLVM_DEBUG(dbgs() << "SBVec: Target has no vector registers, return.\n");
+    return false;
+  }
   LLVM_DEBUG(dbgs() << "SBVec: Analyzing " << F.getName() << ".\n");
+  // Don't vectorize when the attribute NoImplicitFloat is used.
+  if (F.hasFnAttribute(Attribute::NoImplicitFloat)) {
+    LLVM_DEBUG(dbgs() << "SBVec: NoImplicitFloat attribute, return.\n");
+    return false;
+  }
+
   sandboxir::Context Ctx(F.getContext());
   // Create SandboxIR for `F`.
   sandboxir::Function &SBF = *Ctx.createFunction(&F);
diff --git a/llvm/test/Transforms/SandboxVectorizer/X86/no_vector_regs.ll b/llvm/test/Transforms/SandboxVectorizer/X86/no_vector_regs.ll
new file mode 100644
index 00000000000000..3c3a3bd2fe6ea0
--- /dev/null
+++ b/llvm/test/Transforms/SandboxVectorizer/X86/no_vector_regs.ll
@@ -0,0 +1,9 @@
+; RUN: opt -passes=sandbox-vectorizer -debug -mtriple=x86_64-- -mattr=-sse %s 2>&1 | FileCheck %s
+; REQUIRES: asserts
+; Please note that this won't update automatically with update_test_checks.py !
+
+; Check that we early return if the target has no vector registers.
+define void @no_vector_regs() {
+; CHECK: SBVec: Target has no vector registers, return.
+  ret void
+}
diff --git a/llvm/test/Transforms/SandboxVectorizer/no_implicit_float.ll b/llvm/test/Transforms/SandboxVectorizer/no_implicit_float.ll
new file mode 100644
index 00000000000000..8081323c88137f
--- /dev/null
+++ b/llvm/test/Transforms/SandboxVectorizer/no_implicit_float.ll
@@ -0,0 +1,9 @@
+; RUN: opt -passes=sandbox-vectorizer -debug %s 2>&1 | FileCheck %s
+; REQUIRES: asserts
+; Please note that this won't update automatically with update_test_checks.py !
+
+; Check that we early return if the function has the NoImplicitFloat attribute.
+define void @no_implicit_float() noimplicitfloat {
+; CHECK: SBVec: NoImplicitFloat attribute, return.
+  ret void
+}

>From fa2c36f6a669e69cb6c93804587091262186132d Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Thu, 5 Sep 2024 15:06:33 -0700
Subject: [PATCH 2/2] fixup! [SandboxVec] Early return checks

---
 .../SandboxVectorizer/SandboxVectorizer.cpp   |  2 +-
 .../X86/no_implicit_float.ll                  | 23 +++++++++++++++++++
 .../SandboxVectorizer/X86/no_vector_regs.ll   |  9 --------
 .../SandboxVectorizer/no_implicit_float.ll    |  9 --------
 4 files changed, 24 insertions(+), 19 deletions(-)
 create mode 100644 llvm/test/Transforms/SandboxVectorizer/X86/no_implicit_float.ll
 delete mode 100644 llvm/test/Transforms/SandboxVectorizer/X86/no_vector_regs.ll
 delete mode 100644 llvm/test/Transforms/SandboxVectorizer/no_implicit_float.ll

diff --git a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
index 1ac11dba08fbd6..e9be6f5283fea7 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
@@ -35,7 +35,7 @@ bool SandboxVectorizerPass::runImpl(Function &F) {
     return false;
   }
   LLVM_DEBUG(dbgs() << "SBVec: Analyzing " << F.getName() << ".\n");
-  // Don't vectorize when the attribute NoImplicitFloat is used.
+  // Early return if the attribute NoImplicitFloat is used.
   if (F.hasFnAttribute(Attribute::NoImplicitFloat)) {
     LLVM_DEBUG(dbgs() << "SBVec: NoImplicitFloat attribute, return.\n");
     return false;
diff --git a/llvm/test/Transforms/SandboxVectorizer/X86/no_implicit_float.ll b/llvm/test/Transforms/SandboxVectorizer/X86/no_implicit_float.ll
new file mode 100644
index 00000000000000..37fc03cb311661
--- /dev/null
+++ b/llvm/test/Transforms/SandboxVectorizer/X86/no_implicit_float.ll
@@ -0,0 +1,23 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -passes=sandbox-vectorizer -mtriple=x86_64-- -mattr=+avx %s -S | FileCheck %s
+
+; Check that we don't vectorize a NoImplicitFloat function.
+define void @no_implicit_float(ptr %ptr) noimplicitfloat {
+; CHECK-LABEL: define void @no_implicit_float(
+; CHECK-SAME: ptr [[PTR:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:    [[PTR0:%.*]] = getelementptr double, ptr [[PTR]], i32 0
+; CHECK-NEXT:    [[PTR1:%.*]] = getelementptr double, ptr [[PTR]], i32 1
+; CHECK-NEXT:    [[LD0:%.*]] = load double, ptr [[PTR0]], align 8
+; CHECK-NEXT:    [[LD1:%.*]] = load double, ptr [[PTR1]], align 8
+; CHECK-NEXT:    store double [[LD0]], ptr [[PTR0]], align 8
+; CHECK-NEXT:    store double [[LD1]], ptr [[PTR1]], align 8
+; CHECK-NEXT:    ret void
+;
+  %ptr0 = getelementptr double, ptr %ptr, i32 0
+  %ptr1 = getelementptr double, ptr %ptr, i32 1
+  %ld0 = load double, ptr %ptr0
+  %ld1 = load double, ptr %ptr1
+  store double %ld0, ptr %ptr0
+  store double %ld1, ptr %ptr1
+  ret void
+}
diff --git a/llvm/test/Transforms/SandboxVectorizer/X86/no_vector_regs.ll b/llvm/test/Transforms/SandboxVectorizer/X86/no_vector_regs.ll
deleted file mode 100644
index 3c3a3bd2fe6ea0..00000000000000
--- a/llvm/test/Transforms/SandboxVectorizer/X86/no_vector_regs.ll
+++ /dev/null
@@ -1,9 +0,0 @@
-; RUN: opt -passes=sandbox-vectorizer -debug -mtriple=x86_64-- -mattr=-sse %s 2>&1 | FileCheck %s
-; REQUIRES: asserts
-; Please note that this won't update automatically with update_test_checks.py !
-
-; Check that we early return if the target has no vector registers.
-define void @no_vector_regs() {
-; CHECK: SBVec: Target has no vector registers, return.
-  ret void
-}
diff --git a/llvm/test/Transforms/SandboxVectorizer/no_implicit_float.ll b/llvm/test/Transforms/SandboxVectorizer/no_implicit_float.ll
deleted file mode 100644
index 8081323c88137f..00000000000000
--- a/llvm/test/Transforms/SandboxVectorizer/no_implicit_float.ll
+++ /dev/null
@@ -1,9 +0,0 @@
-; RUN: opt -passes=sandbox-vectorizer -debug %s 2>&1 | FileCheck %s
-; REQUIRES: asserts
-; Please note that this won't update automatically with update_test_checks.py !
-
-; Check that we early return if the function has the NoImplicitFloat attribute.
-define void @no_implicit_float() noimplicitfloat {
-; CHECK: SBVec: NoImplicitFloat attribute, return.
-  ret void
-}



More information about the llvm-commits mailing list