Skip to content

[SandboxVec] Early return checks #107465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
// Early return if 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);
Expand Down
23 changes: 23 additions & 0 deletions llvm/test/Transforms/SandboxVectorizer/X86/no_implicit_float.ll
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be stored to a different pointer? otherwise this is dead code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use a different pointer, but it shouldn't matter too much. The vectorizer won't clean it up.

store double %ld1, ptr %ptr1
ret void
}
Loading