Skip to content

Add vscale_range attribute to functions with sve #58433

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions src/llvm-cpufeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ bool lowerCPUFeatures(Module &M) JL_NOTSAFEPOINT
Materialized.push_back(I);
}
}
if (TT.isAArch64()) {
Attribute FSAttr = F.getFnAttribute("target-features");
StringRef FS =
FSAttr.isValid() ? FSAttr.getValueAsString() : jl_ExecutionEngine->getTargetFeatureString();
SmallVector<StringRef, 128> Features;
FS.split(Features, ',');
for (StringRef Feature : Features) {
if (Feature == "sve")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (Feature == "sve")
if (Feature == "+sve")

With this the function gets the attribute vscale_range

; Function Attrs: vscale_range(1,16)
define swiftcc void @"julia_axpy!_763"(ptr nonnull swiftself %pgcstack_arg, double %"a::Float64", ptr noundef nonnull align 8 dereferenceable(24) %"x::Array", ptr noundef nonnull align 8 dereferenceable(24) %"y::Array") local_unnamed_addr #0 !dbg !4 {
; [...]
attributes #0 = { vscale_range(1,16) "frame-pointer"="all" "julia.fsig"="axpy!(Float64, Array{Float64, 1}, Array{Float64, 1})" "probe-stack"="inline-asm" }
attributes #1 = { noinline optnone vscale_range(1,16) "frame-pointer"="all" "probe-stack"="inline-asm" }
attributes #2 = { memory(argmem: readwrite, inaccessiblemem: readwrite) vscale_range(1,16) }
attributes #3 = { mustprogress nofree norecurse nosync nounwind speculatable willreturn memory(none) vscale_range(1,16) }
attributes #4 = { noreturn vscale_range(1,16) "frame-pointer"="all" "julia.fsig"="throw_eachindex_mismatch_indices(String, Base.OneTo{Int64}, Base.OneTo{Int64})" "probe-stack"="inline-asm" }
attributes #5 = { nounwind willreturn allockind("alloc") allocsize(2) memory(argmem: read, inaccessiblemem: readwrite) }
attributes #6 = { memory(argmem: readwrite, inaccessiblemem: readwrite) }
attributes #7 = { nounwind willreturn allockind("alloc") allocsize(1) memory(argmem: read, inaccessiblemem: readwrite) }
attributes #8 = { noreturn }

but there's still not vscale in the vector body.

F.addFnAttr(llvm::Attribute::getWithVScaleRangeArgs(M.getContext(), 1, 16)); //Hardcode for now
Copy link
Contributor

Choose a reason for hiding this comment

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

This is relevant for risc-v, too. I've got access to a chip with scalable vector registers (RVV extension), now, if only we could compile julia for that architecture: #57569 😇

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

@gbaraldi gbaraldi May 16, 2025

Choose a reason for hiding this comment

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

Don't look at how that function is implemented, you will find something similar :)

}
}
}

if (!Materialized.empty()) {
Expand Down