Skip to content

Add autocast support for x86amx #142251

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

Closed
wants to merge 10 commits into from
Closed

Conversation

sayantn
Copy link
Contributor

@sayantn sayantn commented Jun 9, 2025

Builds on #140763 (well currently it just includes those commits as well) by further adding autocasts for x86amx from/to vectors of size 8192 bits.

This also disables SIMD vector abi checks for the "unadjusted" abi because

  • This is primarily used to link with LLVM intrinsics, which don't actually lower to function calls with vector arguments. Even with other cg backends, this is true.
  • This ABI is internal and perma-unstable (and also super specific), so it is very unlikely that this will cause breakages.
  • (The primary reason) Without doing this we can't actually use 8192 bit long vectors to represent x86amx

This PR also does some refactoring in our intrinsic caching mechanism. The core philosophy of this is that the LLVM intrinsic is uniquely determined by its base name and its type parameters (this is only relevant if the intrinsic is not overloaded).

  • Instead of caching based on the full name, we cache based on the base name and the type parameters. This helps with the implementations because often we do elaborate transformations to string representation from LLVM type to get the full overloaded LLVM name, which is no longer needed.
  • This makes the caching more flexible. For overloaded intrinsics like llvm.is.constant, we could only ever manually cache a finite amount of types, but with this we can now dynamically generate the cache (which also has the byproduct that is_val_statically_known is now implemented in cg_llvm for all immediate types.

Just putting this as a PR to notify myself that this exists

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 9, 2025
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check-2 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] rustc_index_macros test:true 0.153
error[E0308]: mismatched types
    --> compiler/rustc_codegen_llvm/src/builder.rs:1399:77
     |
1399 |             let pointer = self.call_intrinsic("llvm.threadlocal.address", &[global]);
     |                                                                             ^^^^^^ expected `&llvm::ffi::Type`, found `&llvm::ffi::Value`
     |
    ::: compiler/rustc_codegen_llvm/src/llvm/ffi.rs:746:5
     |
746  |     pub(crate) type Type;
     |     -------------------- the expected foreign type
---

error[E0061]: this method takes 3 arguments but 2 arguments were supplied
    --> compiler/rustc_codegen_llvm/src/builder.rs:1399:32
     |
1399 |             let pointer = self.call_intrinsic("llvm.threadlocal.address", &[global]);
     |                                ^^^^^^^^^^^^^^--------------------------------------- argument #3 of type `&[&llvm::ffi::Value]` is missing
     |
note: method defined here
    --> compiler/rustc_codegen_llvm/src/builder.rs:1553:19
     |
1553 |     pub(crate) fn call_intrinsic(
     |                   ^^^^^^^^^^^^^^
...
1557 |         args: &[&'ll Value],
     |         -------------------
help: provide the argument
     |
1399 |             let pointer = self.call_intrinsic("llvm.threadlocal.address", &[global], /* &[&llvm::ffi::Value] */);
     |                                                                                    ++++++++++++++++++++++++++++

error[E0308]: mismatched types
    --> compiler/rustc_codegen_llvm/src/builder.rs:1846:64
     |
1846 |             let cond = self.call_intrinsic("llvm.type.test", &[llfn, typeid]);
     |                                                                ^^^^ expected `&llvm::ffi::Type`, found `&llvm::ffi::Value`
     |
    ::: compiler/rustc_codegen_llvm/src/llvm/ffi.rs:746:5
     |
746  |     pub(crate) type Type;
     |     -------------------- the expected foreign type
---

error[E0061]: this method takes 3 arguments but 2 arguments were supplied
    --> compiler/rustc_codegen_llvm/src/builder.rs:1846:29
     |
1846 |             let cond = self.call_intrinsic("llvm.type.test", &[llfn, typeid]);
     |                             ^^^^^^^^^^^^^^----------------------------------- argument #3 of type `&[&llvm::ffi::Value]` is missing
     |
note: method defined here
    --> compiler/rustc_codegen_llvm/src/builder.rs:1553:19
     |
1553 |     pub(crate) fn call_intrinsic(
     |                   ^^^^^^^^^^^^^^
...
1557 |         args: &[&'ll Value],
     |         -------------------
help: provide the argument
     |
1846 |             let cond = self.call_intrinsic("llvm.type.test", &[llfn, typeid], /* &[&llvm::ffi::Value] */);
     |                                                                             ++++++++++++++++++++++++++++

Some errors have detailed explanations: E0061, E0308.
For more information about an error, try `rustc --explain E0061`.
[RUSTC-TIMING] rustc_codegen_llvm test:false 3.278

@sayantn
Copy link
Contributor Author

sayantn commented Jun 9, 2025

I have decided to split this into different PRs - one for the intrinsic implementation changes, and the AMX changes I will merge with #140763

@sayantn sayantn closed this Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants