Skip to content

Commit 4abe3f1

Browse files
committed
[SPIRV] Fix bug in emitting GLSL ext inst names
Lookup extended instruction numbers in the given instruction set so that correct names are now emitted for GLSL.std.450 instructions as well as OpenCL.std. Add a single test to verify correct abs intrinsic names are emitted when targetting logical SPIR-V. Depends on D156424 Differential Revision: https://reviews.llvm.org/D159227
1 parent e15d72a commit 4abe3f1

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ getExtInstSetFromString(std::string SetName) {
217217
std::string getExtInstName(SPIRV::InstructionSet::InstructionSet Set,
218218
uint32_t InstructionNumber) {
219219
const SPIRV::ExtendedBuiltin *Lookup =
220-
SPIRV::lookupExtendedBuiltinBySetAndNumber(
221-
SPIRV::InstructionSet::OpenCL_std, InstructionNumber);
220+
SPIRV::lookupExtendedBuiltinBySetAndNumber(Set, InstructionNumber);
222221

223222
if (!Lookup)
224223
return "UNKNOWN_EXT_INST";
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: llc -O0 -mtriple=spirv-unknown-linux %s -o - | FileCheck %s
2+
3+
; CHECK: OpExtInstImport "GLSL.std.450"
4+
5+
define void @main() #1 {
6+
entry:
7+
%i = alloca i32, align 4
8+
%absi = alloca i32, align 4
9+
%f = alloca float, align 4
10+
%absf = alloca float, align 4
11+
%0 = load i32, ptr %i, align 4
12+
13+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] SAbs %[[#]]
14+
%elt.abs = call i32 @llvm.abs.i32(i32 %0, i1 false)
15+
16+
store i32 %elt.abs, ptr %absi, align 4
17+
%1 = load float, ptr %f, align 4
18+
19+
; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FAbs %[[#]]
20+
%elt.abs1 = call float @llvm.fabs.f32(float %1)
21+
22+
store float %elt.abs1, ptr %absf, align 4
23+
ret void
24+
}
25+
26+
declare i32 @llvm.abs.i32(i32, i1 immarg) #2
27+
declare float @llvm.fabs.f32(float) #2

0 commit comments

Comments
 (0)