-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
MergeFunctions LLVM pass can generate invalid function calls under calling convention #57356
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.P-mediumMedium priorityMedium priorityT-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.llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixesIssue expected to be fixed by the next major LLVM upgrade, or backported fixes
Metadata
Metadata
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.P-mediumMedium priorityMedium priorityT-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.llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixesIssue expected to be fixed by the next major LLVM upgrade, or backported fixes
Type
Fields
Give feedbackNo fields configured for issues without a type.
Basically, the MergeFunctions LLVM pass can rewrite functions to generate calls that are not valid under the calling convention of the target, e.g.
extern "ptx-kernel"functions should not call otherextern "ptx-kernel"functions in NVPTX.This is an LLVM bug, described here (thanks @nikic): https://bugs.llvm.org/show_bug.cgi?id=40232. A PR also adds a target option and a -Z flag to control MergeFunctions: #57268.
Example: in the following Rust source, the functions
fooandbarget merged by MergeFunctions:to yield the incorrect PTX assembly, as the
call.uni barinstruction is not valid since a kernel is calling another kernel (note this requiresrustc -Z merge-functions=trampolinesfrom the above PR):Disabling MergeFunctions (e.g. using
rustc -Z merge-functions=disabled) yields correct PTX assembly:P.S. Currently the default operation of MergeFunctions is to emit function aliases which are not supported by NVPTX, so controlling MergeFunctions via the
merge-functionsflag is necessary to generate any of the PTX assembly above.Meta
I'm on a patched rustc so this may not be so helpful, but here it is anyway:
rustc --version --verbose: