Skip to content

Commit 4c58dc2

Browse files
committed
Update cl_ext_float_atomics patch
This fixes incorrect translation for FP-typed atomic_fetch_sub function and addes tests. Atomic functions which do not support floating types should be translted to FunctionCall such as atomic_inc and atomic_or and so on. When cl_ext_float_atomics is enabled, there are atomic_fetch_sub function declaration on clang headers, but there are no corresponding SPIRV Atomic instructions, so atomic_fetch_sub should be translted to FunctionCall as before. Signed-off-by: haonanya <[email protected]>
1 parent a2fc2a8 commit 4c58dc2

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

patches/spirv/0001-Add-support-for-cl_ext_float_atomics-in-SPIRVWriter.patch

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
From 8ba15d3b243584a005b3016fb4cd02e78a636a10 Mon Sep 17 00:00:00 2001
1+
From 1a155b4a98bef1ca74cb215db5c16a5259e9492a Mon Sep 17 00:00:00 2001
22
From: haonanya <[email protected]>
33
Date: Wed, 28 Jul 2021 11:43:20 +0800
44
Subject: [PATCH] Add support for cl_ext_float_atomics in SPIRVWriter
55

66
Signed-off-by: haonanya <[email protected]>
77
---
8-
lib/SPIRV/OCLToSPIRV.cpp | 27 +++++++-
9-
lib/SPIRV/OCLUtil.cpp | 19 +++---
10-
test/AtomicBuiltinsFloat.ll | 79 +++++++++++++++++++++++
8+
lib/SPIRV/OCLToSPIRV.cpp | 27 ++++++-
9+
lib/SPIRV/OCLUtil.cpp | 15 ++--
10+
test/AtomicBuiltinsFloat.ll | 94 +++++++++++++++++++++++++
1111
test/negative/InvalidAtomicBuiltins.cl | 20 +-----
12-
test/transcoding/AtomicFAddEXTForOCL.ll | 84 +++++++++++++++++++++++++
13-
test/transcoding/AtomicFMaxEXTForOCL.ll | 84 +++++++++++++++++++++++++
14-
test/transcoding/AtomicFMinEXTForOCL.ll | 83 ++++++++++++++++++++++++
15-
7 files changed, 368 insertions(+), 28 deletions(-)
12+
test/transcoding/AtomicFAddEXTForOCL.ll | 84 ++++++++++++++++++++++
13+
test/transcoding/AtomicFMaxEXTForOCL.ll | 84 ++++++++++++++++++++++
14+
test/transcoding/AtomicFMinEXTForOCL.ll | 83 ++++++++++++++++++++++
15+
7 files changed, 381 insertions(+), 26 deletions(-)
1616
create mode 100644 test/AtomicBuiltinsFloat.ll
1717
create mode 100644 test/transcoding/AtomicFAddEXTForOCL.ll
1818
create mode 100644 test/transcoding/AtomicFMaxEXTForOCL.ll
@@ -71,30 +71,28 @@ index d9ed4a7a..cadc2247 100644
7171
&Attrs);
7272
}
7373
diff --git a/lib/SPIRV/OCLUtil.cpp b/lib/SPIRV/OCLUtil.cpp
74-
index 2de3f152..2150a991 100644
74+
index 2de3f152..94e248c1 100644
7575
--- a/lib/SPIRV/OCLUtil.cpp
7676
+++ b/lib/SPIRV/OCLUtil.cpp
7777
@@ -662,29 +662,32 @@ size_t getSPIRVAtomicBuiltinNumMemoryOrderArgs(Op OC) {
7878
return 1;
7979
}
8080

81-
+// atomic_fetch_[add, sub, min, max] and atomic_fetch_[add, sub, min,
82-
+// max]_explicit functions are defined on OpenCL headers, they are not
83-
+// translated to function call
81+
+// atomic_fetch_[add, min, max] and atomic_fetch_[add, min, max]_explicit
82+
+// functions declared in clang headers should be translated to corresponding
83+
+// FP-typed Atomic Instructions
8484
bool isComputeAtomicOCLBuiltin(StringRef DemangledName) {
8585
if (!DemangledName.startswith(kOCLBuiltinName::AtomicPrefix) &&
8686
!DemangledName.startswith(kOCLBuiltinName::AtomPrefix))
8787
return false;
8888

8989
return llvm::StringSwitch<bool>(DemangledName)
9090
- .EndsWith("add", true)
91-
- .EndsWith("sub", true)
91+
.EndsWith("sub", true)
9292
+ .EndsWith("atomic_add", true)
93-
+ .EndsWith("atomic_sub", true)
9493
+ .EndsWith("atomic_min", true)
9594
+ .EndsWith("atomic_max", true)
9695
+ .EndsWith("atom_add", true)
97-
+ .EndsWith("atom_sub", true)
9896
+ .EndsWith("atom_min", true)
9997
+ .EndsWith("atom_max", true)
10098
.EndsWith("inc", true)
@@ -106,7 +104,7 @@ index 2de3f152..2150a991 100644
106104
.EndsWith("or", true)
107105
.EndsWith("xor", true)
108106
- .EndsWith("add_explicit", true)
109-
- .EndsWith("sub_explicit", true)
107+
.EndsWith("sub_explicit", true)
110108
.EndsWith("or_explicit", true)
111109
.EndsWith("xor_explicit", true)
112110
.EndsWith("and_explicit", true)
@@ -117,11 +115,13 @@ index 2de3f152..2150a991 100644
117115

118116
diff --git a/test/AtomicBuiltinsFloat.ll b/test/AtomicBuiltinsFloat.ll
119117
new file mode 100644
120-
index 00000000..d75bd012
118+
index 00000000..c85dd5b6
121119
--- /dev/null
122120
+++ b/test/AtomicBuiltinsFloat.ll
123-
@@ -0,0 +1,79 @@
121+
@@ -0,0 +1,94 @@
124122
+; Check that translator generate atomic instructions for atomic builtins
123+
+; FP-typed atomic_fetch_sub and atomic_fetch_sub_explicit should be translated
124+
+; to FunctionCall
125125
+; RUN: llvm-as %s -o %t.bc
126126
+; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s
127127
+; RUN: llvm-spirv %t.bc -o %t.spv
@@ -132,12 +132,13 @@ index 00000000..d75bd012
132132
+; CHECK-COUNT-3: AtomicStore
133133
+; CHECK-COUNT-3: AtomicLoad
134134
+; CHECK-COUNT-3: AtomicExchange
135+
+; CHECK-COUNT-3: FunctionCall
135136
+
136137
+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"
137138
+target triple = "spir-unknown-unknown"
138139
+
139140
+; Function Attrs: convergent norecurse nounwind
140-
+define spir_kernel void @test_atomic_kernel(float addrspace(3)* %ff, float addrspace(3)* nocapture readnone %a) local_unnamed_addr #0 !kernel_arg_addr_space !3 !kernel_arg_access_qual !4 !kernel_arg_type !5 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 {
141+
+define spir_kernel void @test_atomic_kernel(float addrspace(3)* %ff) local_unnamed_addr #0 !kernel_arg_addr_space !3 !kernel_arg_access_qual !4 !kernel_arg_type !5 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 {
141142
+entry:
142143
+ %0 = addrspacecast float addrspace(3)* %ff to float addrspace(4)*
143144
+ tail call spir_func void @_Z11atomic_initPU3AS4VU7_Atomicff(float addrspace(4)* %0, float 1.000000e+00) #2
@@ -150,6 +151,9 @@ index 00000000..d75bd012
150151
+ %call3 = tail call spir_func float @_Z15atomic_exchangePU3AS4VU7_Atomicff(float addrspace(4)* %0, float 1.000000e+00) #2
151152
+ %call4 = tail call spir_func float @_Z24atomic_exchange_explicitPU3AS4VU7_Atomicff12memory_order(float addrspace(4)* %0, float 1.000000e+00, i32 0) #2
152153
+ %call5 = tail call spir_func float @_Z24atomic_exchange_explicitPU3AS4VU7_Atomicff12memory_order12memory_scope(float addrspace(4)* %0, float 1.000000e+00, i32 0, i32 1) #2
154+
+ %call6 = tail call spir_func float @_Z16atomic_fetch_subPU3AS3VU7_Atomicff(float addrspace(3)* %ff, float 1.000000e+00) #2
155+
+ %call7 = tail call spir_func float @_Z25atomic_fetch_sub_explicitPU3AS3VU7_Atomicff12memory_order(float addrspace(3)* %ff, float 1.000000e+00, i32 0) #2
156+
+ %call8 = tail call spir_func float @_Z25atomic_fetch_sub_explicitPU3AS3VU7_Atomicff12memory_order12memory_scope(float addrspace(3)* %ff, float 1.000000e+00, i32 0, i32 1) #2
153157
+ ret void
154158
+}
155159
+
@@ -183,6 +187,15 @@ index 00000000..d75bd012
183187
+; Function Attrs: convergent
184188
+declare spir_func float @_Z24atomic_exchange_explicitPU3AS4VU7_Atomicff12memory_order12memory_scope(float addrspace(4)*, float, i32, i32) local_unnamed_addr #1
185189
+
190+
+; Function Attrs: convergent
191+
+declare spir_func float @_Z16atomic_fetch_subPU3AS3VU7_Atomicff(float addrspace(3)*, float) local_unnamed_addr #1
192+
+
193+
+; Function Attrs: convergent
194+
+declare spir_func float @_Z25atomic_fetch_sub_explicitPU3AS3VU7_Atomicff12memory_order(float addrspace(3)*, float, i32) local_unnamed_addr #1
195+
+
196+
+; Function Attrs: convergent
197+
+declare spir_func float @_Z25atomic_fetch_sub_explicitPU3AS3VU7_Atomicff12memory_order12memory_scope(float addrspace(3)*, float, i32, i32) local_unnamed_addr #1
198+
+
186199
+attributes #0 = { convergent norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
187200
+attributes #1 = { convergent "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
188201
+attributes #2 = { convergent nounwind }
@@ -194,12 +207,12 @@ index 00000000..d75bd012
194207
+
195208
+!0 = !{i32 1, !"wchar_size", i32 4}
196209
+!1 = !{i32 2, i32 0}
197-
+!2 = !{!"clang version 11.1.0 (https://github.com/llvm/llvm-project.git 15c8e1468997ba90943155d35475b2aaeea65f19)"}
198-
+!3 = !{i32 3, i32 3}
199-
+!4 = !{!"none", !"none"}
200-
+!5 = !{!"atomic_float*", !"float*"}
201-
+!6 = !{!"_Atomic(float)*", !"float*"}
202-
+!7 = !{!"volatile", !""}
210+
+!2 = !{!"clang version 11.1.0 (4989da43e3648ed25a272773165367f195d3b53c)"}
211+
+!3 = !{i32 3}
212+
+!4 = !{!"none"}
213+
+!5 = !{!"atomic_float*"}
214+
+!6 = !{!"_Atomic(float)*"}
215+
+!7 = !{!"volatile"}
203216
diff --git a/test/negative/InvalidAtomicBuiltins.cl b/test/negative/InvalidAtomicBuiltins.cl
204217
index b8ec5b89..18d11bf5 100644
205218
--- a/test/negative/InvalidAtomicBuiltins.cl

0 commit comments

Comments
 (0)