Debian Codegraph @

test/opt/upgrade_memory_model_test.cpp

raw
1 // Copyright (c) 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "assembly_builder.h"
16 #include "pass_fixture.h"
17 #include "pass_utils.h"
18
19 namespace {
20
21 using namespace spvtools;
22
23 using UpgradeMemoryModelTest = opt::PassTest<::testing::Test>;
24
25 TEST_F(UpgradeMemoryModelTest, InvalidMemoryModelOpenCL) {
26 const std::string text = R"(
27 ; CHECK: OpMemoryModel Logical OpenCL
28 OpCapability Kernel
29 OpCapability Linkage
30 OpMemoryModel Logical OpenCL
31 )";
32
33 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
34 }
35
36 TEST_F(UpgradeMemoryModelTest, InvalidMemoryModelVulkan) {
37 const std::string text = R"(
38 ; CHECK: OpMemoryModel Logical Vulkan
39 OpCapability Shader
40 OpCapability Linkage
41 OpCapability VulkanMemoryModel
42 OpExtension "SPV_KHR_vulkan_memory_model"
43 OpMemoryModel Logical Vulkan
44 )";
45
46 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
47 }
48
49 TEST_F(UpgradeMemoryModelTest, JustMemoryModel) {
50 const std::string text = R"(
51 ; CHECK: OpCapability VulkanMemoryModel
52 ; CHECK: OpExtension "SPV_KHR_vulkan_memory_model"
53 ; CHECK: OpMemoryModel Logical Vulkan
54 OpCapability Shader
55 OpCapability Linkage
56 OpMemoryModel Logical GLSL450
57 )";
58
59 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
60 }
61
62 TEST_F(UpgradeMemoryModelTest, RemoveDecorations) {
63 const std::string text = R"(
64 ; CHECK-NOT: OpDecorate
65 OpCapability Shader
66 OpCapability Linkage
67 OpMemoryModel Logical GLSL450
68 OpDecorate %var Volatile
69 OpDecorate %var Coherent
70 %int = OpTypeInt 32 0
71 %ptr_int_Uniform = OpTypePointer Uniform %int
72 %var = OpVariable %ptr_int_Uniform Uniform
73 )";
74
75 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
76 }
77
78 TEST_F(UpgradeMemoryModelTest, WorkgroupVariable) {
79 const std::string text = R"(
80 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 2
81 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
82 ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]]
83 OpCapability Shader
84 OpCapability Linkage
85 OpMemoryModel Logical GLSL450
86 %void = OpTypeVoid
87 %int = OpTypeInt 32 0
88 %ptr_int_Workgroup = OpTypePointer Workgroup %int
89 %var = OpVariable %ptr_int_Workgroup Workgroup
90 %func_ty = OpTypeFunction %void
91 %func = OpFunction %void None %func_ty
92 %1 = OpLabel
93 %ld = OpLoad %int %var
94 OpStore %var %ld
95 OpReturn
96 OpFunctionEnd
97 )";
98
99 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
100 }
101
102 TEST_F(UpgradeMemoryModelTest, WorkgroupFunctionParameter) {
103 const std::string text = R"(
104 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 2
105 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
106 ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]]
107 OpCapability Shader
108 OpCapability Linkage
109 OpMemoryModel Logical GLSL450
110 %void = OpTypeVoid
111 %int = OpTypeInt 32 0
112 %ptr_int_Workgroup = OpTypePointer Workgroup %int
113 %func_ty = OpTypeFunction %void %ptr_int_Workgroup
114 %func = OpFunction %void None %func_ty
115 %param = OpFunctionParameter %ptr_int_Workgroup
116 %1 = OpLabel
117 %ld = OpLoad %int %param
118 OpStore %param %ld
119 OpReturn
120 OpFunctionEnd
121 )";
122
123 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
124 }
125
126 TEST_F(UpgradeMemoryModelTest, SimpleUniformVariable) {
127 const std::string text = R"(
128 ; CHECK-NOT: OpDecorate
129 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
130 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]]
131 ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]]
132 OpCapability Shader
133 OpCapability Linkage
134 OpMemoryModel Logical GLSL450
135 OpDecorate %var Coherent
136 OpDecorate %var Volatile
137 %void = OpTypeVoid
138 %int = OpTypeInt 32 0
139 %ptr_int_Uniform = OpTypePointer Uniform %int
140 %var = OpVariable %ptr_int_Uniform Uniform
141 %func_ty = OpTypeFunction %void
142 %func = OpFunction %void None %func_ty
143 %1 = OpLabel
144 %ld = OpLoad %int %var
145 OpStore %var %ld
146 OpReturn
147 OpFunctionEnd
148 )";
149
150 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
151 }
152
153 TEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameter) {
154 const std::string text = R"(
155 ; CHECK-NOT: OpDecorate
156 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
157 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]]
158 ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]]
159 OpCapability Shader
160 OpCapability Linkage
161 OpMemoryModel Logical GLSL450
162 OpDecorate %param Coherent
163 OpDecorate %param Volatile
164 %void = OpTypeVoid
165 %int = OpTypeInt 32 0
166 %ptr_int_Uniform = OpTypePointer Uniform %int
167 %func_ty = OpTypeFunction %void %ptr_int_Uniform
168 %func = OpFunction %void None %func_ty
169 %param = OpFunctionParameter %ptr_int_Uniform
170 %1 = OpLabel
171 %ld = OpLoad %int %param
172 OpStore %param %ld
173 OpReturn
174 OpFunctionEnd
175 )";
176
177 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
178 }
179
180 TEST_F(UpgradeMemoryModelTest, SimpleUniformVariableOnlyVolatile) {
181 const std::string text = R"(
182 ; CHECK-NOT: OpDecorate
183 ; CHECK-NOT: OpConstant
184 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
185 ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile
186 OpCapability Shader
187 OpCapability Linkage
188 OpMemoryModel Logical GLSL450
189 OpDecorate %var Volatile
190 %void = OpTypeVoid
191 %int = OpTypeInt 32 0
192 %ptr_int_Uniform = OpTypePointer Uniform %int
193 %var = OpVariable %ptr_int_Uniform Uniform
194 %func_ty = OpTypeFunction %void
195 %func = OpFunction %void None %func_ty
196 %1 = OpLabel
197 %ld = OpLoad %int %var
198 OpStore %var %ld
199 OpReturn
200 OpFunctionEnd
201 )";
202
203 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
204 }
205
206 TEST_F(UpgradeMemoryModelTest, SimpleUniformVariableCopied) {
207 const std::string text = R"(
208 ; CHECK-NOT: OpDecorate
209 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
210 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]]
211 ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]]
212 OpCapability Shader
213 OpCapability Linkage
214 OpMemoryModel Logical GLSL450
215 OpDecorate %var Coherent
216 OpDecorate %var Volatile
217 %void = OpTypeVoid
218 %int = OpTypeInt 32 0
219 %ptr_int_Uniform = OpTypePointer Uniform %int
220 %var = OpVariable %ptr_int_Uniform Uniform
221 %func_ty = OpTypeFunction %void
222 %func = OpFunction %void None %func_ty
223 %1 = OpLabel
224 %copy = OpCopyObject %ptr_int_Uniform %var
225 %ld = OpLoad %int %copy
226 OpStore %copy %ld
227 OpReturn
228 OpFunctionEnd
229 )";
230
231 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
232 }
233
234 TEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameterCopied) {
235 const std::string text = R"(
236 ; CHECK-NOT: OpDecorate
237 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
238 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]]
239 ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]]
240 OpCapability Shader
241 OpCapability Linkage
242 OpMemoryModel Logical GLSL450
243 OpDecorate %param Coherent
244 OpDecorate %param Volatile
245 %void = OpTypeVoid
246 %int = OpTypeInt 32 0
247 %ptr_int_Uniform = OpTypePointer Uniform %int
248 %func_ty = OpTypeFunction %void %ptr_int_Uniform
249 %func = OpFunction %void None %func_ty
250 %param = OpFunctionParameter %ptr_int_Uniform
251 %1 = OpLabel
252 %copy = OpCopyObject %ptr_int_Uniform %param
253 %ld = OpLoad %int %copy
254 %copy2 = OpCopyObject %ptr_int_Uniform %param
255 OpStore %copy2 %ld
256 OpReturn
257 OpFunctionEnd
258 )";
259
260 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
261 }
262
263 TEST_F(UpgradeMemoryModelTest, SimpleUniformVariableAccessChain) {
264 const std::string text = R"(
265 ; CHECK-NOT: OpDecorate
266 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
267 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]]
268 ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]]
269 OpCapability Shader
270 OpCapability Linkage
271 OpMemoryModel Logical GLSL450
272 OpDecorate %var Coherent
273 OpDecorate %var Volatile
274 %void = OpTypeVoid
275 %int = OpTypeInt 32 0
276 %int0 = OpConstant %int 0
277 %int3 = OpConstant %int 3
278 %int_array_3 = OpTypeArray %int %int3
279 %ptr_intarray_Uniform = OpTypePointer Uniform %int_array_3
280 %ptr_int_Uniform = OpTypePointer Uniform %int
281 %var = OpVariable %ptr_intarray_Uniform Uniform
282 %func_ty = OpTypeFunction %void
283 %func = OpFunction %void None %func_ty
284 %1 = OpLabel
285 %gep = OpAccessChain %ptr_int_Uniform %var %int0
286 %ld = OpLoad %int %gep
287 OpStore %gep %ld
288 OpReturn
289 OpFunctionEnd
290 )";
291
292 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
293 }
294
295 TEST_F(UpgradeMemoryModelTest, SimpleUniformFunctionParameterAccessChain) {
296 const std::string text = R"(
297 ; CHECK-NOT: OpDecorate
298 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
299 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]]
300 ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]]
301 OpCapability Shader
302 OpCapability Linkage
303 OpMemoryModel Logical GLSL450
304 OpDecorate %param Coherent
305 OpDecorate %param Volatile
306 %void = OpTypeVoid
307 %int = OpTypeInt 32 0
308 %int0 = OpConstant %int 0
309 %int3 = OpConstant %int 3
310 %int_array_3 = OpTypeArray %int %int3
311 %ptr_intarray_Uniform = OpTypePointer Uniform %int_array_3
312 %ptr_int_Uniform = OpTypePointer Uniform %int
313 %func_ty = OpTypeFunction %void %ptr_intarray_Uniform
314 %func = OpFunction %void None %func_ty
315 %param = OpFunctionParameter %ptr_intarray_Uniform
316 %1 = OpLabel
317 %ld_gep = OpAccessChain %ptr_int_Uniform %param %int0
318 %ld = OpLoad %int %ld_gep
319 %st_gep = OpAccessChain %ptr_int_Uniform %param %int0
320 OpStore %st_gep %ld
321 OpReturn
322 OpFunctionEnd
323 )";
324
325 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
326 }
327
328 TEST_F(UpgradeMemoryModelTest, VariablePointerSelect) {
329 const std::string text = R"(
330 ; CHECK-NOT: OpDecorate
331 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
332 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]]
333 ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]]
334 OpCapability Shader
335 OpCapability Linkage
336 OpCapability VariablePointers
337 OpExtension "SPV_KHR_variable_pointers"
338 OpMemoryModel Logical GLSL450
339 OpDecorate %var Coherent
340 OpDecorate %var Volatile
341 %void = OpTypeVoid
342 %int = OpTypeInt 32 0
343 %bool = OpTypeBool
344 %true = OpConstantTrue %bool
345 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
346 %null = OpConstantNull %ptr_int_StorageBuffer
347 %var = OpVariable %ptr_int_StorageBuffer StorageBuffer
348 %func_ty = OpTypeFunction %void
349 %func = OpFunction %void None %func_ty
350 %1 = OpLabel
351 %select = OpSelect %ptr_int_StorageBuffer %true %var %null
352 %ld = OpLoad %int %select
353 OpStore %var %ld
354 OpReturn
355 OpFunctionEnd
356 )";
357
358 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
359 }
360
361 TEST_F(UpgradeMemoryModelTest, VariablePointerSelectConservative) {
362 const std::string text = R"(
363 ; CHECK-NOT: OpDecorate
364 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
365 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[scope]]
366 ; CHECK: OpStore {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[scope]]
367 OpCapability Shader
368 OpCapability Linkage
369 OpCapability VariablePointers
370 OpExtension "SPV_KHR_variable_pointers"
371 OpMemoryModel Logical GLSL450
372 OpDecorate %var1 Coherent
373 OpDecorate %var2 Volatile
374 %void = OpTypeVoid
375 %int = OpTypeInt 32 0
376 %bool = OpTypeBool
377 %true = OpConstantTrue %bool
378 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
379 %var1 = OpVariable %ptr_int_StorageBuffer StorageBuffer
380 %var2 = OpVariable %ptr_int_StorageBuffer StorageBuffer
381 %func_ty = OpTypeFunction %void
382 %func = OpFunction %void None %func_ty
383 %1 = OpLabel
384 %select = OpSelect %ptr_int_StorageBuffer %true %var1 %var2
385 %ld = OpLoad %int %select
386 OpStore %select %ld
387 OpReturn
388 OpFunctionEnd
389 )";
390
391 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
392 }
393
394 TEST_F(UpgradeMemoryModelTest, VariablePointerIncrement) {
395 const std::string text = R"(
396 ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
397 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
398 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
399 ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]]
400 OpCapability Shader
401 OpCapability Linkage
402 OpCapability VariablePointers
403 OpExtension "SPV_KHR_variable_pointers"
404 OpMemoryModel Logical GLSL450
405 OpDecorate %param Coherent
406 OpDecorate %ptr_int_StorageBuffer ArrayStride 4
407 %void = OpTypeVoid
408 %bool = OpTypeBool
409 %int = OpTypeInt 32 0
410 %int0 = OpConstant %int 0
411 %int1 = OpConstant %int 1
412 %int10 = OpConstant %int 10
413 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
414 %func_ty = OpTypeFunction %void %ptr_int_StorageBuffer
415 %func = OpFunction %void None %func_ty
416 %param = OpFunctionParameter %ptr_int_StorageBuffer
417 %1 = OpLabel
418 OpBranch %2
419 %2 = OpLabel
420 %phi = OpPhi %ptr_int_StorageBuffer %param %1 %ptr_next %2
421 %iv = OpPhi %int %int0 %1 %inc %2
422 %inc = OpIAdd %int %iv %int1
423 %ptr_next = OpPtrAccessChain %ptr_int_StorageBuffer %phi %int1
424 %cmp = OpIEqual %bool %iv %int10
425 OpLoopMerge %3 %2 None
426 OpBranchConditional %cmp %3 %2
427 %3 = OpLabel
428 %ld = OpLoad %int %phi
429 OpStore %phi %ld
430 OpReturn
431 OpFunctionEnd
432 )";
433
434 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
435 }
436
437 TEST_F(UpgradeMemoryModelTest, VariablePointerStoreToFunctionAndPrivate) {
438 const std::string text = R"(
439 ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
440 ; CHECK-NOT: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer {{%\w+}}
441 OpCapability Shader
442 OpCapability Linkage
443 OpCapability VariablePointersStorageBuffer
444 OpExtension "SPV_KHR_variable_pointers"
445 OpMemoryModel Logical GLSL450
446 OpDecorate %_runtimearr_uint ArrayStride 4
447 OpMemberDecorate %_struct_4 0 Offset 0
448 OpMemberDecorate %_struct_4 0 Coherent
449 OpDecorate %_struct_4 Block
450 %void = OpTypeVoid
451 %uint = OpTypeInt 32 0
452 %_runtimearr_uint = OpTypeRuntimeArray %uint
453 %_struct_4 = OpTypeStruct %_runtimearr_uint
454 %_ptr_StorageBuffer__struct_4 = OpTypePointer StorageBuffer %_struct_4
455 %_ptr_Function_uint = OpTypePointer Function %uint
456 %_ptr_Function__ptr_StorageBuffer__struct_4 = OpTypePointer Function %_ptr_StorageBuffer__struct_4
457 %functy = OpTypeFunction %void %_ptr_Function__ptr_StorageBuffer__struct_4 %_ptr_Function_uint
458 %_ptr_Private__ptr_StorageBuffer__struct_4 = OpTypePointer Private %_ptr_StorageBuffer__struct_4
459 %var_bufPtr_pri = OpVariable %_ptr_Private__ptr_StorageBuffer__struct_4 Private
460 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
461 %func = OpFunction %void None %functy
462 %param_buf = OpFunctionParameter %_ptr_Function__ptr_StorageBuffer__struct_4
463 %bb_entry = OpLabel
464 %buf = OpLoad %_ptr_StorageBuffer__struct_4 %param_buf
465 OpStore %param_buf %buf
466 OpStore %var_bufPtr_pri %buf
467 OpReturn
468 OpFunctionEnd
469 )";
470 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
471 }
472
473 TEST_F(UpgradeMemoryModelTest, VariablePointerIndirectLoad) {
474 const std::string text = R"(
475 ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
476 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
477 ; CHECK: [[buffer:%\w+]] = OpLoad {{%\w+}} {{%\w+}}
478 ; CHECK: [[ld_gep:%\w+]] = OpAccessChain {{%\w+}} [[buffer]] {{%\w+}} {{%\w+}}
479 ; CHECK: OpLoad {{%\w+}} [[ld_gep]] MakePointerVisible|NonPrivatePointer [[scope]]
480 OpCapability Shader
481 OpCapability Linkage
482 OpCapability VariablePointersStorageBuffer
483 OpExtension "SPV_KHR_variable_pointers"
484 OpMemoryModel Logical GLSL450
485 OpDecorate %_runtimearr_uint ArrayStride 4
486 OpMemberDecorate %_struct_4 0 Offset 0
487 OpMemberDecorate %_struct_4 0 Coherent
488 OpDecorate %_struct_4 Block
489 %uint = OpTypeInt 32 0
490 %uint_0 = OpConstant %uint 0
491 %_runtimearr_uint = OpTypeRuntimeArray %uint
492 %_struct_4 = OpTypeStruct %_runtimearr_uint
493 %_ptr_StorageBuffer__struct_4 = OpTypePointer StorageBuffer %_struct_4
494 %_ptr_Function_uint = OpTypePointer Function %uint
495 %_ptr_Function__ptr_StorageBuffer__struct_4 = OpTypePointer Function %_ptr_StorageBuffer__struct_4
496 %functy = OpTypeFunction %uint %_ptr_Function__ptr_StorageBuffer__struct_4 %_ptr_Function_uint
497 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
498 %func = OpFunction %uint None %functy
499 %param_buf = OpFunctionParameter %_ptr_Function__ptr_StorageBuffer__struct_4
500 %param_offset = OpFunctionParameter %_ptr_Function_uint
501 %bb_entry = OpLabel
502 %buf = OpLoad %_ptr_StorageBuffer__struct_4 %param_buf
503 %offset = OpLoad %uint %param_offset
504 %ld_gep = OpAccessChain %_ptr_StorageBuffer_uint %buf %uint_0 %offset
505 %data = OpLoad %uint %ld_gep
506 OpReturnValue %data
507 OpFunctionEnd
508 )";
509 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
510 }
511
512 TEST_F(UpgradeMemoryModelTest, VariablePointerIndirectLoadWithPrivateAS) {
513 const std::string text = R"(
514 ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
515 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
516 ; CHECK: [[ld_gep:%\w+]] = OpAccessChain {{%\w+}} [[buffer:%\w+]] {{%\w+}} {{%\w+}}
517 ; CHECK: OpLoad {{%\w+}} [[ld_gep]] MakePointerVisible|NonPrivatePointer [[scope]]
518 OpCapability Shader
519 OpCapability Linkage
520 OpCapability VariablePointersStorageBuffer
521 OpExtension "SPV_KHR_variable_pointers"
522 OpMemoryModel Logical GLSL450
523 OpDecorate %_runtimearr_uint ArrayStride 4
524 OpMemberDecorate %_struct_4 0 Offset 0
525 OpMemberDecorate %_struct_4 0 Coherent
526 OpDecorate %_struct_4 Block
527 %uint = OpTypeInt 32 0
528 %uint_0 = OpConstant %uint 0
529 %_runtimearr_uint = OpTypeRuntimeArray %uint
530 %_struct_4 = OpTypeStruct %_runtimearr_uint
531 %_ptr_StorageBuffer__struct_4 = OpTypePointer StorageBuffer %_struct_4
532 %_ptr_Function_uint = OpTypePointer Function %uint
533 %_ptr_Function__ptr_StorageBuffer__struct_4 = OpTypePointer Function %_ptr_StorageBuffer__struct_4
534 %_ptr_Private__ptr_StorageBuffer__struct_4 = OpTypePointer Private %_ptr_StorageBuffer__struct_4
535 %var_bufPtr_pri = OpVariable %_ptr_Private__ptr_StorageBuffer__struct_4 Private
536 %functy = OpTypeFunction %uint %_ptr_Function__ptr_StorageBuffer__struct_4 %_ptr_Function_uint
537 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
538 %func = OpFunction %uint None %functy
539 %param_buf = OpFunctionParameter %_ptr_Function__ptr_StorageBuffer__struct_4
540 %param_offset = OpFunctionParameter %_ptr_Function_uint
541 %bb_entry = OpLabel
542 %buf0 = OpLoad %_ptr_StorageBuffer__struct_4 %param_buf
543 OpStore %var_bufPtr_pri %buf0
544 %offset = OpLoad %uint %param_offset
545 %buf1 = OpLoad %_ptr_StorageBuffer__struct_4 %var_bufPtr_pri
546 %ld_gep = OpAccessChain %_ptr_StorageBuffer_uint %buf1 %uint_0 %offset
547 %data = OpLoad %uint %ld_gep
548 OpReturnValue %data
549 OpFunctionEnd
550 )";
551 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
552 }
553
554 TEST_F(UpgradeMemoryModelTest, VariablePointerIndirectStore) {
555 const std::string text = R"(
556 ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
557 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
558 ; CHECK: [[st_gep:%\w+]] = OpAccessChain
559 ; CHECK: OpStore [[st_gep]] {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]]
560 OpCapability Shader
561 OpCapability Linkage
562 OpCapability VariablePointersStorageBuffer
563 OpExtension "SPV_KHR_variable_pointers"
564 OpMemoryModel Logical GLSL450
565 OpDecorate %_runtimearr_uint ArrayStride 4
566 OpMemberDecorate %_struct_4 0 Offset 0
567 OpMemberDecorate %_struct_4 0 Coherent
568 OpDecorate %_struct_4 Block
569 %uint = OpTypeInt 32 0
570 %void = OpTypeVoid
571 %uint_0 = OpConstant %uint 0
572 %_runtimearr_uint = OpTypeRuntimeArray %uint
573 %_struct_4 = OpTypeStruct %_runtimearr_uint
574 %_ptr_StorageBuffer__struct_4 = OpTypePointer StorageBuffer %_struct_4
575 %_ptr_Function_uint = OpTypePointer Function %uint
576 %_ptr_Function__ptr_StorageBuffer__struct_4 = OpTypePointer Function %_ptr_StorageBuffer__struct_4
577 %functy = OpTypeFunction %void %_ptr_Function__ptr_StorageBuffer__struct_4 %_ptr_Function_uint
578 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
579 %func = OpFunction %void None %functy
580 %param_buf = OpFunctionParameter %_ptr_Function__ptr_StorageBuffer__struct_4
581 %param_offset = OpFunctionParameter %_ptr_Function_uint
582 %bb_entry = OpLabel
583 %buf = OpLoad %_ptr_StorageBuffer__struct_4 %param_buf
584 %offset = OpLoad %uint %param_offset
585 %st_gep = OpAccessChain %_ptr_StorageBuffer_uint %buf %uint_0 %offset
586 OpStore %st_gep %uint_0
587 OpReturn
588 OpFunctionEnd
589 )";
590 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
591 }
592
593 TEST_F(UpgradeMemoryModelTest, VariablePointerIndirectStoreWithPrivateAS) {
594 const std::string text = R"(
595 ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
596 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
597 ; CHECK: [[st_gep:%\w+]] = OpAccessChain
598 ; CHECK: OpStore [[st_gep]] {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]]
599 OpCapability Shader
600 OpCapability Linkage
601 OpCapability VariablePointersStorageBuffer
602 OpExtension "SPV_KHR_variable_pointers"
603 OpMemoryModel Logical GLSL450
604 OpDecorate %_runtimearr_uint ArrayStride 4
605 OpMemberDecorate %_struct_4 0 Offset 0
606 OpMemberDecorate %_struct_4 0 Coherent
607 OpDecorate %_struct_4 Block
608 %uint = OpTypeInt 32 0
609 %void = OpTypeVoid
610 %uint_0 = OpConstant %uint 0
611 %_runtimearr_uint = OpTypeRuntimeArray %uint
612 %_struct_4 = OpTypeStruct %_runtimearr_uint
613 %_ptr_StorageBuffer__struct_4 = OpTypePointer StorageBuffer %_struct_4
614 %_ptr_Function_uint = OpTypePointer Function %uint
615 %_ptr_Function__ptr_StorageBuffer__struct_4 = OpTypePointer Function %_ptr_StorageBuffer__struct_4
616 %_ptr_Private__ptr_StorageBuffer__struct_4 = OpTypePointer Private %_ptr_StorageBuffer__struct_4
617 %var_bufPtr_pri = OpVariable %_ptr_Private__ptr_StorageBuffer__struct_4 Private
618 %functy = OpTypeFunction %void %_ptr_Function__ptr_StorageBuffer__struct_4 %_ptr_Function_uint
619 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
620 %func = OpFunction %void None %functy
621 %param_buf = OpFunctionParameter %_ptr_Function__ptr_StorageBuffer__struct_4
622 %param_offset = OpFunctionParameter %_ptr_Function_uint
623 %bb_entry = OpLabel
624 %buf0 = OpLoad %_ptr_StorageBuffer__struct_4 %param_buf
625 OpStore %var_bufPtr_pri %buf0
626 %offset = OpLoad %uint %param_offset
627 %buf1 = OpLoad %_ptr_StorageBuffer__struct_4 %var_bufPtr_pri
628 %st_gep = OpAccessChain %_ptr_StorageBuffer_uint %buf1 %uint_0 %offset
629 OpStore %st_gep %uint_0
630 OpReturn
631 OpFunctionEnd
632 )";
633 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
634 }
635
636 TEST_F(UpgradeMemoryModelTest, VariablePointerIndirectSelect) {
637 const std::string text = R"(
638 ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
639 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
640 ; CHECK: [[buffer:%\w+]] = OpSelect {{%\w+}} {{%\w+}}
641 ; CHECK: [[ld_gep:%\w+]] = OpAccessChain {{%\w+}} [[buffer]] {{%\w+}} {{%\w+}}
642 ; CHECK: OpLoad {{%\w+}} [[ld_gep]] MakePointerVisible|NonPrivatePointer [[scope]]
643 OpCapability Shader
644 OpCapability Linkage
645 OpCapability VariablePointersStorageBuffer
646 OpExtension "SPV_KHR_variable_pointers"
647 OpMemoryModel Logical GLSL450
648 OpDecorate %_runtimearr_uint ArrayStride 4
649 OpMemberDecorate %_struct_4 0 Offset 0
650 OpMemberDecorate %_struct_4 0 Coherent
651 OpDecorate %_struct_4 Block
652 %uint = OpTypeInt 32 0
653 %uint_0 = OpConstant %uint 0
654 %bool = OpTypeBool
655 %true = OpConstantTrue %bool
656 %_runtimearr_uint = OpTypeRuntimeArray %uint
657 %_struct_4 = OpTypeStruct %_runtimearr_uint
658 %_ptr_StorageBuffer__struct_4 = OpTypePointer StorageBuffer %_struct_4
659 %_ptr_Function_uint = OpTypePointer Function %uint
660 %_ptr_Function__ptr_StorageBuffer__struct_4 = OpTypePointer Function %_ptr_StorageBuffer__struct_4
661 %functy = OpTypeFunction %uint %_ptr_Function__ptr_StorageBuffer__struct_4 %_ptr_Function_uint
662 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
663 %null = OpConstantNull %_ptr_StorageBuffer__struct_4
664 %func = OpFunction %uint None %functy
665 %param_buf = OpFunctionParameter %_ptr_Function__ptr_StorageBuffer__struct_4
666 %param_offset = OpFunctionParameter %_ptr_Function_uint
667 %bb_entry = OpLabel
668 %buf = OpLoad %_ptr_StorageBuffer__struct_4 %param_buf
669 %select = OpSelect %_ptr_StorageBuffer__struct_4 %true %buf %null
670 %offset = OpLoad %uint %param_offset
671 %ld_gep = OpAccessChain %_ptr_StorageBuffer_uint %select %uint_0 %offset
672 %data = OpLoad %uint %ld_gep
673 OpReturnValue %data
674 OpFunctionEnd
675 )";
676 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
677 }
678
679 TEST_F(UpgradeMemoryModelTest, VariablePointerIndirectCopied) {
680 const std::string text = R"(
681 ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
682 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
683 ; CHECK: [[buffer:%\w+]] = OpLoad {{%\w+}} {{%\w+}}
684 ; CHECK: [[ld_gep:%\w+]] = OpAccessChain {{%\w+}} [[buffer]] {{%\w+}} {{%\w+}}
685 ; CHECK: OpLoad {{%\w+}} [[ld_gep]] MakePointerVisible|NonPrivatePointer [[scope]]
686 OpCapability Shader
687 OpCapability Linkage
688 OpCapability VariablePointersStorageBuffer
689 OpExtension "SPV_KHR_variable_pointers"
690 OpMemoryModel Logical GLSL450
691 OpDecorate %_runtimearr_uint ArrayStride 4
692 OpMemberDecorate %_struct_4 0 Offset 0
693 OpMemberDecorate %_struct_4 0 Coherent
694 OpDecorate %_struct_4 Block
695 %uint = OpTypeInt 32 0
696 %uint_0 = OpConstant %uint 0
697 %_runtimearr_uint = OpTypeRuntimeArray %uint
698 %_struct_4 = OpTypeStruct %_runtimearr_uint
699 %_ptr_StorageBuffer__struct_4 = OpTypePointer StorageBuffer %_struct_4
700 %_ptr_Function_uint = OpTypePointer Function %uint
701 %_ptr_Function__ptr_StorageBuffer__struct_4 = OpTypePointer Function %_ptr_StorageBuffer__struct_4
702 %functy = OpTypeFunction %uint %_ptr_Function__ptr_StorageBuffer__struct_4 %_ptr_Function_uint
703 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
704 %func = OpFunction %uint None %functy
705 %param_buf = OpFunctionParameter %_ptr_Function__ptr_StorageBuffer__struct_4
706 %param_offset = OpFunctionParameter %_ptr_Function_uint
707 %bb_entry = OpLabel
708 %copy = OpCopyObject %_ptr_Function__ptr_StorageBuffer__struct_4 %param_buf
709 %buf = OpLoad %_ptr_StorageBuffer__struct_4 %copy
710 %offset = OpLoad %uint %param_offset
711 %ld_gep = OpAccessChain %_ptr_StorageBuffer_uint %buf %uint_0 %offset
712 %data = OpLoad %uint %ld_gep
713 OpReturnValue %data
714 OpFunctionEnd
715 )";
716 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
717 }
718
719 TEST_F(UpgradeMemoryModelTest, VariablePointerIndirectPhi) {
720 const std::string text = R"(
721 ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
722 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
723 ; CHECK: [[buffer:%\w+]] = OpPhi {{%\w+}} {{%\w+}}
724 ; CHECK: [[ld_gep:%\w+]] = OpAccessChain {{%\w+}} [[buffer]] {{%\w+}} {{%\w+}}
725 ; CHECK: OpLoad {{%\w+}} [[ld_gep]] MakePointerVisible|NonPrivatePointer [[scope]]
726 OpCapability Shader
727 OpCapability Linkage
728 OpCapability VariablePointersStorageBuffer
729 OpExtension "SPV_KHR_variable_pointers"
730 OpMemoryModel Logical GLSL450
731 OpDecorate %_runtimearr_uint ArrayStride 4
732 OpMemberDecorate %_struct_4 0 Offset 0
733 OpMemberDecorate %_struct_4 0 Coherent
734 OpDecorate %_struct_4 Block
735 %uint = OpTypeInt 32 0
736 %uint_0 = OpConstant %uint 0
737 %bool = OpTypeBool
738 %true = OpConstantTrue %bool
739 %_runtimearr_uint = OpTypeRuntimeArray %uint
740 %_struct_4 = OpTypeStruct %_runtimearr_uint
741 %_ptr_StorageBuffer__struct_4 = OpTypePointer StorageBuffer %_struct_4
742 %_ptr_Function_uint = OpTypePointer Function %uint
743 %_ptr_Function__ptr_StorageBuffer__struct_4 = OpTypePointer Function %_ptr_StorageBuffer__struct_4
744 %functy = OpTypeFunction %uint %_ptr_Function__ptr_StorageBuffer__struct_4 %_ptr_Function_uint
745 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
746 %null = OpConstantNull %_ptr_StorageBuffer__struct_4
747 %func = OpFunction %uint None %functy
748 %param_buf = OpFunctionParameter %_ptr_Function__ptr_StorageBuffer__struct_4
749 %param_offset = OpFunctionParameter %_ptr_Function_uint
750 %bb_entry = OpLabel
751 %buf = OpLoad %_ptr_StorageBuffer__struct_4 %param_buf
752 OpSelectionMerge %bb_end None
753 OpBranchConditional %true %bb_then %bb_else
754 %bb_then = OpLabel
755 OpBranch %bb_end
756 %bb_else = OpLabel
757 OpBranch %bb_end
758 %bb_end = OpLabel
759 %phi_buf_ptr = OpPhi %_ptr_StorageBuffer__struct_4 %buf %bb_then %null %bb_else
760 %offset = OpLoad %uint %param_offset
761 %ld_gep = OpAccessChain %_ptr_StorageBuffer_uint %phi_buf_ptr %uint_0 %offset
762 %data = OpLoad %uint %ld_gep
763 OpReturnValue %data
764 OpFunctionEnd
765 )";
766 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
767 }
768
769 TEST_F(UpgradeMemoryModelTest, VariablePointerIndirectFuncCall) {
770 const std::string text = R"(
771 ; CHECK-NOT: OpDecorate {{%\w+}} Coherent
772 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
773 ; CHECK: [[buffer:%\w+]] = OpLoad {{%\w+}} {{%\w+}}
774 ; CHECK: [[ld_gep:%\w+]] = OpAccessChain {{%\w+}} [[buffer]] {{%\w+}} {{%\w+}}
775 ; CHECK: OpLoad {{%\w+}} [[ld_gep]] MakePointerVisible|NonPrivatePointer [[scope]]
776 ; CHECK: [[buffer2:%\w+]] = OpLoad {{%\w+}} {{%\w+}} Volatile
777 ; CHECK: [[ld_gep2:%\w+]] = OpAccessChain {{%\w+}} [[buffer2]] {{%\w+}} {{%\w+}}
778 ; CHECK: OpLoad {{%\w+}} [[ld_gep2]] Volatile|MakePointerVisible|NonPrivatePointer [[scope]]
779 OpCapability Shader
780 OpCapability Linkage
781 OpCapability VariablePointersStorageBuffer
782 OpExtension "SPV_KHR_variable_pointers"
783 OpMemoryModel Logical GLSL450
784 OpDecorate %_runtimearr_uint ArrayStride 4
785 OpMemberDecorate %_struct_4 0 Offset 0
786 OpDecorate %_struct_4 Block
787 OpDecorate %param_buf Coherent
788 OpDecorate %param_buf_1 Coherent
789 OpDecorate %param_buf_1 Volatile
790 %uint = OpTypeInt 32 0
791 %uint_0 = OpConstant %uint 0
792 %uint_1024 = OpConstant %uint 1024
793 %_runtimearr_uint = OpTypeRuntimeArray %uint
794 %_struct_4 = OpTypeStruct %_runtimearr_uint
795 %_ptr_StorageBuffer__struct_4 = OpTypePointer StorageBuffer %_struct_4
796 %_ptr_Function_uint = OpTypePointer Function %uint
797 %_ptr_Function__ptr_StorageBuffer__struct_4 = OpTypePointer Function %_ptr_StorageBuffer__struct_4
798 %functy = OpTypeFunction %uint %_ptr_Function__ptr_StorageBuffer__struct_4 %_ptr_Function_uint
799 %local_functy = OpTypeFunction %uint %_ptr_Function__ptr_StorageBuffer__struct_4
800 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
801 %func = OpFunction %uint None %functy
802 %param_buf = OpFunctionParameter %_ptr_Function__ptr_StorageBuffer__struct_4
803 %param_offset = OpFunctionParameter %_ptr_Function_uint
804 %bb_entry = OpLabel
805 %buf = OpLoad %_ptr_StorageBuffer__struct_4 %param_buf
806 %offset = OpLoad %uint %param_offset
807 %ld_gep = OpAccessChain %_ptr_StorageBuffer_uint %buf %uint_0 %offset
808 %data = OpLoad %uint %ld_gep
809 %data_2 = OpFunctionCall %uint %local_func %param_buf
810 %ret = OpIAdd %uint %data %data_2
811 OpReturnValue %ret
812 OpFunctionEnd
813 %local_func = OpFunction %uint None %local_functy
814 %param_buf_1 = OpFunctionParameter %_ptr_Function__ptr_StorageBuffer__struct_4
815 %bb_entry_1 = OpLabel
816 %buf_1 = OpLoad %_ptr_StorageBuffer__struct_4 %param_buf_1
817 %ld_gep_1 = OpAccessChain %_ptr_StorageBuffer_uint %buf_1 %uint_0 %uint_1024
818 %data_1 = OpLoad %uint %ld_gep_1
819 OpReturnValue %data_1
820 OpFunctionEnd
821 )";
822 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
823 }
824
825 TEST_F(UpgradeMemoryModelTest, CoherentStructElement) {
826 const std::string text = R"(
827 ; CHECK-NOT: OpMemberDecorate
828 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
829 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
830 ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]]
831 OpCapability Shader
832 OpCapability Linkage
833 OpExtension "SPV_KHR_storage_buffer_storage_class"
834 OpMemoryModel Logical GLSL450
835 OpMemberDecorate %struct 0 Coherent
836 %void = OpTypeVoid
837 %int = OpTypeInt 32 0
838 %int0 = OpConstant %int 0
839 %struct = OpTypeStruct %int
840 %ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct
841 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
842 %func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer
843 %func = OpFunction %void None %func_ty
844 %param = OpFunctionParameter %ptr_struct_StorageBuffer
845 %1 = OpLabel
846 %gep = OpAccessChain %ptr_int_StorageBuffer %param %int0
847 %ld = OpLoad %int %gep
848 OpStore %gep %ld
849 OpReturn
850 OpFunctionEnd
851 )";
852
853 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
854 }
855
856 TEST_F(UpgradeMemoryModelTest, CoherentElementFullStructAccess) {
857 const std::string text = R"(
858 ; CHECK-NOT: OpMemberDecorate
859 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
860 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
861 ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]]
862 OpCapability Shader
863 OpCapability Linkage
864 OpExtension "SPV_KHR_storage_buffer_storage_class"
865 OpMemoryModel Logical GLSL450
866 OpMemberDecorate %struct 0 Coherent
867 %void = OpTypeVoid
868 %int = OpTypeInt 32 0
869 %struct = OpTypeStruct %int
870 %ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct
871 %func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer
872 %func = OpFunction %void None %func_ty
873 %param = OpFunctionParameter %ptr_struct_StorageBuffer
874 %1 = OpLabel
875 %ld = OpLoad %struct %param
876 OpStore %param %ld
877 OpReturn
878 OpFunctionEnd
879 )";
880
881 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
882 }
883
884 TEST_F(UpgradeMemoryModelTest, CoherentElementNotAccessed) {
885 const std::string text = R"(
886 ; CHECK-NOT: OpMemberDecorate
887 ; CHECK-NOT: MakePointerAvailable
888 ; CHECK-NOT: NonPrivatePointer
889 ; CHECK-NOT: MakePointerVisible
890 OpCapability Shader
891 OpCapability Linkage
892 OpExtension "SPV_KHR_storage_buffer_storage_class"
893 OpMemoryModel Logical GLSL450
894 OpMemberDecorate %struct 1 Coherent
895 %void = OpTypeVoid
896 %int = OpTypeInt 32 0
897 %int0 = OpConstant %int 0
898 %struct = OpTypeStruct %int %int
899 %ptr_struct_StorageBuffer = OpTypePointer StorageBuffer %struct
900 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
901 %func_ty = OpTypeFunction %void %ptr_struct_StorageBuffer
902 %func = OpFunction %void None %func_ty
903 %param = OpFunctionParameter %ptr_struct_StorageBuffer
904 %1 = OpLabel
905 %gep = OpAccessChain %ptr_int_StorageBuffer %param %int0
906 %ld = OpLoad %int %gep
907 OpStore %gep %ld
908 OpReturn
909 OpFunctionEnd
910 )";
911
912 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
913 }
914
915 TEST_F(UpgradeMemoryModelTest, MultiIndexAccessCoherent) {
916 const std::string text = R"(
917 ; CHECK-NOT: OpMemberDecorate
918 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
919 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
920 ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]]
921 OpCapability Shader
922 OpCapability Linkage
923 OpExtension "SPV_KHR_storage_buffer_storage_class"
924 OpMemoryModel Logical GLSL450
925 OpMemberDecorate %inner 1 Coherent
926 %void = OpTypeVoid
927 %int = OpTypeInt 32 0
928 %int0 = OpConstant %int 0
929 %int1 = OpConstant %int 1
930 %inner = OpTypeStruct %int %int
931 %middle = OpTypeStruct %inner
932 %outer = OpTypeStruct %middle %middle
933 %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
934 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
935 %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
936 %func = OpFunction %void None %func_ty
937 %param = OpFunctionParameter %ptr_outer_StorageBuffer
938 %1 = OpLabel
939 %ld_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int0 %int0 %int1
940 %ld = OpLoad %int %ld_gep
941 %st_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int1 %int0 %int1
942 OpStore %st_gep %ld
943 OpReturn
944 OpFunctionEnd
945 )";
946
947 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
948 }
949
950 TEST_F(UpgradeMemoryModelTest, MultiIndexAccessNonCoherent) {
951 const std::string text = R"(
952 ; CHECK-NOT: OpMemberDecorate
953 ; CHECK-NOT: MakePointerAvailable
954 ; CHECK-NOT: NonPrivatePointer
955 ; CHECK-NOT: MakePointerVisible
956 OpCapability Shader
957 OpCapability Linkage
958 OpExtension "SPV_KHR_storage_buffer_storage_class"
959 OpMemoryModel Logical GLSL450
960 OpMemberDecorate %inner 1 Coherent
961 %void = OpTypeVoid
962 %int = OpTypeInt 32 0
963 %int0 = OpConstant %int 0
964 %int1 = OpConstant %int 1
965 %inner = OpTypeStruct %int %int
966 %middle = OpTypeStruct %inner
967 %outer = OpTypeStruct %middle %middle
968 %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
969 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
970 %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
971 %func = OpFunction %void None %func_ty
972 %param = OpFunctionParameter %ptr_outer_StorageBuffer
973 %1 = OpLabel
974 %ld_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int0 %int0 %int0
975 %ld = OpLoad %int %ld_gep
976 %st_gep = OpInBoundsAccessChain %ptr_int_StorageBuffer %param %int1 %int0 %int0
977 OpStore %st_gep %ld
978 OpReturn
979 OpFunctionEnd
980 )";
981
982 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
983 }
984
985 TEST_F(UpgradeMemoryModelTest, ConsecutiveAccessChainCoherent) {
986 const std::string text = R"(
987 ; CHECK-NOT: OpMemberDecorate
988 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
989 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
990 ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]]
991 OpCapability Shader
992 OpCapability Linkage
993 OpExtension "SPV_KHR_storage_buffer_storage_class"
994 OpMemoryModel Logical GLSL450
995 OpMemberDecorate %inner 1 Coherent
996 %void = OpTypeVoid
997 %int = OpTypeInt 32 0
998 %int0 = OpConstant %int 0
999 %int1 = OpConstant %int 1
1000 %inner = OpTypeStruct %int %int
1001 %middle = OpTypeStruct %inner
1002 %outer = OpTypeStruct %middle %middle
1003 %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
1004 %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
1005 %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
1006 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
1007 %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
1008 %func = OpFunction %void None %func_ty
1009 %param = OpFunctionParameter %ptr_outer_StorageBuffer
1010 %1 = OpLabel
1011 %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
1012 %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
1013 %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1
1014 %ld = OpLoad %int %ld_gep3
1015 %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
1016 %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
1017 %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1
1018 OpStore %st_gep3 %ld
1019 OpReturn
1020 OpFunctionEnd
1021 )";
1022
1023 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1024 }
1025
1026 TEST_F(UpgradeMemoryModelTest, ConsecutiveAccessChainNonCoherent) {
1027 const std::string text = R"(
1028 ; CHECK-NOT: OpMemberDecorate
1029 ; CHECK-NOT: MakePointerAvailable
1030 ; CHECK-NOT: NonPrivatePointer
1031 ; CHECK-NOT: MakePointerVisible
1032 OpCapability Shader
1033 OpCapability Linkage
1034 OpExtension "SPV_KHR_storage_buffer_storage_class"
1035 OpMemoryModel Logical GLSL450
1036 OpMemberDecorate %inner 1 Coherent
1037 %void = OpTypeVoid
1038 %int = OpTypeInt 32 0
1039 %int0 = OpConstant %int 0
1040 %int1 = OpConstant %int 1
1041 %inner = OpTypeStruct %int %int
1042 %middle = OpTypeStruct %inner
1043 %outer = OpTypeStruct %middle %middle
1044 %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
1045 %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
1046 %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
1047 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
1048 %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
1049 %func = OpFunction %void None %func_ty
1050 %param = OpFunctionParameter %ptr_outer_StorageBuffer
1051 %1 = OpLabel
1052 %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
1053 %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
1054 %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int0
1055 %ld = OpLoad %int %ld_gep3
1056 %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
1057 %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
1058 %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int0
1059 OpStore %st_gep3 %ld
1060 OpReturn
1061 OpFunctionEnd
1062 )";
1063
1064 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1065 }
1066
1067 TEST_F(UpgradeMemoryModelTest, CoherentStructElementAccess) {
1068 const std::string text = R"(
1069 ; CHECK-NOT: OpMemberDecorate
1070 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
1071 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
1072 ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]]
1073 OpCapability Shader
1074 OpCapability Linkage
1075 OpExtension "SPV_KHR_storage_buffer_storage_class"
1076 OpMemoryModel Logical GLSL450
1077 OpMemberDecorate %middle 0 Coherent
1078 %void = OpTypeVoid
1079 %int = OpTypeInt 32 0
1080 %int0 = OpConstant %int 0
1081 %int1 = OpConstant %int 1
1082 %inner = OpTypeStruct %int %int
1083 %middle = OpTypeStruct %inner
1084 %outer = OpTypeStruct %middle %middle
1085 %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
1086 %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
1087 %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
1088 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
1089 %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
1090 %func = OpFunction %void None %func_ty
1091 %param = OpFunctionParameter %ptr_outer_StorageBuffer
1092 %1 = OpLabel
1093 %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
1094 %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
1095 %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1
1096 %ld = OpLoad %int %ld_gep3
1097 %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
1098 %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
1099 %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1
1100 OpStore %st_gep3 %ld
1101 OpReturn
1102 OpFunctionEnd
1103 )";
1104
1105 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1106 }
1107
1108 TEST_F(UpgradeMemoryModelTest, NonCoherentLoadCoherentStore) {
1109 const std::string text = R"(
1110 ; CHECK-NOT: OpMemberDecorate
1111 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
1112 ; CHECK-NOT: MakePointerVisible
1113 ; CHECK: OpStore {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]]
1114 OpCapability Shader
1115 OpCapability Linkage
1116 OpExtension "SPV_KHR_storage_buffer_storage_class"
1117 OpMemoryModel Logical GLSL450
1118 OpMemberDecorate %outer 1 Coherent
1119 %void = OpTypeVoid
1120 %int = OpTypeInt 32 0
1121 %int0 = OpConstant %int 0
1122 %int1 = OpConstant %int 1
1123 %inner = OpTypeStruct %int %int
1124 %middle = OpTypeStruct %inner
1125 %outer = OpTypeStruct %middle %middle
1126 %ptr_outer_StorageBuffer = OpTypePointer StorageBuffer %outer
1127 %ptr_middle_StorageBuffer = OpTypePointer StorageBuffer %middle
1128 %ptr_inner_StorageBuffer = OpTypePointer StorageBuffer %inner
1129 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
1130 %func_ty = OpTypeFunction %void %ptr_outer_StorageBuffer
1131 %func = OpFunction %void None %func_ty
1132 %param = OpFunctionParameter %ptr_outer_StorageBuffer
1133 %1 = OpLabel
1134 %ld_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int0
1135 %ld_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %ld_gep1 %int0
1136 %ld_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %ld_gep2 %int1
1137 %ld = OpLoad %int %ld_gep3
1138 %st_gep1 = OpInBoundsAccessChain %ptr_middle_StorageBuffer %param %int1
1139 %st_gep2 = OpInBoundsAccessChain %ptr_inner_StorageBuffer %st_gep1 %int0
1140 %st_gep3 = OpInBoundsAccessChain %ptr_int_StorageBuffer %st_gep2 %int1
1141 OpStore %st_gep3 %ld
1142 OpReturn
1143 OpFunctionEnd
1144 )";
1145
1146 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1147 }
1148
1149 TEST_F(UpgradeMemoryModelTest, CopyMemory) {
1150 const std::string text = R"(
1151 ; CHECK-NOT: OpDecorate
1152 ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
1153 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Volatile|MakePointerVisible|NonPrivatePointer [[queuefamily]]
1154 ; CHECK-NOT: [[queuefamily]]
1155 OpCapability Shader
1156 OpCapability Linkage
1157 OpExtension "SPV_KHR_storage_buffer_storage_class"
1158 OpMemoryModel Logical GLSL450
1159 OpDecorate %in_var Coherent
1160 OpDecorate %out_var Volatile
1161 %void = OpTypeVoid
1162 %int = OpTypeInt 32 0
1163 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
1164 %in_var = OpVariable %ptr_int_StorageBuffer StorageBuffer
1165 %out_var = OpVariable %ptr_int_StorageBuffer StorageBuffer
1166 %func_ty = OpTypeFunction %void
1167 %func = OpFunction %void None %func_ty
1168 %1 = OpLabel
1169 OpCopyMemory %out_var %in_var
1170 OpReturn
1171 OpFunctionEnd
1172 )";
1173
1174 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1175 }
1176
1177 TEST_F(UpgradeMemoryModelTest, CopyMemorySized) {
1178 const std::string text = R"(
1179 ; CHECK-NOT: OpDecorate
1180 ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
1181 ; CHECK: OpCopyMemorySized {{%\w+}} {{%\w+}} {{%\w+}} Volatile|MakePointerAvailable|NonPrivatePointer [[queuefamily]]
1182 ; CHECK-NOT: [[queuefamily]]
1183 OpCapability Shader
1184 OpCapability Linkage
1185 OpCapability Addresses
1186 OpExtension "SPV_KHR_storage_buffer_storage_class"
1187 OpMemoryModel Logical GLSL450
1188 OpDecorate %out_param Coherent
1189 OpDecorate %in_param Volatile
1190 %void = OpTypeVoid
1191 %int = OpTypeInt 32 0
1192 %int4 = OpConstant %int 4
1193 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
1194 %func_ty = OpTypeFunction %void %ptr_int_StorageBuffer %ptr_int_StorageBuffer
1195 %func = OpFunction %void None %func_ty
1196 %in_param = OpFunctionParameter %ptr_int_StorageBuffer
1197 %out_param = OpFunctionParameter %ptr_int_StorageBuffer
1198 %1 = OpLabel
1199 OpCopyMemorySized %out_param %in_param %int4
1200 OpReturn
1201 OpFunctionEnd
1202 )";
1203
1204 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1205 }
1206
1207 TEST_F(UpgradeMemoryModelTest, CopyMemoryTwoScopes) {
1208 const std::string text = R"(
1209 ; CHECK-NOT: OpDecorate
1210 ; CHECK-DAG: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5
1211 ; CHECK-DAG: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2
1212 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} MakePointerAvailable|MakePointerVisible|NonPrivatePointer [[workgroup]] [[queuefamily]]
1213 OpCapability Shader
1214 OpCapability Linkage
1215 OpExtension "SPV_KHR_storage_buffer_storage_class"
1216 OpMemoryModel Logical GLSL450
1217 OpDecorate %in_var Coherent
1218 OpDecorate %out_var Coherent
1219 %void = OpTypeVoid
1220 %int = OpTypeInt 32 0
1221 %ptr_int_Workgroup = OpTypePointer Workgroup %int
1222 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
1223 %in_var = OpVariable %ptr_int_StorageBuffer StorageBuffer
1224 %out_var = OpVariable %ptr_int_Workgroup Workgroup
1225 %func_ty = OpTypeFunction %void
1226 %func = OpFunction %void None %func_ty
1227 %1 = OpLabel
1228 OpCopyMemory %out_var %in_var
1229 OpReturn
1230 OpFunctionEnd
1231 )";
1232
1233 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1234 }
1235
1236 TEST_F(UpgradeMemoryModelTest, VolatileImageRead) {
1237 const std::string text = R"(
1238 ; CHECK-NOT: OpDecorate
1239 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
1240 ; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexel
1241 OpCapability Shader
1242 OpCapability Linkage
1243 OpCapability StorageImageReadWithoutFormat
1244 OpExtension "SPV_KHR_storage_buffer_storage_class"
1245 OpMemoryModel Logical GLSL450
1246 OpDecorate %var Volatile
1247 %void = OpTypeVoid
1248 %int = OpTypeInt 32 0
1249 %v2int = OpTypeVector %int 2
1250 %float = OpTypeFloat 32
1251 %int0 = OpConstant %int 0
1252 %v2int_0 = OpConstantComposite %v2int %int0 %int0
1253 %image = OpTypeImage %float 2D 0 0 0 2 Unknown
1254 %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
1255 %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
1256 %func_ty = OpTypeFunction %void
1257 %func = OpFunction %void None %func_ty
1258 %1 = OpLabel
1259 %ld = OpLoad %image %var
1260 %rd = OpImageRead %float %ld %v2int_0
1261 OpReturn
1262 OpFunctionEnd
1263 )";
1264
1265 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1266 }
1267
1268 TEST_F(UpgradeMemoryModelTest, CoherentImageRead) {
1269 const std::string text = R"(
1270 ; CHECK-NOT: OpDecorate
1271 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
1272 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
1273 ; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisible|NonPrivateTexel [[scope]]
1274 OpCapability Shader
1275 OpCapability Linkage
1276 OpCapability StorageImageReadWithoutFormat
1277 OpExtension "SPV_KHR_storage_buffer_storage_class"
1278 OpMemoryModel Logical GLSL450
1279 OpDecorate %var Coherent
1280 %void = OpTypeVoid
1281 %int = OpTypeInt 32 0
1282 %v2int = OpTypeVector %int 2
1283 %float = OpTypeFloat 32
1284 %int0 = OpConstant %int 0
1285 %v2int_0 = OpConstantComposite %v2int %int0 %int0
1286 %image = OpTypeImage %float 2D 0 0 0 2 Unknown
1287 %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
1288 %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
1289 %func_ty = OpTypeFunction %void
1290 %func = OpFunction %void None %func_ty
1291 %1 = OpLabel
1292 %ld = OpLoad %image %var
1293 %rd = OpImageRead %float %ld %v2int_0
1294 OpReturn
1295 OpFunctionEnd
1296 )";
1297
1298 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1299 }
1300
1301 TEST_F(UpgradeMemoryModelTest, CoherentImageReadExtractedFromSampledImage) {
1302 const std::string text = R"(
1303 ; CHECK-NOT: OpDecorate
1304 ; CHECK: [[image:%\w+]] = OpTypeImage
1305 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
1306 ; CHECK: OpLoad [[image]] {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
1307 ; CHECK-NOT: NonPrivatePointer
1308 ; CHECK: OpImageRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisible|NonPrivateTexel [[scope]]
1309 OpCapability Shader
1310 OpCapability Linkage
1311 OpCapability StorageImageReadWithoutFormat
1312 OpExtension "SPV_KHR_storage_buffer_storage_class"
1313 OpMemoryModel Logical GLSL450
1314 OpDecorate %var Coherent
1315 %void = OpTypeVoid
1316 %int = OpTypeInt 32 0
1317 %v2int = OpTypeVector %int 2
1318 %float = OpTypeFloat 32
1319 %int0 = OpConstant %int 0
1320 %v2int_0 = OpConstantComposite %v2int %int0 %int0
1321 %image = OpTypeImage %float 2D 0 0 0 0 Unknown
1322 %sampled_image = OpTypeSampledImage %image
1323 %sampler = OpTypeSampler
1324 %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
1325 %ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler
1326 %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
1327 %sampler_var = OpVariable %ptr_sampler_StorageBuffer StorageBuffer
1328 %func_ty = OpTypeFunction %void
1329 %func = OpFunction %void None %func_ty
1330 %1 = OpLabel
1331 %ld = OpLoad %image %var
1332 %ld_sampler = OpLoad %sampler %sampler_var
1333 %sample = OpSampledImage %sampled_image %ld %ld_sampler
1334 %extract = OpImage %image %sample
1335 %rd = OpImageRead %float %extract %v2int_0
1336 OpReturn
1337 OpFunctionEnd
1338 )";
1339
1340 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1341 }
1342
1343 TEST_F(UpgradeMemoryModelTest, VolatileImageWrite) {
1344 const std::string text = R"(
1345 ; CHECK-NOT: OpDecorate
1346 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
1347 ; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexel
1348 OpCapability Shader
1349 OpCapability Linkage
1350 OpCapability StorageImageWriteWithoutFormat
1351 OpExtension "SPV_KHR_storage_buffer_storage_class"
1352 OpMemoryModel Logical GLSL450
1353 OpDecorate %param Volatile
1354 %void = OpTypeVoid
1355 %int = OpTypeInt 32 0
1356 %v2int = OpTypeVector %int 2
1357 %float = OpTypeFloat 32
1358 %float0 = OpConstant %float 0
1359 %v2int_null = OpConstantNull %v2int
1360 %image = OpTypeImage %float 2D 0 0 0 0 Unknown
1361 %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
1362 %func_ty = OpTypeFunction %void %ptr_image_StorageBuffer
1363 %func = OpFunction %void None %func_ty
1364 %param = OpFunctionParameter %ptr_image_StorageBuffer
1365 %1 = OpLabel
1366 %ld = OpLoad %image %param
1367 OpImageWrite %ld %v2int_null %float0
1368 OpReturn
1369 OpFunctionEnd
1370 )";
1371
1372 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1373 }
1374
1375 TEST_F(UpgradeMemoryModelTest, CoherentImageWrite) {
1376 const std::string text = R"(
1377 ; CHECK-NOT: OpDecorate
1378 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
1379 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer
1380 ; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelAvailable|NonPrivateTexel [[scope]]
1381 OpCapability Shader
1382 OpCapability Linkage
1383 OpCapability StorageImageWriteWithoutFormat
1384 OpExtension "SPV_KHR_storage_buffer_storage_class"
1385 OpMemoryModel Logical GLSL450
1386 OpDecorate %param Coherent
1387 %void = OpTypeVoid
1388 %int = OpTypeInt 32 0
1389 %v2int = OpTypeVector %int 2
1390 %float = OpTypeFloat 32
1391 %float0 = OpConstant %float 0
1392 %v2int_null = OpConstantNull %v2int
1393 %image = OpTypeImage %float 2D 0 0 0 0 Unknown
1394 %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
1395 %func_ty = OpTypeFunction %void %ptr_image_StorageBuffer
1396 %func = OpFunction %void None %func_ty
1397 %param = OpFunctionParameter %ptr_image_StorageBuffer
1398 %1 = OpLabel
1399 %ld = OpLoad %image %param
1400 OpImageWrite %ld %v2int_null %float0
1401 OpReturn
1402 OpFunctionEnd
1403 )";
1404
1405 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1406 }
1407
1408 TEST_F(UpgradeMemoryModelTest, CoherentImageWriteExtractFromSampledImage) {
1409 const std::string text = R"(
1410 ; CHECK-NOT: OpDecorate
1411 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
1412 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer
1413 ; CHECK-NOT: NonPrivatePointer
1414 ; CHECK: OpImageWrite {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelAvailable|NonPrivateTexel [[scope]]
1415 OpCapability Shader
1416 OpCapability Linkage
1417 OpCapability StorageImageWriteWithoutFormat
1418 OpExtension "SPV_KHR_storage_buffer_storage_class"
1419 OpMemoryModel Logical GLSL450
1420 OpDecorate %param Coherent
1421 %void = OpTypeVoid
1422 %int = OpTypeInt 32 0
1423 %v2int = OpTypeVector %int 2
1424 %float = OpTypeFloat 32
1425 %float0 = OpConstant %float 0
1426 %v2int_null = OpConstantNull %v2int
1427 %image = OpTypeImage %float 2D 0 0 0 0 Unknown
1428 %sampled_image = OpTypeSampledImage %image
1429 %sampler = OpTypeSampler
1430 %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
1431 %ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler
1432 %func_ty = OpTypeFunction %void %ptr_image_StorageBuffer %ptr_sampler_StorageBuffer
1433 %func = OpFunction %void None %func_ty
1434 %param = OpFunctionParameter %ptr_image_StorageBuffer
1435 %sampler_param = OpFunctionParameter %ptr_sampler_StorageBuffer
1436 %1 = OpLabel
1437 %ld = OpLoad %image %param
1438 %ld_sampler = OpLoad %sampler %sampler_param
1439 %sample = OpSampledImage %sampled_image %ld %ld_sampler
1440 %extract = OpImage %image %sample
1441 OpImageWrite %extract %v2int_null %float0
1442 OpReturn
1443 OpFunctionEnd
1444 )";
1445
1446 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1447 }
1448
1449 TEST_F(UpgradeMemoryModelTest, VolatileImageSparseRead) {
1450 const std::string text = R"(
1451 ; CHECK-NOT: OpDecorate
1452 ; CHECK: OpLoad {{%\w+}} {{%\w+}} Volatile
1453 ; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} VolatileTexel
1454 OpCapability Shader
1455 OpCapability Linkage
1456 OpCapability StorageImageReadWithoutFormat
1457 OpCapability SparseResidency
1458 OpExtension "SPV_KHR_storage_buffer_storage_class"
1459 OpMemoryModel Logical GLSL450
1460 OpDecorate %var Volatile
1461 %void = OpTypeVoid
1462 %int = OpTypeInt 32 0
1463 %v2int = OpTypeVector %int 2
1464 %float = OpTypeFloat 32
1465 %int0 = OpConstant %int 0
1466 %v2int_0 = OpConstantComposite %v2int %int0 %int0
1467 %image = OpTypeImage %float 2D 0 0 0 2 Unknown
1468 %struct = OpTypeStruct %int %float
1469 %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
1470 %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
1471 %func_ty = OpTypeFunction %void
1472 %func = OpFunction %void None %func_ty
1473 %1 = OpLabel
1474 %ld = OpLoad %image %var
1475 %rd = OpImageSparseRead %struct %ld %v2int_0
1476 OpReturn
1477 OpFunctionEnd
1478 )";
1479
1480 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1481 }
1482
1483 TEST_F(UpgradeMemoryModelTest, CoherentImageSparseRead) {
1484 const std::string text = R"(
1485 ; CHECK-NOT: OpDecorate
1486 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
1487 ; CHECK: OpLoad {{%\w+}} {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
1488 ; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisible|NonPrivateTexel [[scope]]
1489 OpCapability Shader
1490 OpCapability Linkage
1491 OpCapability StorageImageReadWithoutFormat
1492 OpCapability SparseResidency
1493 OpExtension "SPV_KHR_storage_buffer_storage_class"
1494 OpMemoryModel Logical GLSL450
1495 OpDecorate %var Coherent
1496 %void = OpTypeVoid
1497 %int = OpTypeInt 32 0
1498 %v2int = OpTypeVector %int 2
1499 %float = OpTypeFloat 32
1500 %int0 = OpConstant %int 0
1501 %v2int_0 = OpConstantComposite %v2int %int0 %int0
1502 %image = OpTypeImage %float 2D 0 0 0 2 Unknown
1503 %struct = OpTypeStruct %int %float
1504 %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
1505 %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
1506 %func_ty = OpTypeFunction %void
1507 %func = OpFunction %void None %func_ty
1508 %1 = OpLabel
1509 %ld = OpLoad %image %var
1510 %rd = OpImageSparseRead %struct %ld %v2int_0
1511 OpReturn
1512 OpFunctionEnd
1513 )";
1514
1515 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1516 }
1517
1518 TEST_F(UpgradeMemoryModelTest,
1519 CoherentImageSparseReadExtractedFromSampledImage) {
1520 const std::string text = R"(
1521 ; CHECK-NOT: OpDecorate
1522 ; CHECK: [[image:%\w+]] = OpTypeImage
1523 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
1524 ; CHECK: OpLoad [[image]] {{%\w+}} MakePointerVisible|NonPrivatePointer [[scope]]
1525 ; CHECK-NOT: NonPrivatePointer
1526 ; CHECK: OpImageSparseRead {{%\w+}} {{%\w+}} {{%\w+}} MakeTexelVisible|NonPrivateTexel [[scope]]
1527 OpCapability Shader
1528 OpCapability Linkage
1529 OpCapability StorageImageReadWithoutFormat
1530 OpCapability SparseResidency
1531 OpExtension "SPV_KHR_storage_buffer_storage_class"
1532 OpMemoryModel Logical GLSL450
1533 OpDecorate %var Coherent
1534 %void = OpTypeVoid
1535 %int = OpTypeInt 32 0
1536 %v2int = OpTypeVector %int 2
1537 %float = OpTypeFloat 32
1538 %int0 = OpConstant %int 0
1539 %v2int_0 = OpConstantComposite %v2int %int0 %int0
1540 %image = OpTypeImage %float 2D 0 0 0 0 Unknown
1541 %struct = OpTypeStruct %int %float
1542 %sampled_image = OpTypeSampledImage %image
1543 %sampler = OpTypeSampler
1544 %ptr_image_StorageBuffer = OpTypePointer StorageBuffer %image
1545 %ptr_sampler_StorageBuffer = OpTypePointer StorageBuffer %sampler
1546 %var = OpVariable %ptr_image_StorageBuffer StorageBuffer
1547 %sampler_var = OpVariable %ptr_sampler_StorageBuffer StorageBuffer
1548 %func_ty = OpTypeFunction %void
1549 %func = OpFunction %void None %func_ty
1550 %1 = OpLabel
1551 %ld = OpLoad %image %var
1552 %ld_sampler = OpLoad %sampler %sampler_var
1553 %sample = OpSampledImage %sampled_image %ld %ld_sampler
1554 %extract = OpImage %image %sample
1555 %rd = OpImageSparseRead %struct %extract %v2int_0
1556 OpReturn
1557 OpFunctionEnd
1558 )";
1559
1560 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1561 }
1562
1563 TEST_F(UpgradeMemoryModelTest, TessellationControlBarrierNoChange) {
1564 const std::string text = R"(
1565 ; CHECK: [[none:%\w+]] = OpConstant {{%\w+}} 0{{\s*$}}
1566 ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2{{\s*$}}
1567 ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[none]]{{\s*$}}
1568 OpCapability Tessellation
1569 OpMemoryModel Logical GLSL450
1570 OpEntryPoint TessellationControl %func "func"
1571 %void = OpTypeVoid
1572 %int = OpTypeInt 32 0
1573 %none = OpConstant %int 0
1574 %workgroup = OpConstant %int 2
1575 %func_ty = OpTypeFunction %void
1576 %func = OpFunction %void None %func_ty
1577 %1 = OpLabel
1578 OpControlBarrier %workgroup %workgroup %none
1579 OpReturn
1580 OpFunctionEnd
1581 )";
1582
1583 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1584 }
1585
1586 TEST_F(UpgradeMemoryModelTest, TessellationControlBarrierRelaxedNoChange) {
1587 const std::string text = R"(
1588 ; CHECK: [[none:%\w+]] = OpConstant {{%\w+}} 0{{\s*$}}
1589 ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2{{\s*$}}
1590 ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[none]]{{\s*$}}
1591 OpCapability Tessellation
1592 OpMemoryModel Logical GLSL450
1593 OpEntryPoint TessellationControl %func "func" %var
1594 %void = OpTypeVoid
1595 %int = OpTypeInt 32 0
1596 %none = OpConstant %int 0
1597 %workgroup = OpConstant %int 2
1598 %ptr_int_Output = OpTypePointer Output %int
1599 %var = OpVariable %ptr_int_Output Output
1600 %func_ty = OpTypeFunction %void
1601 %func = OpFunction %void None %func_ty
1602 %1 = OpLabel
1603 %ld = OpLoad %int %var
1604 OpControlBarrier %workgroup %workgroup %none
1605 OpStore %var %ld
1606 OpReturn
1607 OpFunctionEnd
1608 )";
1609
1610 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1611 }
1612
1613 TEST_F(UpgradeMemoryModelTest, TessellationControlBarrierAddOutput) {
1614 const std::string text = R"(
1615 ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2{{\s*$}}
1616 ; CHECK: [[acqrel_workgroup_output:%\w+]] = OpConstant {{%\w+}} 4360{{\s*$}}
1617 ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[acqrel_workgroup_output]]{{\s*$}}
1618 OpCapability Tessellation
1619 OpMemoryModel Logical GLSL450
1620 OpEntryPoint TessellationControl %func "func" %var
1621 %void = OpTypeVoid
1622 %int = OpTypeInt 32 0
1623 %workgroup = OpConstant %int 2
1624 %acqrel_workgroup = OpConstant %int 264
1625 %ptr_int_Output = OpTypePointer Output %int
1626 %var = OpVariable %ptr_int_Output Output
1627 %func_ty = OpTypeFunction %void
1628 %func = OpFunction %void None %func_ty
1629 %1 = OpLabel
1630 %ld = OpLoad %int %var
1631 OpControlBarrier %workgroup %workgroup %acqrel_workgroup
1632 OpStore %var %ld
1633 OpReturn
1634 OpFunctionEnd
1635 )";
1636
1637 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1638 }
1639
1640 TEST_F(UpgradeMemoryModelTest, TessellationMemoryBarrierNoChange) {
1641 const std::string text = R"(
1642 ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2{{\s*$}}
1643 ; CHECK: [[acqrel_workgroup:%\w+]] = OpConstant {{%\w+}} 264{{\s*$}}
1644 ; CHECK: OpMemoryBarrier [[workgroup]] [[acqrel_workgroup]]{{\s*$}}
1645 OpCapability Tessellation
1646 OpMemoryModel Logical GLSL450
1647 OpEntryPoint TessellationControl %func "func" %var
1648 %void = OpTypeVoid
1649 %int = OpTypeInt 32 0
1650 %workgroup = OpConstant %int 2
1651 %acqrel_workgroup = OpConstant %int 264
1652 %ptr_int_Output = OpTypePointer Output %int
1653 %var = OpVariable %ptr_int_Output Output
1654 %func_ty = OpTypeFunction %void
1655 %func = OpFunction %void None %func_ty
1656 %1 = OpLabel
1657 %ld = OpLoad %int %var
1658 OpMemoryBarrier %workgroup %acqrel_workgroup
1659 OpStore %var %ld
1660 OpReturn
1661 OpFunctionEnd
1662 )";
1663
1664 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1665 }
1666
1667 TEST_F(UpgradeMemoryModelTest, TessellationControlBarrierAddOutputSubFunction) {
1668 const std::string text = R"(
1669 ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2{{\s*$}}
1670 ; CHECK: [[acqrel_workgroup_output:%\w+]] = OpConstant {{%\w+}} 4360{{\s*$}}
1671 ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[acqrel_workgroup_output]]{{\s*$}}
1672 OpCapability Tessellation
1673 OpMemoryModel Logical GLSL450
1674 OpEntryPoint TessellationControl %func "func" %var
1675 %void = OpTypeVoid
1676 %int = OpTypeInt 32 0
1677 %workgroup = OpConstant %int 2
1678 %acqrel_workgroup = OpConstant %int 264
1679 %ptr_int_Output = OpTypePointer Output %int
1680 %var = OpVariable %ptr_int_Output Output
1681 %func_ty = OpTypeFunction %void
1682 %func = OpFunction %void None %func_ty
1683 %1 = OpLabel
1684 %call = OpFunctionCall %void %sub_func
1685 OpReturn
1686 OpFunctionEnd
1687 %sub_func = OpFunction %void None %func_ty
1688 %2 = OpLabel
1689 %ld = OpLoad %int %var
1690 OpControlBarrier %workgroup %workgroup %acqrel_workgroup
1691 OpStore %var %ld
1692 OpReturn
1693 OpFunctionEnd
1694 )";
1695
1696 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1697 }
1698
1699 TEST_F(UpgradeMemoryModelTest,
1700 TessellationControlBarrierAddOutputDifferentFunctions) {
1701 const std::string text = R"(
1702 ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2{{\s*$}}
1703 ; CHECK: [[acqrel_workgroup_output:%\w+]] = OpConstant {{%\w+}} 4360{{\s*$}}
1704 ; CHECK: OpControlBarrier [[workgroup]] [[workgroup]] [[acqrel_workgroup_output]]{{\s*$}}
1705 OpCapability Tessellation
1706 OpMemoryModel Logical GLSL450
1707 OpEntryPoint TessellationControl %func "func" %var
1708 %void = OpTypeVoid
1709 %int = OpTypeInt 32 0
1710 %workgroup = OpConstant %int 2
1711 %acqrel_workgroup = OpConstant %int 264
1712 %ptr_int_Output = OpTypePointer Output %int
1713 %var = OpVariable %ptr_int_Output Output
1714 %func_ty = OpTypeFunction %void
1715 %ld_func_ty = OpTypeFunction %int
1716 %st_func_ty = OpTypeFunction %void %int
1717 %func = OpFunction %void None %func_ty
1718 %1 = OpLabel
1719 %call_ld = OpFunctionCall %int %ld_func
1720 %call_barrier = OpFunctionCall %void %barrier_func
1721 %call_st = OpFunctionCall %void %st_func %call_ld
1722 OpReturn
1723 OpFunctionEnd
1724 %ld_func = OpFunction %int None %ld_func_ty
1725 %2 = OpLabel
1726 %ld = OpLoad %int %var
1727 OpReturnValue %ld
1728 OpFunctionEnd
1729 %barrier_func = OpFunction %void None %func_ty
1730 %3 = OpLabel
1731 OpControlBarrier %workgroup %workgroup %acqrel_workgroup
1732 OpReturn
1733 OpFunctionEnd
1734 %st_func = OpFunction %void None %st_func_ty
1735 %param = OpFunctionParameter %int
1736 %4 = OpLabel
1737 OpStore %var %param
1738 OpReturn
1739 OpFunctionEnd
1740 )";
1741
1742 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1743 }
1744
1745 TEST_F(UpgradeMemoryModelTest, ChangeControlBarrierMemoryScope) {
1746 std::string text = R"(
1747 ; CHECK: [[workgroup:%\w+]] = OpConstant {{%\w+}} 2{{\s*$}}
1748 ; CHECK: [[acqrel_workgroup:%\w+]] = OpConstant {{%\w+}} 264{{\s*$}}
1749 ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5{{\s*$}}
1750 ; CHECK: OpControlBarrier [[workgroup]] [[queuefamily]] [[acqrel_workgroup]]{{\s*$}}
1751 OpCapability Shader
1752 OpMemoryModel Logical GLSL450
1753 OpEntryPoint GLCompute %func "func"
1754 %void = OpTypeVoid
1755 %int = OpTypeInt 32 0
1756 %device = OpConstant %int 1
1757 %workgroup = OpConstant %int 2
1758 %acqrel_workgroup = OpConstant %int 264
1759 %func_ty = OpTypeFunction %void
1760 %func = OpFunction %void None %func_ty
1761 %1 = OpLabel
1762 OpControlBarrier %workgroup %device %acqrel_workgroup
1763 OpReturn
1764 OpFunctionEnd
1765 )";
1766
1767 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1768 }
1769
1770 TEST_F(UpgradeMemoryModelTest, ChangeMemoryBarrierMemoryScope) {
1771 std::string text = R"(
1772 ; CHECK: [[acqrel_workgroup:%\w+]] = OpConstant {{%\w+}} 264{{\s*$}}
1773 ; CHECK: [[queuefamily:%\w+]] = OpConstant {{%\w+}} 5{{\s*$}}
1774 ; CHECK: OpMemoryBarrier [[queuefamily]] [[acqrel_workgroup]]{{\s*$}}
1775 OpCapability Shader
1776 OpMemoryModel Logical GLSL450
1777 OpEntryPoint GLCompute %func "func"
1778 %void = OpTypeVoid
1779 %int = OpTypeInt 32 0
1780 %device = OpConstant %int 1
1781 %acqrel_workgroup = OpConstant %int 264
1782 %func_ty = OpTypeFunction %void
1783 %func = OpFunction %void None %func_ty
1784 %1 = OpLabel
1785 OpMemoryBarrier %device %acqrel_workgroup
1786 OpReturn
1787 OpFunctionEnd
1788 )";
1789
1790 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1791 }
1792
1793 TEST_F(UpgradeMemoryModelTest, ChangeAtomicMemoryScope) {
1794 std::string text = R"(
1795 ; CHECK: [[int:%\w+]] = OpTypeInt
1796 ; CHECK: [[var:%\w+]] = OpVariable
1797 ; CHECK: [[qf:%\w+]] = OpConstant [[int]] 5
1798 ; CHECK: OpAtomicLoad [[int]] [[var]] [[qf]]
1799 ; CHECK: OpAtomicStore [[var]] [[qf]]
1800 ; CHECK: OpAtomicExchange [[int]] [[var]] [[qf]]
1801 ; CHECK: OpAtomicCompareExchange [[int]] [[var]] [[qf]]
1802 ; CHECK: OpAtomicIIncrement [[int]] [[var]] [[qf]]
1803 ; CHECK: OpAtomicIDecrement [[int]] [[var]] [[qf]]
1804 ; CHECK: OpAtomicIAdd [[int]] [[var]] [[qf]]
1805 ; CHECK: OpAtomicISub [[int]] [[var]] [[qf]]
1806 ; CHECK: OpAtomicSMin [[int]] [[var]] [[qf]]
1807 ; CHECK: OpAtomicSMax [[int]] [[var]] [[qf]]
1808 ; CHECK: OpAtomicUMin [[int]] [[var]] [[qf]]
1809 ; CHECK: OpAtomicUMax [[int]] [[var]] [[qf]]
1810 ; CHECK: OpAtomicAnd [[int]] [[var]] [[qf]]
1811 ; CHECK: OpAtomicOr [[int]] [[var]] [[qf]]
1812 ; CHECK: OpAtomicXor [[int]] [[var]] [[qf]]
1813 OpCapability Shader
1814 OpExtension "SPV_KHR_storage_buffer_storage_class"
1815 OpMemoryModel Logical GLSL450
1816 OpEntryPoint GLCompute %func "func"
1817 %void = OpTypeVoid
1818 %int = OpTypeInt 32 0
1819 %none = OpConstant %int 0
1820 %device = OpConstant %int 1
1821 %func_ty = OpTypeFunction %void
1822 %ptr_int_StorageBuffer = OpTypePointer StorageBuffer %int
1823 %var = OpVariable %ptr_int_StorageBuffer StorageBuffer
1824 %func = OpFunction %void None %func_ty
1825 %1 = OpLabel
1826 %ld = OpAtomicLoad %int %var %device %none
1827 OpAtomicStore %var %device %none %ld
1828 %ex = OpAtomicExchange %int %var %device %none %ld
1829 %cmp_ex = OpAtomicCompareExchange %int %var %device %none %none %ld %ld
1830 %inc = OpAtomicIIncrement %int %var %device %none
1831 %dec = OpAtomicIDecrement %int %var %device %none
1832 %add = OpAtomicIAdd %int %var %device %none %ld
1833 %sub = OpAtomicISub %int %var %device %none %ld
1834 %smin = OpAtomicSMin %int %var %device %none %ld
1835 %smax = OpAtomicSMax %int %var %device %none %ld
1836 %umin = OpAtomicUMin %int %var %device %none %ld
1837 %umax = OpAtomicUMax %int %var %device %none %ld
1838 %and = OpAtomicAnd %int %var %device %none %ld
1839 %or = OpAtomicOr %int %var %device %none %ld
1840 %xor = OpAtomicXor %int %var %device %none %ld
1841 OpReturn
1842 OpFunctionEnd
1843 )";
1844
1845 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1846 }
1847
1848 TEST_F(UpgradeMemoryModelTest, UpgradeModfNoFlags) {
1849 const std::string text = R"(
1850 ; CHECK: [[float:%\w+]] = OpTypeFloat 32
1851 ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
1852 ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]]
1853 ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
1854 ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
1855 ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
1856 ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
1857 ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
1858 ; CHECK: OpStore [[var]] [[ex1]]
1859 ; CHECK-NOT: NonPrivatePointer
1860 ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
1861 OpCapability Shader
1862 OpMemoryModel Logical GLSL450
1863 %import = OpExtInstImport "GLSL.std.450"
1864 OpEntryPoint GLCompute %func "func"
1865 %void = OpTypeVoid
1866 %float = OpTypeFloat 32
1867 %float_0 = OpConstant %float 0
1868 %ptr_ssbo_float = OpTypePointer StorageBuffer %float
1869 %ssbo_var = OpVariable %ptr_ssbo_float StorageBuffer
1870 %func_ty = OpTypeFunction %void
1871 %func = OpFunction %void None %func_ty
1872 %1 = OpLabel
1873 %2 = OpExtInst %float %import Modf %float_0 %ssbo_var
1874 %3 = OpFAdd %float %float_0 %2
1875 OpReturn
1876 OpFunctionEnd
1877 )";
1878
1879 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1880 }
1881
1882 TEST_F(UpgradeMemoryModelTest, UpgradeModfWorkgroupCoherent) {
1883 const std::string text = R"(
1884 ; CHECK: [[float:%\w+]] = OpTypeFloat 32
1885 ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
1886 ; CHECK: [[ptr:%\w+]] = OpTypePointer Workgroup [[float]]
1887 ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] Workgroup
1888 ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
1889 ; CHECK: [[wg_scope:%\w+]] = OpConstant {{%\w+}} 2
1890 ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
1891 ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
1892 ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
1893 ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailable|NonPrivatePointer [[wg_scope]]
1894 ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
1895 OpCapability Shader
1896 OpMemoryModel Logical GLSL450
1897 %import = OpExtInstImport "GLSL.std.450"
1898 OpEntryPoint GLCompute %func "func"
1899 OpDecorate %wg_var Coherent
1900 %void = OpTypeVoid
1901 %float = OpTypeFloat 32
1902 %float_0 = OpConstant %float 0
1903 %ptr_wg_float = OpTypePointer Workgroup %float
1904 %wg_var = OpVariable %ptr_wg_float Workgroup
1905 %func_ty = OpTypeFunction %void
1906 %func = OpFunction %void None %func_ty
1907 %1 = OpLabel
1908 %2 = OpExtInst %float %import Modf %float_0 %wg_var
1909 %3 = OpFAdd %float %float_0 %2
1910 OpReturn
1911 OpFunctionEnd
1912 )";
1913
1914 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1915 }
1916
1917 TEST_F(UpgradeMemoryModelTest, UpgradeModfSSBOCoherent) {
1918 const std::string text = R"(
1919 ; CHECK: [[float:%\w+]] = OpTypeFloat 32
1920 ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
1921 ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]]
1922 ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
1923 ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
1924 ; CHECK: [[qf_scope:%\w+]] = OpConstant {{%\w+}} 5
1925 ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
1926 ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
1927 ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
1928 ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailable|NonPrivatePointer [[qf_scope]]
1929 ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
1930 OpCapability Shader
1931 OpMemoryModel Logical GLSL450
1932 %import = OpExtInstImport "GLSL.std.450"
1933 OpEntryPoint GLCompute %func "func"
1934 OpDecorate %ssbo_var Coherent
1935 %void = OpTypeVoid
1936 %float = OpTypeFloat 32
1937 %float_0 = OpConstant %float 0
1938 %ptr_ssbo_float = OpTypePointer StorageBuffer %float
1939 %ssbo_var = OpVariable %ptr_ssbo_float StorageBuffer
1940 %func_ty = OpTypeFunction %void
1941 %func = OpFunction %void None %func_ty
1942 %1 = OpLabel
1943 %2 = OpExtInst %float %import Modf %float_0 %ssbo_var
1944 %3 = OpFAdd %float %float_0 %2
1945 OpReturn
1946 OpFunctionEnd
1947 )";
1948
1949 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1950 }
1951
1952 TEST_F(UpgradeMemoryModelTest, UpgradeModfSSBOVolatile) {
1953 const std::string text = R"(
1954 ; CHECK: [[float:%\w+]] = OpTypeFloat 32
1955 ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
1956 ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[float]]
1957 ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
1958 ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[float]]
1959 ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} ModfStruct [[float_0]]
1960 ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
1961 ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 1
1962 ; CHECK: OpStore [[var]] [[ex1]] Volatile
1963 ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
1964 OpCapability Shader
1965 OpMemoryModel Logical GLSL450
1966 %import = OpExtInstImport "GLSL.std.450"
1967 OpEntryPoint GLCompute %func "func"
1968 OpDecorate %wg_var Volatile
1969 %void = OpTypeVoid
1970 %float = OpTypeFloat 32
1971 %float_0 = OpConstant %float 0
1972 %ptr_ssbo_float = OpTypePointer StorageBuffer %float
1973 %wg_var = OpVariable %ptr_ssbo_float StorageBuffer
1974 %func_ty = OpTypeFunction %void
1975 %func = OpFunction %void None %func_ty
1976 %1 = OpLabel
1977 %2 = OpExtInst %float %import Modf %float_0 %wg_var
1978 %3 = OpFAdd %float %float_0 %2
1979 OpReturn
1980 OpFunctionEnd
1981 )";
1982
1983 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
1984 }
1985
1986 TEST_F(UpgradeMemoryModelTest, UpgradeFrexpNoFlags) {
1987 const std::string text = R"(
1988 ; CHECK: [[float:%\w+]] = OpTypeFloat 32
1989 ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
1990 ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
1991 ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]]
1992 ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
1993 ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
1994 ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
1995 ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
1996 ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
1997 ; CHECK: OpStore [[var]] [[ex1]]
1998 ; CHECK-NOT: NonPrivatePointer
1999 ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
2000 OpCapability Shader
2001 OpMemoryModel Logical GLSL450
2002 %import = OpExtInstImport "GLSL.std.450"
2003 OpEntryPoint GLCompute %func "func"
2004 %void = OpTypeVoid
2005 %float = OpTypeFloat 32
2006 %float_0 = OpConstant %float 0
2007 %int = OpTypeInt 32 0
2008 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2009 %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
2010 %func_ty = OpTypeFunction %void
2011 %func = OpFunction %void None %func_ty
2012 %1 = OpLabel
2013 %2 = OpExtInst %float %import Frexp %float_0 %ssbo_var
2014 %3 = OpFAdd %float %float_0 %2
2015 OpReturn
2016 OpFunctionEnd
2017 )";
2018
2019 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2020 }
2021
2022 TEST_F(UpgradeMemoryModelTest, UpgradeFrexpWorkgroupCoherent) {
2023 const std::string text = R"(
2024 ; CHECK: [[float:%\w+]] = OpTypeFloat 32
2025 ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
2026 ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
2027 ; CHECK: [[ptr:%\w+]] = OpTypePointer Workgroup [[int]]
2028 ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] Workgroup
2029 ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
2030 ; CHECK: [[wg_scope:%\w+]] = OpConstant {{%\w+}} 2
2031 ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
2032 ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
2033 ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
2034 ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailable|NonPrivatePointer [[wg_scope]]
2035 ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
2036 OpCapability Shader
2037 OpMemoryModel Logical GLSL450
2038 %import = OpExtInstImport "GLSL.std.450"
2039 OpEntryPoint GLCompute %func "func"
2040 OpDecorate %wg_var Coherent
2041 %void = OpTypeVoid
2042 %float = OpTypeFloat 32
2043 %float_0 = OpConstant %float 0
2044 %int = OpTypeInt 32 0
2045 %ptr_wg_int = OpTypePointer Workgroup %int
2046 %wg_var = OpVariable %ptr_wg_int Workgroup
2047 %func_ty = OpTypeFunction %void
2048 %func = OpFunction %void None %func_ty
2049 %1 = OpLabel
2050 %2 = OpExtInst %float %import Frexp %float_0 %wg_var
2051 %3 = OpFAdd %float %float_0 %2
2052 OpReturn
2053 OpFunctionEnd
2054 )";
2055
2056 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2057 }
2058
2059 TEST_F(UpgradeMemoryModelTest, UpgradeFrexpSSBOCoherent) {
2060 const std::string text = R"(
2061 ; CHECK: [[float:%\w+]] = OpTypeFloat 32
2062 ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
2063 ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
2064 ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]]
2065 ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
2066 ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
2067 ; CHECK: [[qf_scope:%\w+]] = OpConstant {{%\w+}} 5
2068 ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
2069 ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
2070 ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
2071 ; CHECK: OpStore [[var]] [[ex1]] MakePointerAvailable|NonPrivatePointer [[qf_scope]]
2072 ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
2073 OpCapability Shader
2074 OpMemoryModel Logical GLSL450
2075 %import = OpExtInstImport "GLSL.std.450"
2076 OpEntryPoint GLCompute %func "func"
2077 OpDecorate %ssbo_var Coherent
2078 %void = OpTypeVoid
2079 %float = OpTypeFloat 32
2080 %float_0 = OpConstant %float 0
2081 %int = OpTypeInt 32 0
2082 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2083 %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
2084 %func_ty = OpTypeFunction %void
2085 %func = OpFunction %void None %func_ty
2086 %1 = OpLabel
2087 %2 = OpExtInst %float %import Frexp %float_0 %ssbo_var
2088 %3 = OpFAdd %float %float_0 %2
2089 OpReturn
2090 OpFunctionEnd
2091 )";
2092
2093 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2094 }
2095
2096 TEST_F(UpgradeMemoryModelTest, UpgradeFrexpSSBOVolatile) {
2097 const std::string text = R"(
2098 ; CHECK: [[float:%\w+]] = OpTypeFloat 32
2099 ; CHECK: [[float_0:%\w+]] = OpConstant [[float]] 0
2100 ; CHECK: [[int:%\w+]] = OpTypeInt 32 0
2101 ; CHECK: [[ptr:%\w+]] = OpTypePointer StorageBuffer [[int]]
2102 ; CHECK: [[var:%\w+]] = OpVariable [[ptr]] StorageBuffer
2103 ; CHECK: [[struct:%\w+]] = OpTypeStruct [[float]] [[int]]
2104 ; CHECK: [[modfstruct:%\w+]] = OpExtInst [[struct]] {{%\w+}} FrexpStruct [[float_0]]
2105 ; CHECK: [[ex0:%\w+]] = OpCompositeExtract [[float]] [[modfstruct]] 0
2106 ; CHECK: [[ex1:%\w+]] = OpCompositeExtract [[int]] [[modfstruct]] 1
2107 ; CHECK: OpStore [[var]] [[ex1]] Volatile
2108 ; CHECK: OpFAdd [[float]] [[float_0]] [[ex0]]
2109 OpCapability Shader
2110 OpMemoryModel Logical GLSL450
2111 %import = OpExtInstImport "GLSL.std.450"
2112 OpEntryPoint GLCompute %func "func"
2113 OpDecorate %wg_var Volatile
2114 %void = OpTypeVoid
2115 %float = OpTypeFloat 32
2116 %float_0 = OpConstant %float 0
2117 %int = OpTypeInt 32 0
2118 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2119 %wg_var = OpVariable %ptr_ssbo_int StorageBuffer
2120 %func_ty = OpTypeFunction %void
2121 %func = OpFunction %void None %func_ty
2122 %1 = OpLabel
2123 %2 = OpExtInst %float %import Frexp %float_0 %wg_var
2124 %3 = OpFAdd %float %float_0 %2
2125 OpReturn
2126 OpFunctionEnd
2127 )";
2128
2129 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2130 }
2131
2132 TEST_F(UpgradeMemoryModelTest, SPV14NormalizeCopyMemoryAddOperands) {
2133 const std::string text = R"(
2134 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} None None
2135 OpCapability Shader
2136 OpMemoryModel Logical GLSL450
2137 OpEntryPoint GLCompute %func "func" %src %dst
2138 %void = OpTypeVoid
2139 %int = OpTypeInt 32 0
2140 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2141 %src = OpVariable %ptr_ssbo_int StorageBuffer
2142 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2143 %void_fn = OpTypeFunction %void
2144 %func = OpFunction %void None %void_fn
2145 %entry = OpLabel
2146 OpCopyMemory %dst %src
2147 OpReturn
2148 OpFunctionEnd
2149 )";
2150
2151 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2152 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2153 }
2154
2155 TEST_F(UpgradeMemoryModelTest, SPV14NormalizeCopyMemoryDuplicateOperand) {
2156 const std::string text = R"(
2157 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Nontemporal Nontemporal
2158 OpCapability Shader
2159 OpMemoryModel Logical GLSL450
2160 OpEntryPoint GLCompute %func "func" %src %dst
2161 %void = OpTypeVoid
2162 %int = OpTypeInt 32 0
2163 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2164 %src = OpVariable %ptr_ssbo_int StorageBuffer
2165 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2166 %void_fn = OpTypeFunction %void
2167 %func = OpFunction %void None %void_fn
2168 %entry = OpLabel
2169 OpCopyMemory %dst %src Nontemporal
2170 OpReturn
2171 OpFunctionEnd
2172 )";
2173
2174 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2175 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2176 }
2177
2178 TEST_F(UpgradeMemoryModelTest, SPV14NormalizeCopyMemoryDuplicateOperands) {
2179 const std::string text = R"(
2180 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Aligned 4 Aligned 4
2181 OpCapability Shader
2182 OpMemoryModel Logical GLSL450
2183 OpEntryPoint GLCompute %func "func" %src %dst
2184 %void = OpTypeVoid
2185 %int = OpTypeInt 32 0
2186 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2187 %src = OpVariable %ptr_ssbo_int StorageBuffer
2188 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2189 %void_fn = OpTypeFunction %void
2190 %func = OpFunction %void None %void_fn
2191 %entry = OpLabel
2192 OpCopyMemory %dst %src Aligned 4
2193 OpReturn
2194 OpFunctionEnd
2195 )";
2196
2197 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2198 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2199 }
2200
2201 TEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryDstCoherent) {
2202 const std::string text = R"(
2203 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
2204 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] None
2205 OpCapability Shader
2206 OpMemoryModel Logical GLSL450
2207 OpEntryPoint GLCompute %func "func" %src %dst
2208 OpDecorate %dst Coherent
2209 %void = OpTypeVoid
2210 %int = OpTypeInt 32 0
2211 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2212 %src = OpVariable %ptr_ssbo_int StorageBuffer
2213 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2214 %void_fn = OpTypeFunction %void
2215 %func = OpFunction %void None %void_fn
2216 %entry = OpLabel
2217 OpCopyMemory %dst %src
2218 OpReturn
2219 OpFunctionEnd
2220 )";
2221
2222 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2223 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2224 }
2225
2226 TEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryDstCoherentPreviousArgs) {
2227 const std::string text = R"(
2228 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
2229 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Aligned|MakePointerAvailable|NonPrivatePointer 4 [[scope]] Aligned 4
2230 OpCapability Shader
2231 OpMemoryModel Logical GLSL450
2232 OpEntryPoint GLCompute %func "func" %src %dst
2233 OpDecorate %dst Coherent
2234 %void = OpTypeVoid
2235 %int = OpTypeInt 32 0
2236 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2237 %src = OpVariable %ptr_ssbo_int StorageBuffer
2238 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2239 %void_fn = OpTypeFunction %void
2240 %func = OpFunction %void None %void_fn
2241 %entry = OpLabel
2242 OpCopyMemory %dst %src Aligned 4
2243 OpReturn
2244 OpFunctionEnd
2245 )";
2246
2247 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2248 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2249 }
2250
2251 TEST_F(UpgradeMemoryModelTest, SPV14CopyMemorySrcCoherent) {
2252 const std::string text = R"(
2253 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
2254 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} None MakePointerVisible|NonPrivatePointer [[scope]]
2255 OpCapability Shader
2256 OpMemoryModel Logical GLSL450
2257 OpEntryPoint GLCompute %func "func" %src %dst
2258 OpDecorate %src Coherent
2259 %void = OpTypeVoid
2260 %int = OpTypeInt 32 0
2261 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2262 %src = OpVariable %ptr_ssbo_int StorageBuffer
2263 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2264 %void_fn = OpTypeFunction %void
2265 %func = OpFunction %void None %void_fn
2266 %entry = OpLabel
2267 OpCopyMemory %dst %src
2268 OpReturn
2269 OpFunctionEnd
2270 )";
2271
2272 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2273 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2274 }
2275
2276 TEST_F(UpgradeMemoryModelTest, SPV14CopyMemorySrcCoherentPreviousArgs) {
2277 const std::string text = R"(
2278 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
2279 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Aligned 4 Aligned|MakePointerVisible|NonPrivatePointer 4 [[scope]]
2280 OpCapability Shader
2281 OpMemoryModel Logical GLSL450
2282 OpEntryPoint GLCompute %func "func" %src %dst
2283 OpDecorate %src Coherent
2284 %void = OpTypeVoid
2285 %int = OpTypeInt 32 0
2286 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2287 %src = OpVariable %ptr_ssbo_int StorageBuffer
2288 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2289 %void_fn = OpTypeFunction %void
2290 %func = OpFunction %void None %void_fn
2291 %entry = OpLabel
2292 OpCopyMemory %dst %src Aligned 4
2293 OpReturn
2294 OpFunctionEnd
2295 )";
2296
2297 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2298 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2299 }
2300
2301 TEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryBothCoherent) {
2302 const std::string text = R"(
2303 ; CHECK-DAG: [[queue:%\w+]] = OpConstant {{%\w+}} 5
2304 ; CHECK-DAG: [[wg:%\w+]] = OpConstant {{%\w+}} 2
2305 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[wg]] MakePointerVisible|NonPrivatePointer [[queue]]
2306 OpCapability Shader
2307 OpMemoryModel Logical GLSL450
2308 OpEntryPoint GLCompute %func "func" %src %dst
2309 OpDecorate %src Coherent
2310 %void = OpTypeVoid
2311 %int = OpTypeInt 32 0
2312 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2313 %ptr_wg_int = OpTypePointer Workgroup %int
2314 %src = OpVariable %ptr_ssbo_int StorageBuffer
2315 %dst = OpVariable %ptr_wg_int Workgroup
2316 %void_fn = OpTypeFunction %void
2317 %func = OpFunction %void None %void_fn
2318 %entry = OpLabel
2319 OpCopyMemory %dst %src
2320 OpReturn
2321 OpFunctionEnd
2322 )";
2323
2324 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2325 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2326 }
2327
2328 TEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryBothCoherentPreviousArgs) {
2329 const std::string text = R"(
2330 ; CHECK-DAG: [[queue:%\w+]] = OpConstant {{%\w+}} 5
2331 ; CHECK-DAG: [[wg:%\w+]] = OpConstant {{%\w+}} 2
2332 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Aligned|MakePointerAvailable|NonPrivatePointer 4 [[queue]] Aligned|MakePointerVisible|NonPrivatePointer 4 [[wg]]
2333 OpCapability Shader
2334 OpMemoryModel Logical GLSL450
2335 OpEntryPoint GLCompute %func "func" %src %dst
2336 OpDecorate %dst Coherent
2337 %void = OpTypeVoid
2338 %int = OpTypeInt 32 0
2339 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2340 %ptr_wg_int = OpTypePointer Workgroup %int
2341 %src = OpVariable %ptr_wg_int Workgroup
2342 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2343 %void_fn = OpTypeFunction %void
2344 %func = OpFunction %void None %void_fn
2345 %entry = OpLabel
2346 OpCopyMemory %dst %src Aligned 4
2347 OpReturn
2348 OpFunctionEnd
2349 )";
2350
2351 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2352 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2353 }
2354
2355 TEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryBothVolatile) {
2356 const std::string text = R"(
2357 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Volatile Volatile
2358 OpCapability Shader
2359 OpMemoryModel Logical GLSL450
2360 OpEntryPoint GLCompute %func "func" %src %dst
2361 OpDecorate %src Volatile
2362 OpDecorate %dst Volatile
2363 %void = OpTypeVoid
2364 %int = OpTypeInt 32 0
2365 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2366 %src = OpVariable %ptr_ssbo_int StorageBuffer
2367 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2368 %void_fn = OpTypeFunction %void
2369 %func = OpFunction %void None %void_fn
2370 %entry = OpLabel
2371 OpCopyMemory %dst %src
2372 OpReturn
2373 OpFunctionEnd
2374 )";
2375
2376 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2377 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2378 }
2379
2380 TEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryBothVolatilePreviousArgs) {
2381 const std::string text = R"(
2382 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Volatile|Aligned 4 Volatile|Aligned 4
2383 OpCapability Shader
2384 OpMemoryModel Logical GLSL450
2385 OpEntryPoint GLCompute %func "func" %src %dst
2386 OpDecorate %src Volatile
2387 OpDecorate %dst Volatile
2388 %void = OpTypeVoid
2389 %int = OpTypeInt 32 0
2390 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2391 %src = OpVariable %ptr_ssbo_int StorageBuffer
2392 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2393 %void_fn = OpTypeFunction %void
2394 %func = OpFunction %void None %void_fn
2395 %entry = OpLabel
2396 OpCopyMemory %dst %src Aligned 4
2397 OpReturn
2398 OpFunctionEnd
2399 )";
2400
2401 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2402 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2403 }
2404
2405 TEST_F(UpgradeMemoryModelTest, SPV14CopyMemoryDstCoherentTwoOperands) {
2406 const std::string text = R"(
2407 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
2408 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} MakePointerAvailable|NonPrivatePointer [[scope]] None
2409 OpCapability Shader
2410 OpMemoryModel Logical GLSL450
2411 OpEntryPoint GLCompute %func "func" %src %dst
2412 OpDecorate %dst Coherent
2413 %void = OpTypeVoid
2414 %int = OpTypeInt 32 0
2415 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2416 %src = OpVariable %ptr_ssbo_int StorageBuffer
2417 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2418 %void_fn = OpTypeFunction %void
2419 %func = OpFunction %void None %void_fn
2420 %entry = OpLabel
2421 OpCopyMemory %dst %src None None
2422 OpReturn
2423 OpFunctionEnd
2424 )";
2425
2426 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2427 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2428 }
2429
2430 TEST_F(UpgradeMemoryModelTest,
2431 SPV14CopyMemoryDstCoherentPreviousArgsTwoOperands) {
2432 const std::string text = R"(
2433 ; CHECK: [[scope:%\w+]] = OpConstant {{%\w+}} 5
2434 ; CHECK: OpCopyMemory {{%\w+}} {{%\w+}} Aligned|MakePointerAvailable|NonPrivatePointer 4 [[scope]] Aligned 8
2435 OpCapability Shader
2436 OpMemoryModel Logical GLSL450
2437 OpEntryPoint GLCompute %func "func" %src %dst
2438 OpDecorate %dst Coherent
2439 %void = OpTypeVoid
2440 %int = OpTypeInt 32 0
2441 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2442 %src = OpVariable %ptr_ssbo_int StorageBuffer
2443 %dst = OpVariable %ptr_ssbo_int StorageBuffer
2444 %void_fn = OpTypeFunction %void
2445 %func = OpFunction %void None %void_fn
2446 %entry = OpLabel
2447 OpCopyMemory %dst %src Aligned 4 Aligned 8
2448 OpReturn
2449 OpFunctionEnd
2450 )";
2451
2452 SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
2453 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2454 }
2455
2456 TEST_F(UpgradeMemoryModelTest, VolatileAtomicLoad) {
2457 const std::string text = R"(
2458 ; CHECK-NOT: OpDecorate {{.*}} Volatile
2459 ; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32768
2460 ; CHECK: OpAtomicLoad [[int]] {{.*}} {{.*}} [[volatile]]
2461 OpCapability Shader
2462 OpCapability Linkage
2463 OpMemoryModel Logical GLSL450
2464 OpDecorate %ssbo_var Volatile
2465 %void = OpTypeVoid
2466 %int = OpTypeInt 32 0
2467 %device = OpConstant %int 1
2468 %relaxed = OpConstant %int 0
2469 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2470 %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
2471 %void_fn = OpTypeFunction %void
2472 %func = OpFunction %void None %void_fn
2473 %entry = OpLabel
2474 %ld = OpAtomicLoad %int %ssbo_var %device %relaxed
2475 OpReturn
2476 OpFunctionEnd
2477 )";
2478
2479 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2480 }
2481
2482 TEST_F(UpgradeMemoryModelTest, VolatileAtomicLoadPreviousFlags) {
2483 const std::string text = R"(
2484 ; CHECK-NOT: OpDecorate {{.*}} Volatile
2485 ; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32834
2486 ; CHECK: OpAtomicLoad [[int]] {{.*}} {{.*}} [[volatile]]
2487 OpCapability Shader
2488 OpCapability Linkage
2489 OpMemoryModel Logical GLSL450
2490 OpDecorate %ssbo_var Volatile
2491 %void = OpTypeVoid
2492 %int = OpTypeInt 32 0
2493 %device = OpConstant %int 1
2494 %acquire_ssbo = OpConstant %int 66
2495 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2496 %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
2497 %void_fn = OpTypeFunction %void
2498 %func = OpFunction %void None %void_fn
2499 %entry = OpLabel
2500 %ld = OpAtomicLoad %int %ssbo_var %device %acquire_ssbo
2501 OpReturn
2502 OpFunctionEnd
2503 )";
2504
2505 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2506 }
2507
2508 TEST_F(UpgradeMemoryModelTest, VolatileAtomicStore) {
2509 const std::string text = R"(
2510 ; CHECK-NOT: OpDecorate {{.*}} Volatile
2511 ; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant {{.*}} 32768
2512 ; CHECK: OpAtomicStore {{.*}} {{.*}} [[volatile]]
2513 OpCapability Shader
2514 OpCapability Linkage
2515 OpMemoryModel Logical GLSL450
2516 OpDecorate %ssbo_var Volatile
2517 %void = OpTypeVoid
2518 %int = OpTypeInt 32 0
2519 %int_0 = OpConstant %int 0
2520 %device = OpConstant %int 1
2521 %relaxed = OpConstant %int 0
2522 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2523 %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
2524 %void_fn = OpTypeFunction %void
2525 %func = OpFunction %void None %void_fn
2526 %entry = OpLabel
2527 OpAtomicStore %ssbo_var %device %relaxed %int_0
2528 OpReturn
2529 OpFunctionEnd
2530 )";
2531
2532 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2533 }
2534
2535 TEST_F(UpgradeMemoryModelTest, VolatileAtomicStorePreviousFlags) {
2536 const std::string text = R"(
2537 ; CHECK-NOT: OpDecorate {{.*}} Volatile
2538 ; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant {{.*}} 32836
2539 ; CHECK: OpAtomicStore {{.*}} {{.*}} [[volatile]]
2540 OpCapability Shader
2541 OpCapability Linkage
2542 OpMemoryModel Logical GLSL450
2543 OpDecorate %ssbo_var Volatile
2544 %void = OpTypeVoid
2545 %int = OpTypeInt 32 0
2546 %int_0 = OpConstant %int 0
2547 %device = OpConstant %int 1
2548 %release_ssbo = OpConstant %int 68
2549 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2550 %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
2551 %void_fn = OpTypeFunction %void
2552 %func = OpFunction %void None %void_fn
2553 %entry = OpLabel
2554 OpAtomicStore %ssbo_var %device %release_ssbo %int_0
2555 OpReturn
2556 OpFunctionEnd
2557 )";
2558
2559 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2560 }
2561
2562 TEST_F(UpgradeMemoryModelTest, VolatileAtomicCompareExchange) {
2563 const std::string text = R"(
2564 ; CHECK-NOT: OpDecorate {{.*}} Volatile
2565 ; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32768
2566 ; CHECK: OpAtomicCompareExchange [[int]] {{.*}} {{.*}} [[volatile]] [[volatile]]
2567 OpCapability Shader
2568 OpCapability Linkage
2569 OpMemoryModel Logical GLSL450
2570 OpDecorate %ssbo_var Volatile
2571 %void = OpTypeVoid
2572 %int = OpTypeInt 32 0
2573 %int_0 = OpConstant %int 0
2574 %int_1 = OpConstant %int 1
2575 %device = OpConstant %int 1
2576 %relaxed = OpConstant %int 0
2577 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2578 %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
2579 %void_fn = OpTypeFunction %void
2580 %func = OpFunction %void None %void_fn
2581 %entry = OpLabel
2582 %ld = OpAtomicCompareExchange %int %ssbo_var %device %relaxed %relaxed %int_0 %int_1
2583 OpReturn
2584 OpFunctionEnd
2585 )";
2586
2587 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2588 }
2589
2590 TEST_F(UpgradeMemoryModelTest, VolatileAtomicCompareExchangePreviousFlags) {
2591 const std::string text = R"(
2592 ; CHECK-NOT: OpDecorate {{.*}} Volatile
2593 ; CHECK: [[volatile_acq_rel:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32840
2594 ; CHECK: [[volatile_acq:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32834
2595 ; CHECK: OpAtomicCompareExchange [[int]] {{.*}} {{.*}} [[volatile_acq_rel]] [[volatile_acq]]
2596 OpCapability Shader
2597 OpCapability Linkage
2598 OpMemoryModel Logical GLSL450
2599 OpDecorate %ssbo_var Volatile
2600 %void = OpTypeVoid
2601 %int = OpTypeInt 32 0
2602 %int_0 = OpConstant %int 0
2603 %int_1 = OpConstant %int 1
2604 %device = OpConstant %int 1
2605 %acq_ssbo = OpConstant %int 66
2606 %acq_rel_ssbo = OpConstant %int 72
2607 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2608 %ssbo_var = OpVariable %ptr_ssbo_int StorageBuffer
2609 %void_fn = OpTypeFunction %void
2610 %func = OpFunction %void None %void_fn
2611 %entry = OpLabel
2612 %ld = OpAtomicCompareExchange %int %ssbo_var %device %acq_rel_ssbo %acq_ssbo %int_0 %int_1
2613 OpReturn
2614 OpFunctionEnd
2615 )";
2616
2617 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2618 }
2619
2620 TEST_F(UpgradeMemoryModelTest, VolatileAtomicLoadMemberDecoration) {
2621 const std::string text = R"(
2622 ; CHECK-NOT: OpMemberDecorate {{.*}} {{.*}} Volatile
2623 ; CHECK: [[relaxed:%[a-zA-Z0-9_]+]] = OpConstant {{.*}} 0
2624 ; CHECK: [[volatile:%[a-zA-Z0-9_]+]] = OpConstant [[int:%[a-zA-Z0-9_]+]] 32768
2625 ; CHECK: OpAtomicLoad [[int]] {{.*}} {{.*}} [[relaxed]]
2626 ; CHECK: OpAtomicLoad [[int]] {{.*}} {{.*}} [[volatile]]
2627 OpCapability Shader
2628 OpCapability Linkage
2629 OpMemoryModel Logical GLSL450
2630 OpMemberDecorate %struct 1 Volatile
2631 %void = OpTypeVoid
2632 %int = OpTypeInt 32 0
2633 %device = OpConstant %int 1
2634 %relaxed = OpConstant %int 0
2635 %int_0 = OpConstant %int 0
2636 %int_1 = OpConstant %int 1
2637 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2638 %struct = OpTypeStruct %int %int
2639 %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
2640 %ssbo_var = OpVariable %ptr_ssbo_struct StorageBuffer
2641 %void_fn = OpTypeFunction %void
2642 %func = OpFunction %void None %void_fn
2643 %entry = OpLabel
2644 %gep0 = OpAccessChain %ptr_ssbo_int %ssbo_var %int_0
2645 %ld0 = OpAtomicLoad %int %gep0 %device %relaxed
2646 %gep1 = OpAccessChain %ptr_ssbo_int %ssbo_var %int_1
2647 %ld1 = OpAtomicLoad %int %gep1 %device %relaxed
2648 OpReturn
2649 OpFunctionEnd
2650 )";
2651
2652 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2653 }
2654
2655 TEST_F(UpgradeMemoryModelTest, CoherentStructMemberInArray) {
2656 const std::string text = R"(
2657 ; CHECK-NOT: OpMemberDecorate
2658 ; CHECK: [[int:%[a-zA-Z0-9_]+]] = OpTypeInt 32 0
2659 ; CHECK: [[device:%[a-zA-Z0-9_]+]] = OpConstant [[int]] 1
2660 ; CHECK: OpLoad [[int]] {{.*}} MakePointerVisible|NonPrivatePointer
2661 OpCapability Shader
2662 OpCapability Linkage
2663 OpMemoryModel Logical GLSL450
2664 OpMemberDecorate %inner 1 Coherent
2665 %void = OpTypeVoid
2666 %int = OpTypeInt 32 0
2667 %int_0 = OpConstant %int 0
2668 %int_1 = OpConstant %int 1
2669 %int_4 = OpConstant %int 4
2670 %inner = OpTypeStruct %int %int
2671 %array = OpTypeArray %inner %int_4
2672 %struct = OpTypeStruct %array
2673 %ptr_ssbo_struct = OpTypePointer StorageBuffer %struct
2674 %ptr_ssbo_int = OpTypePointer StorageBuffer %int
2675 %ssbo_var = OpVariable %ptr_ssbo_struct StorageBuffer
2676 %void_fn = OpTypeFunction %void
2677 %func = OpFunction %void None %void_fn
2678 %entry = OpLabel
2679 %gep = OpAccessChain %ptr_ssbo_int %ssbo_var %int_0 %int_0 %int_1
2680 %ld = OpLoad %int %gep
2681 OpReturn
2682 OpFunctionEnd
2683 )";
2684
2685 SinglePassRunAndMatch<opt::UpgradeMemoryModel>(text, true);
2686 }
2687
2688 } // namespace