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

via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 14:18:05 PDT 2024


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

This patch implements a couple of early return checks.

>From abb6673d1aa4227fdf0ab254d8ad40cc4b0cd605 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] [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 072a6606694a0f..9c84ca2880ca39 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp
@@ -28,7 +28,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
+}



More information about the llvm-commits mailing list