Adapt NVPTX target-feature handling for LLVM 22#157868
Open
kulst wants to merge 1 commit into
Open
Conversation
This comment has been minimized.
This comment has been minimized.
7b7a043 to
abd0003
Compare
This comment has been minimized.
This comment has been minimized.
Previously, Rust did not explicitly enable a PTX version target-feature, because LLVM implied one from the selected CPU. Starting with LLVM 22, the NVPTX backend still infers the minimum required PTX version from the selected CPU when none is selected explicitly, but no longer reflects that version in the enabled subtarget features. As a result, cfg could miss the PTX version of the emitted PTX. Also, if a PTX version below the required minimum is selected explicitly, LLVM errors. We missed this because the corresponding NVPTX target-feature test was mistakenly disabled. To keep cfg evaluation consistent and avoid LLVM errors, always select an explicit PTX version: whichever is higher between - Rust's minimum required PTX version, and - the CPU's minimum required PTX version. Re-enable the NVPTX target-feature test and adapt it to Rust's minimum required PTX and sm versions. Forbid PTX and sm versions below Rust's minimum required versions by marking the corresponding target-features as `Forbidden`. Add PTX and sm versions present in LLVM 22 but missing as Rust target-features.
abd0003 to
8ec03af
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, we did not explicitly enable a PTX version target-feature, because LLVM implied one from the selected CPU.
Starting with LLVM 22, the NVPTX backend still infers the minimum required PTX version from the selected CPU when none is selected explicitly, but no longer reflects that version in the enabled subtarget features. As a result, cfg could miss the PTX version of the emitted PTX. Also, if a PTX version below the required minimum is selected explicitly, LLVM errors.
We missed this because the corresponding NVPTX target-feature test was mistakenly disabled.
With this patch we always select a PTX version explicitly, whichever is higher between
The patch also re-enables the NVPTX target-feature test to catch such changes in the future.
It additionally forbids PTX and sm versions below Rust's minimum required versions by marking the corresponding target-features as
Forbidden.Lastly it adds PTX and sm versions present in LLVM 22 but missing as Rust target-features.
This will not prevent all issues. In fact, the following combinations might still miscompile:
cc: @kjetilkjeka
r? @ZuseZ4
@rustbot label +O-NVPTX