-
Couldn't load subscription status.
- Fork 13.9k
Change codegen of LLVM intrinsics to be name-based, and add llvm linkage support for bf16(xN) and i1xN
#140763
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
base: master
Are you sure you want to change the base?
Conversation
|
Some changes occurred in compiler/rustc_codegen_ssa |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in compiler/rustc_codegen_gcc |
This comment has been minimized.
This comment has been minimized.
x86amx for i32x256 for AMX intrinsics
x86amx for i32x256 for AMX intrinsicsx86amx and i32x256 for AMX intrinsics
This comment has been minimized.
This comment has been minimized.
|
I think you can use |
|
That can be used to improve performance, I am not really focusing on performance in this PR. I want to currently emphasize the correctness of the codegen. |
|
Oh wait, I probably misunderstood your comment, you meant using the llvm declaration by itself. Yeah, that would be better, thanks for the info. I will update the impl when I get the chance |
I think you can just focus on non-overloaded functions for this PR. Overloaded functions and type checking that checking Rust function signatures using LLVM defined can be subsequent PRs. @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@sayantn Taking the address of an intrinsic is invalid LLVM IR. |
This comment has been minimized.
This comment has been minimized.
|
@rustbot ready Sorry for the inactivity, got busy with other things. I have removed the AMX autocasting part, but couldn't remove the
So the autoupgrade script upgrades the old versions to the new ones. But I encountered some interesting error messages if I try to delegate it to AutoUpgrade (while compiling stdarch)
About your comment on not being able to generalize the autocasts to generic intrinsics, to me that sounds fine enough. The scope of this PR is anyway limited to non-overloaded intrinsics. Autocasts are not as important for overloaded functions because stdarch (the main consumer of |
This comment has been minimized.
This comment has been minimized.
53c231b to
a390bc2
Compare
bf16(xN), i1xN and x86amxbf16(xN) and i1xN
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
☔ The latest upstream changes (presumably #146185) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
|
@nikic small ping, this pr is quite bitrotty in nature, and tends to accumulate merge conflicts with almost all PRs to cg_llvm. |
|
☔ The latest upstream changes (presumably #147384) made this pull request unmergeable. Please resolve the merge conflicts. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
☔ The latest upstream changes (presumably #147453) made this pull request unmergeable. Please resolve the merge conflicts. |
- Correct usage of invalid intrinsics in tests
…error messages Create lints for deprecated and invalid intrinsics
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This PR changes how LLVM intrinsics are codegen
Explanation of the changes
Current procedure
This is the same for all functions, LLVM intrinsics are not treated specially
f32 (f32)due to the Rust signaturePros
Cons
-Zverify-llvm-irto it will fail compilation). I would expect this code to not compile at all instead of generating invalid IR.x86amxtype, and (almost) all intrinsics that have vectors ofi1types) can't be linked to at all. This is a (major?) roadblock in the AMX and AVX512 support in stdarch.-Zverify-llvm-irwon't complain. Eventually it will error out due to the non-existing function (courtesy of the linker). I don't think this is a behavior we want.What this PR does
LLVMIntrinsicGetTypeto directly get the function type of the intrinsic from LLVM.Note
This PR only focuses on non-overloaded intrinsics, overloaded can be done in a future PR
Regardless, the undermentioned functionalities work for all intrinsics
AutoUpgraded by LLVM. If not, that means it is an invalid intrinsic, and we error out.Pros
x86amxand injectingllvm.x86.cast.vector.to.tileandllvm.x86.cast.tile.to.vectors in callsite)Note
I don't intend for these bypasses to be permanent. A better approach will be introducing a
bf16type in Rust, and allowingrepr(simd)withbools to get Rust-nativei1xNs. These are meant to be short-time, as I mentioned, "bypass"es. They shouldn't cause any major breakage even if removed, aslink_llvm_intrinsicsis perma-unstable.This PR adds bypasses for
bf16(viai16),bf16xN(viai16xN) andi1xN(viaiM, whereMis the smallest power of 2 s.t.M >= N, unlessN <= 4, where we useM = 8). This will unblock AVX512-VP2INTERSECT and a lot of bf16 intrinsics in stdarch. This PR also automatically destructures structs if the types don't exactly match (this is required for us to start emitting hard errors on mismmatches).Cons
Possible ways to extend this to overloaded intrinsics (future)
Parse the mangled intrinsic name to get the type parameters
LLVM has a stable mangling of intrinsic names with type parameters (in
LLVMIntrinsicCopyOverloadedName2), so we can parse the name to get the type parameters, and then just do the same thing.Pros
Cons
TargetExttypes or identified structs, their name is a part of the mangling, making it impossible to reverse. Even more complexities arise when there are unnamed identified structs, as LLVM adds more mangling to the names.Use the
IITDescriptortable and the Rust function signatureWe can use the base name to get the
IITDescriptors of the corresponding intrinsic, and then manually implement the matching logic based on the Rust signature.Pros
TargetExttypes. Also, fun fact, Rust exports all struct types as literal structs (unless it is emitting LLVM IR, then it always uses named identified structs, with mangled names)Cons
llvm.sqrt.bf16until we havebf16types in Rust. Because if we are usingu16s (or any other type) asbf16s, then the matcher will deduce that the signature isu16 (u16)notbf16 (bf16)(which would lead to an error becauseu16is not a valid type parameter forllvm.sqrt), even though the intended type parameter is specified in the name.IITDescriptorKindsThese 2 approaches might give different results for same function. Let's take
The name-based approach will decide that the type parameter is
bf16, and the LLVM signature isi1 (bf16)and will inject some bitcasts at callsite.The
IITDescriptor-based approach will decide that the LLVM signature isi1 (u16), and will see that the name given doesn't match the expected name (llvm.is.constant.u16), and will error out.Other things that this PR does
bitcasts incg_llvm/builder::check_call(now renamed ascast_argumentsdue to its new counterpartcast_return). This was old code from when Rust used to pass non-erased lifetimes to LLVM.Reviews are welcome, as this is my first time actually contributing to
rustcAfter CI is green, we would need a try build and a rustc-perf run.
@rustbot label T-compiler A-codegen A-LLVM
r? codegen