Skip to content

Commit 89b19c4

Browse files
authored
[SPIR-V 1.5] Deprecate OpLessOrGreater in favor of OpFOrdNotEqual (#2491)
This is a follow-up to 08884df
1 parent 7c85c6b commit 89b19c4

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6097,6 +6097,15 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
60976097
// Moreover, OpAtomicCompareExchangeWeak has been deprecated.
60986098
if (OC == OpAtomicCompareExchangeWeak)
60996099
OC = OpAtomicCompareExchange;
6100+
6101+
// We should do this replacement only for SPIR-V 1.5, as OpLessOrGreater is
6102+
// deprecated there. However we do such replacement for the usual pipeline
6103+
// (not via SPIR-V friendly calls) without minding the version, so we can do
6104+
// such thing here as well.
6105+
if (OC == OpLessOrGreater &&
6106+
BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_5))
6107+
OC = OpFOrdNotEqual;
6108+
61006109
if (isGroupOpCode(OC))
61016110
BM->addCapability(CapabilityGroups);
61026111
switch (static_cast<size_t>(OC)) {

test/transcoding/OpLessOrGreater.ll

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv %t.spv -to-text -o %t.spt
4+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
5+
; RUN: spirv-val %t.spv
6+
7+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
8+
; RUN: llvm-dis %t.rev.bc
9+
; RUN: FileCheck < %t.rev.ll %s --check-prefix=CHECK-LLVM
10+
11+
; SPIR-V 1.5
12+
; CHECK-SPIRV: 66816
13+
14+
; CHECK-SPIRV-NOT: LessOrGreater
15+
; CHECK-SPIRV: FOrdNotEqual
16+
17+
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
18+
target triple = "spir64-unknown-unknown"
19+
20+
; Function Attrs: nounwind
21+
define spir_kernel void @test(float %a) local_unnamed_addr #0 {
22+
entry:
23+
; CHECK-LLVM: fcmp one float %a, %a
24+
%call = tail call spir_func i1 @_Z21__spirv_LessOrGreater(float %a, float %a)
25+
ret void
26+
}
27+
28+
; This is needed to check that 1.5 is enabled
29+
define dso_local spir_kernel void @test2(i16 noundef signext %a, i32 noundef %id) local_unnamed_addr #0 {
30+
entry:
31+
%call = tail call spir_func signext i16 @_Z31sub_group_non_uniform_broadcastsj(i16 noundef signext %a, i32 noundef %id)
32+
ret void
33+
}
34+
35+
declare spir_func noundef i1 @_Z21__spirv_LessOrGreater(float, float)
36+
declare spir_func signext i16 @_Z31sub_group_non_uniform_broadcastsj(i16 noundef signext, i32 noundef)
37+
38+
attributes #0 = { convergent nounwind writeonly }
39+
40+
!llvm.module.flags = !{!0}
41+
!opencl.ocl.version = !{!1}
42+
!opencl.spir.version = !{!1}
43+
44+
!0 = !{i32 1, !"wchar_size", i32 4}
45+
!1 = !{i32 2, i32 0}

0 commit comments

Comments
 (0)