[llvm] [SPIR-V] Don't consider a function be a builtin just by checking name (PR #182776)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 22 14:07:47 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-spir-v
Author: Dmitry Sidorov (MrSidims)
<details>
<summary>Changes</summary>
If a function has the same name as a (n OpenCL) builtin, but not matching number of arguments to the builtin - consider it to be a user function.
Fixes: https://github.com/llvm/llvm-project/issues/165237
---
Full diff: https://github.com/llvm/llvm-project/pull/182776.diff
2 Files Affected:
- (modified) llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp (+8-3)
- (added) llvm/test/CodeGen/SPIRV/user-function-with-builtin-name.ll (+12)
``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index 3123a6f9ffe77..e0a9a83f8e19b 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -3194,9 +3194,14 @@ std::optional<bool> lowerBuiltin(const StringRef DemangledCall,
return std::nullopt;
}
- // TODO: check if the provided args meet the builtin requirments.
- assert(Args.size() >= Call->Builtin->MinNumArgs &&
- "Too few arguments to generate the builtin");
+ // Check if the provided args meet the builtin requirements. If not, treat
+ // the call as a regular function call rather than crashing.
+ if (Args.size() < Call->Builtin->MinNumArgs) {
+ LLVM_DEBUG(dbgs() << "Too few arguments for builtin " << DemangledCall
+ << ": expected at least " << Call->Builtin->MinNumArgs
+ << ", got " << Args.size() << "\n");
+ return std::nullopt;
+ }
if (Call->Builtin->MaxNumArgs && Args.size() > Call->Builtin->MaxNumArgs)
LLVM_DEBUG(dbgs() << "More arguments provided than required!\n");
diff --git a/llvm/test/CodeGen/SPIRV/user-function-with-builtin-name.ll b/llvm/test/CodeGen/SPIRV/user-function-with-builtin-name.ll
new file mode 100644
index 0000000000000..9d150b8645cda
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/user-function-with-builtin-name.ll
@@ -0,0 +1,12 @@
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+
+; Verify that calling a function, that looks like a builtin, but has no matching
+; number of arguments is treated as user function.
+
+; CHECK: OpFunctionCall %[[#]] %[[#]]
+define spir_func void @test() {
+ call spir_func void @barrier()
+ ret void
+}
+
+declare spir_func void @barrier()
``````````
</details>
https://github.com/llvm/llvm-project/pull/182776
More information about the llvm-commits
mailing list