Skip to content

Commit 4f403e8

Browse files
[SPIR-V] Ensure that OpExtInst instructions generated by NonSemantic_Shader_DebugInfo_100 are not mixed up with other OpExtInst instructions (#107007)
This PR is to ensure that OpExtInst instructions generated by NonSemantic_Shader_DebugInfo_100 are not mixed up with other OpExtInst instructions. Original implementation (#97558) has introduced an issue by moving OpExtInst instruction with the 3rd operand equal to DebugSource (value 35) or DebugCompilationUnit (value 1) even if OpExtInst is not generated by NonSemantic_Shader_DebugInfo_100 implementation code. The reproducer is attached as a new test case. The code of the test case reproduces the issue, because "lgamma" has the same code (35) inside OpenCL_std as DebugSource inside NonSemantic_Shader_DebugInfo_100.
1 parent ebdadcf commit 4f403e8

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,10 @@ void SPIRVModuleAnalysis::processOtherInstrs(const Module &M) {
428428
const unsigned OpCode = MI.getOpcode();
429429
if (OpCode == SPIRV::OpString) {
430430
collectOtherInstr(MI, MAI, SPIRV::MB_DebugStrings, IS);
431-
} else if (OpCode == SPIRV::OpExtInst) {
431+
} else if (OpCode == SPIRV::OpExtInst && MI.getOperand(2).isImm() &&
432+
MI.getOperand(2).getImm() ==
433+
SPIRV::InstructionSet::
434+
NonSemantic_Shader_DebugInfo_100) {
432435
MachineOperand Ins = MI.getOperand(3);
433436
namespace NS = SPIRV::NonSemanticExtInst;
434437
static constexpr int64_t GlobalNonSemanticDITy[] = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; This test is to ensure that OpExtInst generated by NonSemantic_Shader_DebugInfo_100
2+
; are not mixed up with other OpExtInst instructions.
3+
; The code of the test is a reproducer, because "lgamma" has the same code (35)
4+
; inside OpenCL_std as DebugSource inside NonSemantic_Shader_DebugInfo_100.
5+
6+
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
7+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
8+
9+
; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s
10+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32-unknown-unknown %s -o - -filetype=obj | spirv-val %}
11+
12+
; CHECK: %[[#Ocl:]] = OpExtInstImport "OpenCL.std"
13+
; CHECK: OpName %[[#Fun:]] "__devicelib_lgammaf"
14+
; CHECK: %[[#Fun]] = OpFunction %[[#]] None %[[#]]
15+
; CHECK: OpFunctionParameter
16+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#Ocl]] lgamma %[[#]]
17+
18+
define weak_odr dso_local spir_kernel void @foo() {
19+
entry:
20+
%r = tail call spir_func noundef float @lgammaf(float noundef 0x7FF8000000000000)
21+
ret void
22+
}
23+
24+
define weak dso_local spir_func float @lgammaf(float noundef %x) {
25+
entry:
26+
%call = tail call spir_func float @__devicelib_lgammaf(float noundef %x)
27+
ret float %call
28+
}
29+
30+
define weak dso_local spir_func float @__devicelib_lgammaf(float noundef %x) {
31+
entry:
32+
%call = tail call spir_func noundef float @_Z18__spirv_ocl_lgammaf(float noundef %x)
33+
ret float %call
34+
}
35+
36+
declare dso_local spir_func noundef float @_Z18__spirv_ocl_lgammaf(float noundef)

0 commit comments

Comments
 (0)