Skip to content

Conversation

@Flakebi
Copy link
Contributor

@Flakebi Flakebi commented Dec 4, 2025

GPU targets have convergent operations that require careful handling
when running optimizations. E.g. they must not be duplicated.

An example convergent operation is a barrier/syncthreads.

We do not want to deal with convergent operations in mir optimizations,
so set the optimization level to 0 and skip all optimizations.

On targets with convergent operations, we need to add the convergent
attribute to all functions that run convergent operations. Following
clang, we can conservatively apply the attribute to all functions when
compiling for such a target and rely on LLVM optimizing away the
attribute in cases where it is not necessary.

The amdgpu and nvptx targets are marked as having convergent operations.

Fixes #137086, see this issue for details.
Tracking issue: #135024

cc @RDambrosio016 @kjetilkjeka for nvptx
cc @ZuseZ4

@rustbot
Copy link
Collaborator

rustbot commented Dec 4, 2025

These commits modify compiler targets.
(See the Target Tier Policy.)

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 4, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 4, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

GPU targets have convergent operations that require careful handling
when running optimizations. E.g. they must not be duplicated.

An example convergent operation is a barrier/syncthreads.

We do not want to deal with convergent operations in mir optimizations,
so set the optimization level to 0 and skip all optimizations.

This affects the amdgpu and nvptx targets.
On targets with convergent operations, we need to add the convergent
attribute to all functions that run convergent operations. Following
clang, we can conservatively apply the attribute to all functions when
compiling for such a target and rely on LLVM optimizing away the
attribute in cases where it is not necessary.

This affects the amdgpu and nvptx targets.
@Flakebi Flakebi force-pushed the fix-convergent-mir-opts branch from 25d4193 to f17636b Compare December 4, 2025 21:40
@ZuseZ4 ZuseZ4 mentioned this pull request Dec 5, 2025
5 tasks
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. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

MIR passes do not take into account if an operation is convergent

6 participants