Conversation
Contributor
|
The code changes look mostly OK to me. The test changes also look OK right now at first reading, although it is a bit new for me to see a three pass opt pipeline instead of using -O1 in clang, but I see that it does demonstrate hoisting. I approved CI tests, so, I will await those results, and I'm curious about the performance impact of this change in the default pipeline. |
schittir
reviewed
Sep 16, 2026
| // A builtin with no side effects cannot trap and always | ||
| // returns, so it is safe to speculate. Without this, licm | ||
| // cannot hoist a call to it out of a conditional block. | ||
| if (Builtin.IsConst) { |
Contributor
There was a problem hiding this comment.
Is IsConst the right/precise enough check to add these attributes?
A SPIR-V builtin declared Attr.Const computes its result from its arguments alone, but clang only gives it memory(none) and willreturn. LLVM needs speculatable before it will move a call out of a conditional block, so licm cannot hoist such a call out of a loop. Mark those declarations speculatable and not convergent. The attribute goes on the declaration alone: a call site may carry speculatable only while its callee carries it too, which stops holding once a module that defines the builtin, such as libclc, is linked in.
mikaoP
force-pushed
the
spirv-builtins-speculatable
branch
from
September 16, 2026 16:13
0a7deb3 to
f3e5d50
Compare
| @@ -0,0 +1,22 @@ | |||
| // RUN: %clang_cc1 -triple spir64 -fdeclare-spirv-builtins -fconvergent-functions \ | |||
Contributor
There was a problem hiding this comment.
This should not be a FE test. The FileCheck is testing a pass (?) output, not what the FE is emitting. This should be moved wherever the pass is tested.
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.
A SPIR-V builtin declared Attr.Const computes its result from its arguments alone, but clang only gives it memory(none) and willreturn. LLVM needs speculatable before it will move a call out of a conditional block, so licm cannot hoist such a call out of a loop. Mark those declarations speculatable and not convergent.