Skip to content

Commit c1c4251

Browse files
authored
[SandboxVec] Early return checks (#107465)
This patch implements a couple of early return checks.
1 parent bd840a4 commit c1c4251

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

llvm/lib/Transforms/Vectorize/SandboxVectorizer/SandboxVectorizer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,18 @@ PreservedAnalyses SandboxVectorizerPass::run(Function &F,
2929
}
3030

3131
bool SandboxVectorizerPass::runImpl(Function &F) {
32+
// If the target claims to have no vector registers early return.
33+
if (!TTI->getNumberOfRegisters(TTI->getRegisterClassForType(true))) {
34+
LLVM_DEBUG(dbgs() << "SBVec: Target has no vector registers, return.\n");
35+
return false;
36+
}
3237
LLVM_DEBUG(dbgs() << "SBVec: Analyzing " << F.getName() << ".\n");
38+
// Early return if the attribute NoImplicitFloat is used.
39+
if (F.hasFnAttribute(Attribute::NoImplicitFloat)) {
40+
LLVM_DEBUG(dbgs() << "SBVec: NoImplicitFloat attribute, return.\n");
41+
return false;
42+
}
43+
3344
sandboxir::Context Ctx(F.getContext());
3445
// Create SandboxIR for `F`.
3546
sandboxir::Function &SBF = *Ctx.createFunction(&F);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes=sandbox-vectorizer -mtriple=x86_64-- -mattr=+avx %s -S | FileCheck %s
3+
4+
; Check that we don't vectorize a NoImplicitFloat function.
5+
define void @no_implicit_float(ptr %ptr) noimplicitfloat {
6+
; CHECK-LABEL: define void @no_implicit_float(
7+
; CHECK-SAME: ptr [[PTR:%.*]]) #[[ATTR0:[0-9]+]] {
8+
; CHECK-NEXT: [[PTR0:%.*]] = getelementptr double, ptr [[PTR]], i32 0
9+
; CHECK-NEXT: [[PTR1:%.*]] = getelementptr double, ptr [[PTR]], i32 1
10+
; CHECK-NEXT: [[LD0:%.*]] = load double, ptr [[PTR0]], align 8
11+
; CHECK-NEXT: [[LD1:%.*]] = load double, ptr [[PTR1]], align 8
12+
; CHECK-NEXT: store double [[LD0]], ptr [[PTR0]], align 8
13+
; CHECK-NEXT: store double [[LD1]], ptr [[PTR1]], align 8
14+
; CHECK-NEXT: ret void
15+
;
16+
%ptr0 = getelementptr double, ptr %ptr, i32 0
17+
%ptr1 = getelementptr double, ptr %ptr, i32 1
18+
%ld0 = load double, ptr %ptr0
19+
%ld1 = load double, ptr %ptr1
20+
store double %ld0, ptr %ptr0
21+
store double %ld1, ptr %ptr1
22+
ret void
23+
}

0 commit comments

Comments
 (0)