-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
RISC-V intrinsics with one or more target features are not inlined #137293
Copy link
Copy link
Open
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchO-riscvTarget: RISC-V architectureTarget: RISC-V architectureT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchO-riscvTarget: RISC-V architectureTarget: RISC-V architectureT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The Problem
The compiler does not inline RISC-V intrinsics that can be enabled with one or more target features (i.e.
#[target_feature(enable = "zkne", enable = "zknd")]) unless all of them are present.Expected Behavior
At least one enabled feature should be enough for the compiler to generate inlined code.
Explanation
RISC-V intrinsics such as sha512sig0 require only one target feature:
When
zknhis enabled, the compiler inlines the intrinsic with the appropriate instruction on nightly (https://godbolt.org/z/Kozx3KE11):Unfortunately, this is not the case for intrinsics that can be enabled by one or more target features. Let's take a look at aes64ks2:
The documentation states that the intrinsic is "safe to use if the
zkneORzkndtarget feature is present." which means that enabling at least one of them should be enough to inline the intrinsic.However, the compiler exhibits this behavior only if two of them are enabled at the same time.
The compiler generates a stub if only one of
zkne(https://godbolt.org/z/5TxeKo1sG), orzknd(https://godbolt.org/z/KKqz8MWYY) is enabled:If they are both enabled, the compiler inlines the intrinsic as expected (https://godbolt.org/z/3fEjfr1v8):
Meta
Here is the output of the compiler: