Skip to content

Mark side-effect-free SPIR-V builtins as speculatable - #23176

Open
mikaoP wants to merge 1 commit into
intel:syclfrom
mikaoP:spirv-builtins-speculatable
Open

mikaoP wants to merge 1 commit into
intel:syclfrom
mikaoP:spirv-builtins-speculatable

Conversation

@mikaoP

@mikaoP mikaoP commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

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.

@mikaoP
mikaoP requested a review from a team as a code owner September 15, 2026 12:29
@schittir

schittir commented Sep 16, 2026

Copy link
Copy Markdown
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.

// 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
mikaoP force-pushed the spirv-builtins-speculatable branch from 0a7deb3 to f3e5d50 Compare September 16, 2026 16:13
@@ -0,0 +1,22 @@
// RUN: %clang_cc1 -triple spir64 -fdeclare-spirv-builtins -fconvergent-functions \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants