1fd4e5da5Sopenharmony_ci// Copyright (c) 2017 Valve Corporation
2fd4e5da5Sopenharmony_ci// Copyright (c) 2017 LunarG Inc.
3fd4e5da5Sopenharmony_ci//
4fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
5fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License.
6fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at
7fd4e5da5Sopenharmony_ci//
8fd4e5da5Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
9fd4e5da5Sopenharmony_ci//
10fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
11fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
12fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and
14fd4e5da5Sopenharmony_ci// limitations under the License.
15fd4e5da5Sopenharmony_ci
16fd4e5da5Sopenharmony_ci#include <memory>
17fd4e5da5Sopenharmony_ci#include <string>
18fd4e5da5Sopenharmony_ci
19fd4e5da5Sopenharmony_ci#include "test/opt/pass_fixture.h"
20fd4e5da5Sopenharmony_ci#include "test/opt/pass_utils.h"
21fd4e5da5Sopenharmony_ci
22fd4e5da5Sopenharmony_cinamespace spvtools {
23fd4e5da5Sopenharmony_cinamespace opt {
24fd4e5da5Sopenharmony_cinamespace {
25fd4e5da5Sopenharmony_ci
26fd4e5da5Sopenharmony_ciusing LocalSSAElimTest = PassTest<::testing::Test>;
27fd4e5da5Sopenharmony_ci
28fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, ForLoop) {
29fd4e5da5Sopenharmony_ci  // #version 140
30fd4e5da5Sopenharmony_ci  //
31fd4e5da5Sopenharmony_ci  // in vec4 BC;
32fd4e5da5Sopenharmony_ci  // out float fo;
33fd4e5da5Sopenharmony_ci  //
34fd4e5da5Sopenharmony_ci  // void main()
35fd4e5da5Sopenharmony_ci  // {
36fd4e5da5Sopenharmony_ci  //     float f = 0.0;
37fd4e5da5Sopenharmony_ci  //     for (int i=0; i<4; i++) {
38fd4e5da5Sopenharmony_ci  //       f = f + BC[i];
39fd4e5da5Sopenharmony_ci  //     }
40fd4e5da5Sopenharmony_ci  //     fo = f;
41fd4e5da5Sopenharmony_ci  // }
42fd4e5da5Sopenharmony_ci
43fd4e5da5Sopenharmony_ci  const std::string predefs =
44fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
45fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
46fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
47fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
48fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
49fd4e5da5Sopenharmony_ciOpSource GLSL 140
50fd4e5da5Sopenharmony_ciOpName %main "main"
51fd4e5da5Sopenharmony_ciOpName %f "f"
52fd4e5da5Sopenharmony_ciOpName %i "i"
53fd4e5da5Sopenharmony_ciOpName %BC "BC"
54fd4e5da5Sopenharmony_ciOpName %fo "fo"
55fd4e5da5Sopenharmony_ci%void = OpTypeVoid
56fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
57fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
58fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
59fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
60fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
61fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
62fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
63fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
64fd4e5da5Sopenharmony_ci%bool = OpTypeBool
65fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
66fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
67fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
68fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
69fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
70fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
71fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
72fd4e5da5Sopenharmony_ci)";
73fd4e5da5Sopenharmony_ci
74fd4e5da5Sopenharmony_ci  const std::string before =
75fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %8
76fd4e5da5Sopenharmony_ci%22 = OpLabel
77fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
78fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
79fd4e5da5Sopenharmony_ciOpStore %f %float_0
80fd4e5da5Sopenharmony_ciOpStore %i %int_0
81fd4e5da5Sopenharmony_ciOpBranch %23
82fd4e5da5Sopenharmony_ci%23 = OpLabel
83fd4e5da5Sopenharmony_ciOpLoopMerge %24 %25 None
84fd4e5da5Sopenharmony_ciOpBranch %26
85fd4e5da5Sopenharmony_ci%26 = OpLabel
86fd4e5da5Sopenharmony_ci%27 = OpLoad %int %i
87fd4e5da5Sopenharmony_ci%28 = OpSLessThan %bool %27 %int_4
88fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %24
89fd4e5da5Sopenharmony_ci%29 = OpLabel
90fd4e5da5Sopenharmony_ci%30 = OpLoad %float %f
91fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
92fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
93fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
94fd4e5da5Sopenharmony_ci%34 = OpFAdd %float %30 %33
95fd4e5da5Sopenharmony_ciOpStore %f %34
96fd4e5da5Sopenharmony_ciOpBranch %25
97fd4e5da5Sopenharmony_ci%25 = OpLabel
98fd4e5da5Sopenharmony_ci%35 = OpLoad %int %i
99fd4e5da5Sopenharmony_ci%36 = OpIAdd %int %35 %int_1
100fd4e5da5Sopenharmony_ciOpStore %i %36
101fd4e5da5Sopenharmony_ciOpBranch %23
102fd4e5da5Sopenharmony_ci%24 = OpLabel
103fd4e5da5Sopenharmony_ci%37 = OpLoad %float %f
104fd4e5da5Sopenharmony_ciOpStore %fo %37
105fd4e5da5Sopenharmony_ciOpReturn
106fd4e5da5Sopenharmony_ciOpFunctionEnd
107fd4e5da5Sopenharmony_ci)";
108fd4e5da5Sopenharmony_ci
109fd4e5da5Sopenharmony_ci  const std::string after =
110fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %8
111fd4e5da5Sopenharmony_ci%22 = OpLabel
112fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
113fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
114fd4e5da5Sopenharmony_ciOpStore %f %float_0
115fd4e5da5Sopenharmony_ciOpStore %i %int_0
116fd4e5da5Sopenharmony_ciOpBranch %23
117fd4e5da5Sopenharmony_ci%23 = OpLabel
118fd4e5da5Sopenharmony_ci%39 = OpPhi %float %float_0 %22 %34 %25
119fd4e5da5Sopenharmony_ci%38 = OpPhi %int %int_0 %22 %36 %25
120fd4e5da5Sopenharmony_ciOpLoopMerge %24 %25 None
121fd4e5da5Sopenharmony_ciOpBranch %26
122fd4e5da5Sopenharmony_ci%26 = OpLabel
123fd4e5da5Sopenharmony_ci%28 = OpSLessThan %bool %38 %int_4
124fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %24
125fd4e5da5Sopenharmony_ci%29 = OpLabel
126fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %38
127fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
128fd4e5da5Sopenharmony_ci%34 = OpFAdd %float %39 %33
129fd4e5da5Sopenharmony_ciOpStore %f %34
130fd4e5da5Sopenharmony_ciOpBranch %25
131fd4e5da5Sopenharmony_ci%25 = OpLabel
132fd4e5da5Sopenharmony_ci%36 = OpIAdd %int %38 %int_1
133fd4e5da5Sopenharmony_ciOpStore %i %36
134fd4e5da5Sopenharmony_ciOpBranch %23
135fd4e5da5Sopenharmony_ci%24 = OpLabel
136fd4e5da5Sopenharmony_ciOpStore %fo %39
137fd4e5da5Sopenharmony_ciOpReturn
138fd4e5da5Sopenharmony_ciOpFunctionEnd
139fd4e5da5Sopenharmony_ci)";
140fd4e5da5Sopenharmony_ci
141fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
142fd4e5da5Sopenharmony_ci                                        true);
143fd4e5da5Sopenharmony_ci}
144fd4e5da5Sopenharmony_ci
145fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, NestedForLoop) {
146fd4e5da5Sopenharmony_ci  // #version 450
147fd4e5da5Sopenharmony_ci  //
148fd4e5da5Sopenharmony_ci  // layout (location=0) in mat4 BC;
149fd4e5da5Sopenharmony_ci  // layout (location=0) out float fo;
150fd4e5da5Sopenharmony_ci  //
151fd4e5da5Sopenharmony_ci  // void main()
152fd4e5da5Sopenharmony_ci  // {
153fd4e5da5Sopenharmony_ci  //     float f = 0.0;
154fd4e5da5Sopenharmony_ci  //     for (int i=0; i<4; i++)
155fd4e5da5Sopenharmony_ci  //       for (int j=0; j<4; j++)
156fd4e5da5Sopenharmony_ci  //         f = f + BC[i][j];
157fd4e5da5Sopenharmony_ci  //     fo = f;
158fd4e5da5Sopenharmony_ci  // }
159fd4e5da5Sopenharmony_ci
160fd4e5da5Sopenharmony_ci  const std::string predefs =
161fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
162fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
163fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
164fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
165fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
166fd4e5da5Sopenharmony_ciOpSource GLSL 450
167fd4e5da5Sopenharmony_ciOpName %main "main"
168fd4e5da5Sopenharmony_ciOpName %f "f"
169fd4e5da5Sopenharmony_ciOpName %i "i"
170fd4e5da5Sopenharmony_ciOpName %j "j"
171fd4e5da5Sopenharmony_ciOpName %BC "BC"
172fd4e5da5Sopenharmony_ciOpName %fo "fo"
173fd4e5da5Sopenharmony_ciOpDecorate %BC Location 0
174fd4e5da5Sopenharmony_ciOpDecorate %fo Location 0
175fd4e5da5Sopenharmony_ci%void = OpTypeVoid
176fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
177fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
178fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
179fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
180fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
181fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
182fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
183fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
184fd4e5da5Sopenharmony_ci%bool = OpTypeBool
185fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
186fd4e5da5Sopenharmony_ci%mat4v4float = OpTypeMatrix %v4float 4
187fd4e5da5Sopenharmony_ci%_ptr_Input_mat4v4float = OpTypePointer Input %mat4v4float
188fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_mat4v4float Input
189fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
190fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
191fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
192fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
193fd4e5da5Sopenharmony_ci)";
194fd4e5da5Sopenharmony_ci
195fd4e5da5Sopenharmony_ci  const std::string before =
196fd4e5da5Sopenharmony_ci      R"(
197fd4e5da5Sopenharmony_ci; CHECK: = OpFunction
198fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[entry:%\w+]] = OpLabel
199fd4e5da5Sopenharmony_ci; CHECK: [[outer_header:%\w+]] = OpLabel
200fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[outer_f:%\w+]] = OpPhi %float %float_0 [[entry]] [[inner_f:%\w+]] [[outer_be:%\w+]]
201fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[i:%\w+]] = OpPhi %int %int_0 [[entry]] [[i_next:%\w+]] [[outer_be]]
202fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpSLessThan {{%\w+}} [[i]]
203fd4e5da5Sopenharmony_ci; CHECK: [[inner_pre_header:%\w+]] = OpLabel
204fd4e5da5Sopenharmony_ci; CHECK: [[inner_header:%\w+]] = OpLabel
205fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[inner_f]] = OpPhi %float [[outer_f]] [[inner_pre_header]] [[f_next:%\w+]] [[inner_be:%\w+]]
206fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[j:%\w+]] = OpPhi %int %int_0 [[inner_pre_header]] [[j_next:%\w+]] [[inner_be]]
207fd4e5da5Sopenharmony_ci; CHECK: [[inner_be]] = OpLabel
208fd4e5da5Sopenharmony_ci; CHECK: [[f_next]] = OpFAdd %float [[inner_f]]
209fd4e5da5Sopenharmony_ci; CHECK: [[j_next]] = OpIAdd %int [[j]] %int_1
210fd4e5da5Sopenharmony_ci; CHECK: [[outer_be]] = OpLabel
211fd4e5da5Sopenharmony_ci; CHECK: [[i_next]] = OpIAdd
212fd4e5da5Sopenharmony_ci; CHECK: OpStore %fo [[outer_f]]
213fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
214fd4e5da5Sopenharmony_ci%24 = OpLabel
215fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
216fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
217fd4e5da5Sopenharmony_ci%j = OpVariable %_ptr_Function_int Function
218fd4e5da5Sopenharmony_ciOpStore %f %float_0
219fd4e5da5Sopenharmony_ciOpStore %i %int_0
220fd4e5da5Sopenharmony_ciOpBranch %25
221fd4e5da5Sopenharmony_ci%25 = OpLabel
222fd4e5da5Sopenharmony_ci%26 = OpLoad %int %i
223fd4e5da5Sopenharmony_ci%27 = OpSLessThan %bool %26 %int_4
224fd4e5da5Sopenharmony_ciOpLoopMerge %28 %29 None
225fd4e5da5Sopenharmony_ciOpBranchConditional %27 %30 %28
226fd4e5da5Sopenharmony_ci%30 = OpLabel
227fd4e5da5Sopenharmony_ciOpStore %j %int_0
228fd4e5da5Sopenharmony_ciOpBranch %31
229fd4e5da5Sopenharmony_ci%31 = OpLabel
230fd4e5da5Sopenharmony_ci%32 = OpLoad %int %j
231fd4e5da5Sopenharmony_ci%33 = OpSLessThan %bool %32 %int_4
232fd4e5da5Sopenharmony_ciOpLoopMerge %50 %34 None
233fd4e5da5Sopenharmony_ciOpBranchConditional %33 %34 %50
234fd4e5da5Sopenharmony_ci%34 = OpLabel
235fd4e5da5Sopenharmony_ci%35 = OpLoad %float %f
236fd4e5da5Sopenharmony_ci%36 = OpLoad %int %i
237fd4e5da5Sopenharmony_ci%37 = OpLoad %int %j
238fd4e5da5Sopenharmony_ci%38 = OpAccessChain %_ptr_Input_float %BC %36 %37
239fd4e5da5Sopenharmony_ci%39 = OpLoad %float %38
240fd4e5da5Sopenharmony_ci%40 = OpFAdd %float %35 %39
241fd4e5da5Sopenharmony_ciOpStore %f %40
242fd4e5da5Sopenharmony_ci%41 = OpLoad %int %j
243fd4e5da5Sopenharmony_ci%42 = OpIAdd %int %41 %int_1
244fd4e5da5Sopenharmony_ciOpStore %j %42
245fd4e5da5Sopenharmony_ciOpBranch %31
246fd4e5da5Sopenharmony_ci%50 = OpLabel
247fd4e5da5Sopenharmony_ciOpBranch %29
248fd4e5da5Sopenharmony_ci%29 = OpLabel
249fd4e5da5Sopenharmony_ci%43 = OpLoad %int %i
250fd4e5da5Sopenharmony_ci%44 = OpIAdd %int %43 %int_1
251fd4e5da5Sopenharmony_ciOpStore %i %44
252fd4e5da5Sopenharmony_ciOpBranch %25
253fd4e5da5Sopenharmony_ci%28 = OpLabel
254fd4e5da5Sopenharmony_ci%45 = OpLoad %float %f
255fd4e5da5Sopenharmony_ciOpStore %fo %45
256fd4e5da5Sopenharmony_ciOpReturn
257fd4e5da5Sopenharmony_ciOpFunctionEnd
258fd4e5da5Sopenharmony_ci)";
259fd4e5da5Sopenharmony_ci
260fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(predefs + before, true);
261fd4e5da5Sopenharmony_ci}
262fd4e5da5Sopenharmony_ci
263fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, ForLoopWithContinue) {
264fd4e5da5Sopenharmony_ci  // #version 140
265fd4e5da5Sopenharmony_ci  //
266fd4e5da5Sopenharmony_ci  // in vec4 BC;
267fd4e5da5Sopenharmony_ci  // out float fo;
268fd4e5da5Sopenharmony_ci  //
269fd4e5da5Sopenharmony_ci  // void main()
270fd4e5da5Sopenharmony_ci  // {
271fd4e5da5Sopenharmony_ci  //     float f = 0.0;
272fd4e5da5Sopenharmony_ci  //     for (int i=0; i<4; i++) {
273fd4e5da5Sopenharmony_ci  //       float t = BC[i];
274fd4e5da5Sopenharmony_ci  //       if (t < 0.0)
275fd4e5da5Sopenharmony_ci  //         continue;
276fd4e5da5Sopenharmony_ci  //       f = f + t;
277fd4e5da5Sopenharmony_ci  //     }
278fd4e5da5Sopenharmony_ci  //     fo = f;
279fd4e5da5Sopenharmony_ci  // }
280fd4e5da5Sopenharmony_ci
281fd4e5da5Sopenharmony_ci  const std::string predefs =
282fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
283fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
284fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
285fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
286fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
287fd4e5da5Sopenharmony_ciOpSource GLSL 140
288fd4e5da5Sopenharmony_ci)";
289fd4e5da5Sopenharmony_ci
290fd4e5da5Sopenharmony_ci  const std::string names =
291fd4e5da5Sopenharmony_ci      R"(OpName %main "main"
292fd4e5da5Sopenharmony_ciOpName %f "f"
293fd4e5da5Sopenharmony_ciOpName %i "i"
294fd4e5da5Sopenharmony_ciOpName %t "t"
295fd4e5da5Sopenharmony_ciOpName %BC "BC"
296fd4e5da5Sopenharmony_ciOpName %fo "fo"
297fd4e5da5Sopenharmony_ci)";
298fd4e5da5Sopenharmony_ci
299fd4e5da5Sopenharmony_ci  const std::string predefs2 =
300fd4e5da5Sopenharmony_ci      R"(%void = OpTypeVoid
301fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
302fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
303fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
304fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
305fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
306fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
307fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
308fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
309fd4e5da5Sopenharmony_ci%bool = OpTypeBool
310fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
311fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
312fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
313fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
314fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
315fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
316fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
317fd4e5da5Sopenharmony_ci)";
318fd4e5da5Sopenharmony_ci
319fd4e5da5Sopenharmony_ci  const std::string before =
320fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %9
321fd4e5da5Sopenharmony_ci%23 = OpLabel
322fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
323fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
324fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
325fd4e5da5Sopenharmony_ciOpStore %f %float_0
326fd4e5da5Sopenharmony_ciOpStore %i %int_0
327fd4e5da5Sopenharmony_ciOpBranch %24
328fd4e5da5Sopenharmony_ci%24 = OpLabel
329fd4e5da5Sopenharmony_ciOpLoopMerge %25 %26 None
330fd4e5da5Sopenharmony_ciOpBranch %27
331fd4e5da5Sopenharmony_ci%27 = OpLabel
332fd4e5da5Sopenharmony_ci%28 = OpLoad %int %i
333fd4e5da5Sopenharmony_ci%29 = OpSLessThan %bool %28 %int_4
334fd4e5da5Sopenharmony_ciOpBranchConditional %29 %30 %25
335fd4e5da5Sopenharmony_ci%30 = OpLabel
336fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
337fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
338fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
339fd4e5da5Sopenharmony_ciOpStore %t %33
340fd4e5da5Sopenharmony_ci%34 = OpLoad %float %t
341fd4e5da5Sopenharmony_ci%35 = OpFOrdLessThan %bool %34 %float_0
342fd4e5da5Sopenharmony_ciOpSelectionMerge %36 None
343fd4e5da5Sopenharmony_ciOpBranchConditional %35 %37 %36
344fd4e5da5Sopenharmony_ci%37 = OpLabel
345fd4e5da5Sopenharmony_ciOpBranch %26
346fd4e5da5Sopenharmony_ci%36 = OpLabel
347fd4e5da5Sopenharmony_ci%38 = OpLoad %float %f
348fd4e5da5Sopenharmony_ci%39 = OpLoad %float %t
349fd4e5da5Sopenharmony_ci%40 = OpFAdd %float %38 %39
350fd4e5da5Sopenharmony_ciOpStore %f %40
351fd4e5da5Sopenharmony_ciOpBranch %26
352fd4e5da5Sopenharmony_ci%26 = OpLabel
353fd4e5da5Sopenharmony_ci%41 = OpLoad %int %i
354fd4e5da5Sopenharmony_ci%42 = OpIAdd %int %41 %int_1
355fd4e5da5Sopenharmony_ciOpStore %i %42
356fd4e5da5Sopenharmony_ciOpBranch %24
357fd4e5da5Sopenharmony_ci%25 = OpLabel
358fd4e5da5Sopenharmony_ci%43 = OpLoad %float %f
359fd4e5da5Sopenharmony_ciOpStore %fo %43
360fd4e5da5Sopenharmony_ciOpReturn
361fd4e5da5Sopenharmony_ciOpFunctionEnd
362fd4e5da5Sopenharmony_ci)";
363fd4e5da5Sopenharmony_ci
364fd4e5da5Sopenharmony_ci  const std::string after =
365fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %9
366fd4e5da5Sopenharmony_ci%23 = OpLabel
367fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
368fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
369fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
370fd4e5da5Sopenharmony_ciOpStore %f %float_0
371fd4e5da5Sopenharmony_ciOpStore %i %int_0
372fd4e5da5Sopenharmony_ciOpBranch %24
373fd4e5da5Sopenharmony_ci%24 = OpLabel
374fd4e5da5Sopenharmony_ci%45 = OpPhi %float %float_0 %23 %47 %26
375fd4e5da5Sopenharmony_ci%44 = OpPhi %int %int_0 %23 %42 %26
376fd4e5da5Sopenharmony_ciOpLoopMerge %25 %26 None
377fd4e5da5Sopenharmony_ciOpBranch %27
378fd4e5da5Sopenharmony_ci%27 = OpLabel
379fd4e5da5Sopenharmony_ci%29 = OpSLessThan %bool %44 %int_4
380fd4e5da5Sopenharmony_ciOpBranchConditional %29 %30 %25
381fd4e5da5Sopenharmony_ci%30 = OpLabel
382fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %44
383fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
384fd4e5da5Sopenharmony_ciOpStore %t %33
385fd4e5da5Sopenharmony_ci%35 = OpFOrdLessThan %bool %33 %float_0
386fd4e5da5Sopenharmony_ciOpSelectionMerge %36 None
387fd4e5da5Sopenharmony_ciOpBranchConditional %35 %37 %36
388fd4e5da5Sopenharmony_ci%37 = OpLabel
389fd4e5da5Sopenharmony_ciOpBranch %26
390fd4e5da5Sopenharmony_ci%36 = OpLabel
391fd4e5da5Sopenharmony_ci%40 = OpFAdd %float %45 %33
392fd4e5da5Sopenharmony_ciOpStore %f %40
393fd4e5da5Sopenharmony_ciOpBranch %26
394fd4e5da5Sopenharmony_ci%26 = OpLabel
395fd4e5da5Sopenharmony_ci%47 = OpPhi %float %45 %37 %40 %36
396fd4e5da5Sopenharmony_ci%42 = OpIAdd %int %44 %int_1
397fd4e5da5Sopenharmony_ciOpStore %i %42
398fd4e5da5Sopenharmony_ciOpBranch %24
399fd4e5da5Sopenharmony_ci%25 = OpLabel
400fd4e5da5Sopenharmony_ciOpStore %fo %45
401fd4e5da5Sopenharmony_ciOpReturn
402fd4e5da5Sopenharmony_ciOpFunctionEnd
403fd4e5da5Sopenharmony_ci)";
404fd4e5da5Sopenharmony_ci
405fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(predefs + names + predefs2 + before,
406fd4e5da5Sopenharmony_ci                                        predefs + names + predefs2 + after,
407fd4e5da5Sopenharmony_ci                                        true, true);
408fd4e5da5Sopenharmony_ci}
409fd4e5da5Sopenharmony_ci
410fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, ForLoopWithBreak) {
411fd4e5da5Sopenharmony_ci  // #version 140
412fd4e5da5Sopenharmony_ci  //
413fd4e5da5Sopenharmony_ci  // in vec4 BC;
414fd4e5da5Sopenharmony_ci  // out float fo;
415fd4e5da5Sopenharmony_ci  //
416fd4e5da5Sopenharmony_ci  // void main()
417fd4e5da5Sopenharmony_ci  // {
418fd4e5da5Sopenharmony_ci  //     float f = 0.0;
419fd4e5da5Sopenharmony_ci  //     for (int i=0; i<4; i++) {
420fd4e5da5Sopenharmony_ci  //       float t = f + BC[i];
421fd4e5da5Sopenharmony_ci  //       if (t > 1.0)
422fd4e5da5Sopenharmony_ci  //         break;
423fd4e5da5Sopenharmony_ci  //       f = t;
424fd4e5da5Sopenharmony_ci  //     }
425fd4e5da5Sopenharmony_ci  //     fo = f;
426fd4e5da5Sopenharmony_ci  // }
427fd4e5da5Sopenharmony_ci
428fd4e5da5Sopenharmony_ci  const std::string predefs =
429fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
430fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
431fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
432fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
433fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
434fd4e5da5Sopenharmony_ciOpSource GLSL 140
435fd4e5da5Sopenharmony_ciOpName %main "main"
436fd4e5da5Sopenharmony_ciOpName %f "f"
437fd4e5da5Sopenharmony_ciOpName %i "i"
438fd4e5da5Sopenharmony_ciOpName %t "t"
439fd4e5da5Sopenharmony_ciOpName %BC "BC"
440fd4e5da5Sopenharmony_ciOpName %fo "fo"
441fd4e5da5Sopenharmony_ci%void = OpTypeVoid
442fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
443fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
444fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
445fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
446fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
447fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
448fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
449fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
450fd4e5da5Sopenharmony_ci%bool = OpTypeBool
451fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
452fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
453fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
454fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
455fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
456fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
457fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
458fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
459fd4e5da5Sopenharmony_ci)";
460fd4e5da5Sopenharmony_ci
461fd4e5da5Sopenharmony_ci  const std::string before =
462fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %9
463fd4e5da5Sopenharmony_ci%24 = OpLabel
464fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
465fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
466fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
467fd4e5da5Sopenharmony_ciOpStore %f %float_0
468fd4e5da5Sopenharmony_ciOpStore %i %int_0
469fd4e5da5Sopenharmony_ciOpBranch %25
470fd4e5da5Sopenharmony_ci%25 = OpLabel
471fd4e5da5Sopenharmony_ciOpLoopMerge %26 %27 None
472fd4e5da5Sopenharmony_ciOpBranch %28
473fd4e5da5Sopenharmony_ci%28 = OpLabel
474fd4e5da5Sopenharmony_ci%29 = OpLoad %int %i
475fd4e5da5Sopenharmony_ci%30 = OpSLessThan %bool %29 %int_4
476fd4e5da5Sopenharmony_ciOpBranchConditional %30 %31 %26
477fd4e5da5Sopenharmony_ci%31 = OpLabel
478fd4e5da5Sopenharmony_ci%32 = OpLoad %float %f
479fd4e5da5Sopenharmony_ci%33 = OpLoad %int %i
480fd4e5da5Sopenharmony_ci%34 = OpAccessChain %_ptr_Input_float %BC %33
481fd4e5da5Sopenharmony_ci%35 = OpLoad %float %34
482fd4e5da5Sopenharmony_ci%36 = OpFAdd %float %32 %35
483fd4e5da5Sopenharmony_ciOpStore %t %36
484fd4e5da5Sopenharmony_ci%37 = OpLoad %float %t
485fd4e5da5Sopenharmony_ci%38 = OpFOrdGreaterThan %bool %37 %float_1
486fd4e5da5Sopenharmony_ciOpSelectionMerge %39 None
487fd4e5da5Sopenharmony_ciOpBranchConditional %38 %40 %39
488fd4e5da5Sopenharmony_ci%40 = OpLabel
489fd4e5da5Sopenharmony_ciOpBranch %26
490fd4e5da5Sopenharmony_ci%39 = OpLabel
491fd4e5da5Sopenharmony_ci%41 = OpLoad %float %t
492fd4e5da5Sopenharmony_ciOpStore %f %41
493fd4e5da5Sopenharmony_ciOpBranch %27
494fd4e5da5Sopenharmony_ci%27 = OpLabel
495fd4e5da5Sopenharmony_ci%42 = OpLoad %int %i
496fd4e5da5Sopenharmony_ci%43 = OpIAdd %int %42 %int_1
497fd4e5da5Sopenharmony_ciOpStore %i %43
498fd4e5da5Sopenharmony_ciOpBranch %25
499fd4e5da5Sopenharmony_ci%26 = OpLabel
500fd4e5da5Sopenharmony_ci%44 = OpLoad %float %f
501fd4e5da5Sopenharmony_ciOpStore %fo %44
502fd4e5da5Sopenharmony_ciOpReturn
503fd4e5da5Sopenharmony_ciOpFunctionEnd
504fd4e5da5Sopenharmony_ci)";
505fd4e5da5Sopenharmony_ci
506fd4e5da5Sopenharmony_ci  const std::string after =
507fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %9
508fd4e5da5Sopenharmony_ci%24 = OpLabel
509fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
510fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
511fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
512fd4e5da5Sopenharmony_ciOpStore %f %float_0
513fd4e5da5Sopenharmony_ciOpStore %i %int_0
514fd4e5da5Sopenharmony_ciOpBranch %25
515fd4e5da5Sopenharmony_ci%25 = OpLabel
516fd4e5da5Sopenharmony_ci%46 = OpPhi %float %float_0 %24 %36 %27
517fd4e5da5Sopenharmony_ci%45 = OpPhi %int %int_0 %24 %43 %27
518fd4e5da5Sopenharmony_ciOpLoopMerge %26 %27 None
519fd4e5da5Sopenharmony_ciOpBranch %28
520fd4e5da5Sopenharmony_ci%28 = OpLabel
521fd4e5da5Sopenharmony_ci%30 = OpSLessThan %bool %45 %int_4
522fd4e5da5Sopenharmony_ciOpBranchConditional %30 %31 %26
523fd4e5da5Sopenharmony_ci%31 = OpLabel
524fd4e5da5Sopenharmony_ci%34 = OpAccessChain %_ptr_Input_float %BC %45
525fd4e5da5Sopenharmony_ci%35 = OpLoad %float %34
526fd4e5da5Sopenharmony_ci%36 = OpFAdd %float %46 %35
527fd4e5da5Sopenharmony_ciOpStore %t %36
528fd4e5da5Sopenharmony_ci%38 = OpFOrdGreaterThan %bool %36 %float_1
529fd4e5da5Sopenharmony_ciOpSelectionMerge %39 None
530fd4e5da5Sopenharmony_ciOpBranchConditional %38 %40 %39
531fd4e5da5Sopenharmony_ci%40 = OpLabel
532fd4e5da5Sopenharmony_ciOpBranch %26
533fd4e5da5Sopenharmony_ci%39 = OpLabel
534fd4e5da5Sopenharmony_ciOpStore %f %36
535fd4e5da5Sopenharmony_ciOpBranch %27
536fd4e5da5Sopenharmony_ci%27 = OpLabel
537fd4e5da5Sopenharmony_ci%43 = OpIAdd %int %45 %int_1
538fd4e5da5Sopenharmony_ciOpStore %i %43
539fd4e5da5Sopenharmony_ciOpBranch %25
540fd4e5da5Sopenharmony_ci%26 = OpLabel
541fd4e5da5Sopenharmony_ciOpStore %fo %46
542fd4e5da5Sopenharmony_ciOpReturn
543fd4e5da5Sopenharmony_ciOpFunctionEnd
544fd4e5da5Sopenharmony_ci)";
545fd4e5da5Sopenharmony_ci
546fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
547fd4e5da5Sopenharmony_ci                                        true);
548fd4e5da5Sopenharmony_ci}
549fd4e5da5Sopenharmony_ci
550fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, SwapProblem) {
551fd4e5da5Sopenharmony_ci  // #version 140
552fd4e5da5Sopenharmony_ci  //
553fd4e5da5Sopenharmony_ci  // in float fe;
554fd4e5da5Sopenharmony_ci  // out float fo;
555fd4e5da5Sopenharmony_ci  //
556fd4e5da5Sopenharmony_ci  // void main()
557fd4e5da5Sopenharmony_ci  // {
558fd4e5da5Sopenharmony_ci  //     float f1 = 0.0;
559fd4e5da5Sopenharmony_ci  //     float f2 = 1.0;
560fd4e5da5Sopenharmony_ci  //     int ie = int(fe);
561fd4e5da5Sopenharmony_ci  //     for (int i=0; i<ie; i++) {
562fd4e5da5Sopenharmony_ci  //       float t = f1;
563fd4e5da5Sopenharmony_ci  //       f1 = f2;
564fd4e5da5Sopenharmony_ci  //       f2 = t;
565fd4e5da5Sopenharmony_ci  //     }
566fd4e5da5Sopenharmony_ci  //     fo = f1;
567fd4e5da5Sopenharmony_ci  // }
568fd4e5da5Sopenharmony_ci
569fd4e5da5Sopenharmony_ci  const std::string predefs =
570fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
571fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
572fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
573fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %fe %fo
574fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
575fd4e5da5Sopenharmony_ciOpSource GLSL 140
576fd4e5da5Sopenharmony_ciOpName %main "main"
577fd4e5da5Sopenharmony_ciOpName %f1 "f1"
578fd4e5da5Sopenharmony_ciOpName %f2 "f2"
579fd4e5da5Sopenharmony_ciOpName %ie "ie"
580fd4e5da5Sopenharmony_ciOpName %fe "fe"
581fd4e5da5Sopenharmony_ciOpName %i "i"
582fd4e5da5Sopenharmony_ciOpName %t "t"
583fd4e5da5Sopenharmony_ciOpName %fo "fo"
584fd4e5da5Sopenharmony_ci%void = OpTypeVoid
585fd4e5da5Sopenharmony_ci%11 = OpTypeFunction %void
586fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
587fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
588fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
589fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
590fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
591fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
592fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
593fd4e5da5Sopenharmony_ci%fe = OpVariable %_ptr_Input_float Input
594fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
595fd4e5da5Sopenharmony_ci%bool = OpTypeBool
596fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
597fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
598fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
599fd4e5da5Sopenharmony_ci)";
600fd4e5da5Sopenharmony_ci
601fd4e5da5Sopenharmony_ci  const std::string before =
602fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %11
603fd4e5da5Sopenharmony_ci%23 = OpLabel
604fd4e5da5Sopenharmony_ci%f1 = OpVariable %_ptr_Function_float Function
605fd4e5da5Sopenharmony_ci%f2 = OpVariable %_ptr_Function_float Function
606fd4e5da5Sopenharmony_ci%ie = OpVariable %_ptr_Function_int Function
607fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
608fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
609fd4e5da5Sopenharmony_ciOpStore %f1 %float_0
610fd4e5da5Sopenharmony_ciOpStore %f2 %float_1
611fd4e5da5Sopenharmony_ci%24 = OpLoad %float %fe
612fd4e5da5Sopenharmony_ci%25 = OpConvertFToS %int %24
613fd4e5da5Sopenharmony_ciOpStore %ie %25
614fd4e5da5Sopenharmony_ciOpStore %i %int_0
615fd4e5da5Sopenharmony_ciOpBranch %26
616fd4e5da5Sopenharmony_ci%26 = OpLabel
617fd4e5da5Sopenharmony_ciOpLoopMerge %27 %28 None
618fd4e5da5Sopenharmony_ciOpBranch %29
619fd4e5da5Sopenharmony_ci%29 = OpLabel
620fd4e5da5Sopenharmony_ci%30 = OpLoad %int %i
621fd4e5da5Sopenharmony_ci%31 = OpLoad %int %ie
622fd4e5da5Sopenharmony_ci%32 = OpSLessThan %bool %30 %31
623fd4e5da5Sopenharmony_ciOpBranchConditional %32 %33 %27
624fd4e5da5Sopenharmony_ci%33 = OpLabel
625fd4e5da5Sopenharmony_ci%34 = OpLoad %float %f1
626fd4e5da5Sopenharmony_ciOpStore %t %34
627fd4e5da5Sopenharmony_ci%35 = OpLoad %float %f2
628fd4e5da5Sopenharmony_ciOpStore %f1 %35
629fd4e5da5Sopenharmony_ci%36 = OpLoad %float %t
630fd4e5da5Sopenharmony_ciOpStore %f2 %36
631fd4e5da5Sopenharmony_ciOpBranch %28
632fd4e5da5Sopenharmony_ci%28 = OpLabel
633fd4e5da5Sopenharmony_ci%37 = OpLoad %int %i
634fd4e5da5Sopenharmony_ci%38 = OpIAdd %int %37 %int_1
635fd4e5da5Sopenharmony_ciOpStore %i %38
636fd4e5da5Sopenharmony_ciOpBranch %26
637fd4e5da5Sopenharmony_ci%27 = OpLabel
638fd4e5da5Sopenharmony_ci%39 = OpLoad %float %f1
639fd4e5da5Sopenharmony_ciOpStore %fo %39
640fd4e5da5Sopenharmony_ciOpReturn
641fd4e5da5Sopenharmony_ciOpFunctionEnd
642fd4e5da5Sopenharmony_ci)";
643fd4e5da5Sopenharmony_ci
644fd4e5da5Sopenharmony_ci  const std::string after =
645fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %11
646fd4e5da5Sopenharmony_ci%23 = OpLabel
647fd4e5da5Sopenharmony_ci%f1 = OpVariable %_ptr_Function_float Function
648fd4e5da5Sopenharmony_ci%f2 = OpVariable %_ptr_Function_float Function
649fd4e5da5Sopenharmony_ci%ie = OpVariable %_ptr_Function_int Function
650fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
651fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
652fd4e5da5Sopenharmony_ciOpStore %f1 %float_0
653fd4e5da5Sopenharmony_ciOpStore %f2 %float_1
654fd4e5da5Sopenharmony_ci%24 = OpLoad %float %fe
655fd4e5da5Sopenharmony_ci%25 = OpConvertFToS %int %24
656fd4e5da5Sopenharmony_ciOpStore %ie %25
657fd4e5da5Sopenharmony_ciOpStore %i %int_0
658fd4e5da5Sopenharmony_ciOpBranch %26
659fd4e5da5Sopenharmony_ci%26 = OpLabel
660fd4e5da5Sopenharmony_ci%43 = OpPhi %float %float_1 %23 %42 %28
661fd4e5da5Sopenharmony_ci%42 = OpPhi %float %float_0 %23 %43 %28
662fd4e5da5Sopenharmony_ci%40 = OpPhi %int %int_0 %23 %38 %28
663fd4e5da5Sopenharmony_ciOpLoopMerge %27 %28 None
664fd4e5da5Sopenharmony_ciOpBranch %29
665fd4e5da5Sopenharmony_ci%29 = OpLabel
666fd4e5da5Sopenharmony_ci%32 = OpSLessThan %bool %40 %25
667fd4e5da5Sopenharmony_ciOpBranchConditional %32 %33 %27
668fd4e5da5Sopenharmony_ci%33 = OpLabel
669fd4e5da5Sopenharmony_ciOpStore %t %42
670fd4e5da5Sopenharmony_ciOpStore %f1 %43
671fd4e5da5Sopenharmony_ciOpStore %f2 %42
672fd4e5da5Sopenharmony_ciOpBranch %28
673fd4e5da5Sopenharmony_ci%28 = OpLabel
674fd4e5da5Sopenharmony_ci%38 = OpIAdd %int %40 %int_1
675fd4e5da5Sopenharmony_ciOpStore %i %38
676fd4e5da5Sopenharmony_ciOpBranch %26
677fd4e5da5Sopenharmony_ci%27 = OpLabel
678fd4e5da5Sopenharmony_ciOpStore %fo %42
679fd4e5da5Sopenharmony_ciOpReturn
680fd4e5da5Sopenharmony_ciOpFunctionEnd
681fd4e5da5Sopenharmony_ci)";
682fd4e5da5Sopenharmony_ci
683fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
684fd4e5da5Sopenharmony_ci                                        true);
685fd4e5da5Sopenharmony_ci}
686fd4e5da5Sopenharmony_ci
687fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, LostCopyProblem) {
688fd4e5da5Sopenharmony_ci  // #version 140
689fd4e5da5Sopenharmony_ci  //
690fd4e5da5Sopenharmony_ci  // in vec4 BC;
691fd4e5da5Sopenharmony_ci  // out float fo;
692fd4e5da5Sopenharmony_ci  //
693fd4e5da5Sopenharmony_ci  // void main()
694fd4e5da5Sopenharmony_ci  // {
695fd4e5da5Sopenharmony_ci  //     float f = 0.0;
696fd4e5da5Sopenharmony_ci  //     float t;
697fd4e5da5Sopenharmony_ci  //     for (int i=0; i<4; i++) {
698fd4e5da5Sopenharmony_ci  //       t = f;
699fd4e5da5Sopenharmony_ci  //       f = f + BC[i];
700fd4e5da5Sopenharmony_ci  //       if (f > 1.0)
701fd4e5da5Sopenharmony_ci  //         break;
702fd4e5da5Sopenharmony_ci  //     }
703fd4e5da5Sopenharmony_ci  //     fo = t;
704fd4e5da5Sopenharmony_ci  // }
705fd4e5da5Sopenharmony_ci
706fd4e5da5Sopenharmony_ci  const std::string predefs =
707fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
708fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
709fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
710fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
711fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
712fd4e5da5Sopenharmony_ciOpSource GLSL 140
713fd4e5da5Sopenharmony_ciOpName %main "main"
714fd4e5da5Sopenharmony_ciOpName %f "f"
715fd4e5da5Sopenharmony_ciOpName %i "i"
716fd4e5da5Sopenharmony_ciOpName %t "t"
717fd4e5da5Sopenharmony_ciOpName %BC "BC"
718fd4e5da5Sopenharmony_ciOpName %fo "fo"
719fd4e5da5Sopenharmony_ci%void = OpTypeVoid
720fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
721fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
722fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
723fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
724fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
725fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
726fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
727fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
728fd4e5da5Sopenharmony_ci%bool = OpTypeBool
729fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
730fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
731fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
732fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
733fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
734fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
735fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
736fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
737fd4e5da5Sopenharmony_ci)";
738fd4e5da5Sopenharmony_ci
739fd4e5da5Sopenharmony_ci  const std::string before =
740fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %9
741fd4e5da5Sopenharmony_ci%24 = OpLabel
742fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
743fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
744fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
745fd4e5da5Sopenharmony_ciOpStore %f %float_0
746fd4e5da5Sopenharmony_ciOpStore %i %int_0
747fd4e5da5Sopenharmony_ciOpBranch %25
748fd4e5da5Sopenharmony_ci%25 = OpLabel
749fd4e5da5Sopenharmony_ciOpLoopMerge %26 %27 None
750fd4e5da5Sopenharmony_ciOpBranch %28
751fd4e5da5Sopenharmony_ci%28 = OpLabel
752fd4e5da5Sopenharmony_ci%29 = OpLoad %int %i
753fd4e5da5Sopenharmony_ci%30 = OpSLessThan %bool %29 %int_4
754fd4e5da5Sopenharmony_ciOpBranchConditional %30 %31 %26
755fd4e5da5Sopenharmony_ci%31 = OpLabel
756fd4e5da5Sopenharmony_ci%32 = OpLoad %float %f
757fd4e5da5Sopenharmony_ciOpStore %t %32
758fd4e5da5Sopenharmony_ci%33 = OpLoad %float %f
759fd4e5da5Sopenharmony_ci%34 = OpLoad %int %i
760fd4e5da5Sopenharmony_ci%35 = OpAccessChain %_ptr_Input_float %BC %34
761fd4e5da5Sopenharmony_ci%36 = OpLoad %float %35
762fd4e5da5Sopenharmony_ci%37 = OpFAdd %float %33 %36
763fd4e5da5Sopenharmony_ciOpStore %f %37
764fd4e5da5Sopenharmony_ci%38 = OpLoad %float %f
765fd4e5da5Sopenharmony_ci%39 = OpFOrdGreaterThan %bool %38 %float_1
766fd4e5da5Sopenharmony_ciOpSelectionMerge %40 None
767fd4e5da5Sopenharmony_ciOpBranchConditional %39 %41 %40
768fd4e5da5Sopenharmony_ci%41 = OpLabel
769fd4e5da5Sopenharmony_ciOpBranch %26
770fd4e5da5Sopenharmony_ci%40 = OpLabel
771fd4e5da5Sopenharmony_ciOpBranch %27
772fd4e5da5Sopenharmony_ci%27 = OpLabel
773fd4e5da5Sopenharmony_ci%42 = OpLoad %int %i
774fd4e5da5Sopenharmony_ci%43 = OpIAdd %int %42 %int_1
775fd4e5da5Sopenharmony_ciOpStore %i %43
776fd4e5da5Sopenharmony_ciOpBranch %25
777fd4e5da5Sopenharmony_ci%26 = OpLabel
778fd4e5da5Sopenharmony_ci%44 = OpLoad %float %t
779fd4e5da5Sopenharmony_ciOpStore %fo %44
780fd4e5da5Sopenharmony_ciOpReturn
781fd4e5da5Sopenharmony_ciOpFunctionEnd
782fd4e5da5Sopenharmony_ci)";
783fd4e5da5Sopenharmony_ci
784fd4e5da5Sopenharmony_ci  const std::string after =
785fd4e5da5Sopenharmony_ci      R"(%49 = OpUndef %float
786fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
787fd4e5da5Sopenharmony_ci%24 = OpLabel
788fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
789fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
790fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
791fd4e5da5Sopenharmony_ciOpStore %f %float_0
792fd4e5da5Sopenharmony_ciOpStore %i %int_0
793fd4e5da5Sopenharmony_ciOpBranch %25
794fd4e5da5Sopenharmony_ci%25 = OpLabel
795fd4e5da5Sopenharmony_ci%46 = OpPhi %float %float_0 %24 %37 %27
796fd4e5da5Sopenharmony_ci%45 = OpPhi %int %int_0 %24 %43 %27
797fd4e5da5Sopenharmony_ci%48 = OpPhi %float %49 %24 %46 %27
798fd4e5da5Sopenharmony_ciOpLoopMerge %26 %27 None
799fd4e5da5Sopenharmony_ciOpBranch %28
800fd4e5da5Sopenharmony_ci%28 = OpLabel
801fd4e5da5Sopenharmony_ci%30 = OpSLessThan %bool %45 %int_4
802fd4e5da5Sopenharmony_ciOpBranchConditional %30 %31 %26
803fd4e5da5Sopenharmony_ci%31 = OpLabel
804fd4e5da5Sopenharmony_ciOpStore %t %46
805fd4e5da5Sopenharmony_ci%35 = OpAccessChain %_ptr_Input_float %BC %45
806fd4e5da5Sopenharmony_ci%36 = OpLoad %float %35
807fd4e5da5Sopenharmony_ci%37 = OpFAdd %float %46 %36
808fd4e5da5Sopenharmony_ciOpStore %f %37
809fd4e5da5Sopenharmony_ci%39 = OpFOrdGreaterThan %bool %37 %float_1
810fd4e5da5Sopenharmony_ciOpSelectionMerge %40 None
811fd4e5da5Sopenharmony_ciOpBranchConditional %39 %41 %40
812fd4e5da5Sopenharmony_ci%41 = OpLabel
813fd4e5da5Sopenharmony_ciOpBranch %26
814fd4e5da5Sopenharmony_ci%40 = OpLabel
815fd4e5da5Sopenharmony_ciOpBranch %27
816fd4e5da5Sopenharmony_ci%27 = OpLabel
817fd4e5da5Sopenharmony_ci%43 = OpIAdd %int %45 %int_1
818fd4e5da5Sopenharmony_ciOpStore %i %43
819fd4e5da5Sopenharmony_ciOpBranch %25
820fd4e5da5Sopenharmony_ci%26 = OpLabel
821fd4e5da5Sopenharmony_ci%47 = OpPhi %float %48 %28 %46 %41
822fd4e5da5Sopenharmony_ciOpStore %fo %47
823fd4e5da5Sopenharmony_ciOpReturn
824fd4e5da5Sopenharmony_ciOpFunctionEnd
825fd4e5da5Sopenharmony_ci)";
826fd4e5da5Sopenharmony_ci
827fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
828fd4e5da5Sopenharmony_ci                                        true);
829fd4e5da5Sopenharmony_ci}
830fd4e5da5Sopenharmony_ci
831fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, IfThenElse) {
832fd4e5da5Sopenharmony_ci  // #version 140
833fd4e5da5Sopenharmony_ci  //
834fd4e5da5Sopenharmony_ci  // in vec4 BaseColor;
835fd4e5da5Sopenharmony_ci  // in float f;
836fd4e5da5Sopenharmony_ci  //
837fd4e5da5Sopenharmony_ci  // void main()
838fd4e5da5Sopenharmony_ci  // {
839fd4e5da5Sopenharmony_ci  //     vec4 v;
840fd4e5da5Sopenharmony_ci  //     if (f >= 0)
841fd4e5da5Sopenharmony_ci  //       v = BaseColor * 0.5;
842fd4e5da5Sopenharmony_ci  //     else
843fd4e5da5Sopenharmony_ci  //       v = BaseColor + vec4(1.0,1.0,1.0,1.0);
844fd4e5da5Sopenharmony_ci  //     gl_FragColor = v;
845fd4e5da5Sopenharmony_ci  // }
846fd4e5da5Sopenharmony_ci
847fd4e5da5Sopenharmony_ci  const std::string predefs =
848fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
849fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
850fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
851fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %f %BaseColor %gl_FragColor
852fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
853fd4e5da5Sopenharmony_ciOpSource GLSL 140
854fd4e5da5Sopenharmony_ciOpName %main "main"
855fd4e5da5Sopenharmony_ciOpName %f "f"
856fd4e5da5Sopenharmony_ciOpName %v "v"
857fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
858fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
859fd4e5da5Sopenharmony_ci%void = OpTypeVoid
860fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
861fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
862fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
863fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Input_float Input
864fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
865fd4e5da5Sopenharmony_ci%bool = OpTypeBool
866fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
867fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
868fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
869fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
870fd4e5da5Sopenharmony_ci%float_0_5 = OpConstant %float 0.5
871fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
872fd4e5da5Sopenharmony_ci%18 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
873fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
874fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
875fd4e5da5Sopenharmony_ci)";
876fd4e5da5Sopenharmony_ci
877fd4e5da5Sopenharmony_ci  const std::string before =
878fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %8
879fd4e5da5Sopenharmony_ci%20 = OpLabel
880fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
881fd4e5da5Sopenharmony_ci%21 = OpLoad %float %f
882fd4e5da5Sopenharmony_ci%22 = OpFOrdGreaterThanEqual %bool %21 %float_0
883fd4e5da5Sopenharmony_ciOpSelectionMerge %23 None
884fd4e5da5Sopenharmony_ciOpBranchConditional %22 %24 %25
885fd4e5da5Sopenharmony_ci%24 = OpLabel
886fd4e5da5Sopenharmony_ci%26 = OpLoad %v4float %BaseColor
887fd4e5da5Sopenharmony_ci%27 = OpVectorTimesScalar %v4float %26 %float_0_5
888fd4e5da5Sopenharmony_ciOpStore %v %27
889fd4e5da5Sopenharmony_ciOpBranch %23
890fd4e5da5Sopenharmony_ci%25 = OpLabel
891fd4e5da5Sopenharmony_ci%28 = OpLoad %v4float %BaseColor
892fd4e5da5Sopenharmony_ci%29 = OpFAdd %v4float %28 %18
893fd4e5da5Sopenharmony_ciOpStore %v %29
894fd4e5da5Sopenharmony_ciOpBranch %23
895fd4e5da5Sopenharmony_ci%23 = OpLabel
896fd4e5da5Sopenharmony_ci%30 = OpLoad %v4float %v
897fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %30
898fd4e5da5Sopenharmony_ciOpReturn
899fd4e5da5Sopenharmony_ciOpFunctionEnd
900fd4e5da5Sopenharmony_ci)";
901fd4e5da5Sopenharmony_ci
902fd4e5da5Sopenharmony_ci  const std::string after =
903fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %8
904fd4e5da5Sopenharmony_ci%20 = OpLabel
905fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
906fd4e5da5Sopenharmony_ci%21 = OpLoad %float %f
907fd4e5da5Sopenharmony_ci%22 = OpFOrdGreaterThanEqual %bool %21 %float_0
908fd4e5da5Sopenharmony_ciOpSelectionMerge %23 None
909fd4e5da5Sopenharmony_ciOpBranchConditional %22 %24 %25
910fd4e5da5Sopenharmony_ci%24 = OpLabel
911fd4e5da5Sopenharmony_ci%26 = OpLoad %v4float %BaseColor
912fd4e5da5Sopenharmony_ci%27 = OpVectorTimesScalar %v4float %26 %float_0_5
913fd4e5da5Sopenharmony_ciOpStore %v %27
914fd4e5da5Sopenharmony_ciOpBranch %23
915fd4e5da5Sopenharmony_ci%25 = OpLabel
916fd4e5da5Sopenharmony_ci%28 = OpLoad %v4float %BaseColor
917fd4e5da5Sopenharmony_ci%29 = OpFAdd %v4float %28 %18
918fd4e5da5Sopenharmony_ciOpStore %v %29
919fd4e5da5Sopenharmony_ciOpBranch %23
920fd4e5da5Sopenharmony_ci%23 = OpLabel
921fd4e5da5Sopenharmony_ci%31 = OpPhi %v4float %27 %24 %29 %25
922fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %31
923fd4e5da5Sopenharmony_ciOpReturn
924fd4e5da5Sopenharmony_ciOpFunctionEnd
925fd4e5da5Sopenharmony_ci)";
926fd4e5da5Sopenharmony_ci
927fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
928fd4e5da5Sopenharmony_ci                                        true);
929fd4e5da5Sopenharmony_ci}
930fd4e5da5Sopenharmony_ci
931fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, IfThen) {
932fd4e5da5Sopenharmony_ci  // #version 140
933fd4e5da5Sopenharmony_ci  //
934fd4e5da5Sopenharmony_ci  // in vec4 BaseColor;
935fd4e5da5Sopenharmony_ci  // in float f;
936fd4e5da5Sopenharmony_ci  //
937fd4e5da5Sopenharmony_ci  // void main()
938fd4e5da5Sopenharmony_ci  // {
939fd4e5da5Sopenharmony_ci  //     vec4 v = BaseColor;
940fd4e5da5Sopenharmony_ci  //     if (f <= 0)
941fd4e5da5Sopenharmony_ci  //       v = v * 0.5;
942fd4e5da5Sopenharmony_ci  //     gl_FragColor = v;
943fd4e5da5Sopenharmony_ci  // }
944fd4e5da5Sopenharmony_ci
945fd4e5da5Sopenharmony_ci  const std::string predefs =
946fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
947fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
948fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
949fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %f %gl_FragColor
950fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
951fd4e5da5Sopenharmony_ciOpSource GLSL 140
952fd4e5da5Sopenharmony_ciOpName %main "main"
953fd4e5da5Sopenharmony_ciOpName %v "v"
954fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
955fd4e5da5Sopenharmony_ciOpName %f "f"
956fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
957fd4e5da5Sopenharmony_ci%void = OpTypeVoid
958fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
959fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
960fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
961fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
962fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
963fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
964fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
965fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Input_float Input
966fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
967fd4e5da5Sopenharmony_ci%bool = OpTypeBool
968fd4e5da5Sopenharmony_ci%float_0_5 = OpConstant %float 0.5
969fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
970fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
971fd4e5da5Sopenharmony_ci)";
972fd4e5da5Sopenharmony_ci
973fd4e5da5Sopenharmony_ci  const std::string before =
974fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %8
975fd4e5da5Sopenharmony_ci%18 = OpLabel
976fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
977fd4e5da5Sopenharmony_ci%19 = OpLoad %v4float %BaseColor
978fd4e5da5Sopenharmony_ciOpStore %v %19
979fd4e5da5Sopenharmony_ci%20 = OpLoad %float %f
980fd4e5da5Sopenharmony_ci%21 = OpFOrdLessThanEqual %bool %20 %float_0
981fd4e5da5Sopenharmony_ciOpSelectionMerge %22 None
982fd4e5da5Sopenharmony_ciOpBranchConditional %21 %23 %22
983fd4e5da5Sopenharmony_ci%23 = OpLabel
984fd4e5da5Sopenharmony_ci%24 = OpLoad %v4float %v
985fd4e5da5Sopenharmony_ci%25 = OpVectorTimesScalar %v4float %24 %float_0_5
986fd4e5da5Sopenharmony_ciOpStore %v %25
987fd4e5da5Sopenharmony_ciOpBranch %22
988fd4e5da5Sopenharmony_ci%22 = OpLabel
989fd4e5da5Sopenharmony_ci%26 = OpLoad %v4float %v
990fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %26
991fd4e5da5Sopenharmony_ciOpReturn
992fd4e5da5Sopenharmony_ciOpFunctionEnd
993fd4e5da5Sopenharmony_ci)";
994fd4e5da5Sopenharmony_ci
995fd4e5da5Sopenharmony_ci  const std::string after =
996fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %8
997fd4e5da5Sopenharmony_ci%18 = OpLabel
998fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
999fd4e5da5Sopenharmony_ci%19 = OpLoad %v4float %BaseColor
1000fd4e5da5Sopenharmony_ciOpStore %v %19
1001fd4e5da5Sopenharmony_ci%20 = OpLoad %float %f
1002fd4e5da5Sopenharmony_ci%21 = OpFOrdLessThanEqual %bool %20 %float_0
1003fd4e5da5Sopenharmony_ciOpSelectionMerge %22 None
1004fd4e5da5Sopenharmony_ciOpBranchConditional %21 %23 %22
1005fd4e5da5Sopenharmony_ci%23 = OpLabel
1006fd4e5da5Sopenharmony_ci%25 = OpVectorTimesScalar %v4float %19 %float_0_5
1007fd4e5da5Sopenharmony_ciOpStore %v %25
1008fd4e5da5Sopenharmony_ciOpBranch %22
1009fd4e5da5Sopenharmony_ci%22 = OpLabel
1010fd4e5da5Sopenharmony_ci%27 = OpPhi %v4float %19 %18 %25 %23
1011fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %27
1012fd4e5da5Sopenharmony_ciOpReturn
1013fd4e5da5Sopenharmony_ciOpFunctionEnd
1014fd4e5da5Sopenharmony_ci)";
1015fd4e5da5Sopenharmony_ci
1016fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
1017fd4e5da5Sopenharmony_ci                                        true);
1018fd4e5da5Sopenharmony_ci}
1019fd4e5da5Sopenharmony_ci
1020fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, Switch) {
1021fd4e5da5Sopenharmony_ci  // #version 140
1022fd4e5da5Sopenharmony_ci  //
1023fd4e5da5Sopenharmony_ci  // in vec4 BaseColor;
1024fd4e5da5Sopenharmony_ci  // in float f;
1025fd4e5da5Sopenharmony_ci  //
1026fd4e5da5Sopenharmony_ci  // void main()
1027fd4e5da5Sopenharmony_ci  // {
1028fd4e5da5Sopenharmony_ci  //     vec4 v = BaseColor;
1029fd4e5da5Sopenharmony_ci  //     int i = int(f);
1030fd4e5da5Sopenharmony_ci  //     switch (i) {
1031fd4e5da5Sopenharmony_ci  //       case 0:
1032fd4e5da5Sopenharmony_ci  //         v = v * 0.25;
1033fd4e5da5Sopenharmony_ci  //         break;
1034fd4e5da5Sopenharmony_ci  //       case 1:
1035fd4e5da5Sopenharmony_ci  //         v = v * 0.625;
1036fd4e5da5Sopenharmony_ci  //         break;
1037fd4e5da5Sopenharmony_ci  //       case 2:
1038fd4e5da5Sopenharmony_ci  //         v = v * 0.75;
1039fd4e5da5Sopenharmony_ci  //         break;
1040fd4e5da5Sopenharmony_ci  //       default:
1041fd4e5da5Sopenharmony_ci  //         break;
1042fd4e5da5Sopenharmony_ci  //     }
1043fd4e5da5Sopenharmony_ci  //     gl_FragColor = v;
1044fd4e5da5Sopenharmony_ci  // }
1045fd4e5da5Sopenharmony_ci
1046fd4e5da5Sopenharmony_ci  const std::string predefs =
1047fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1048fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1049fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1050fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %f %gl_FragColor
1051fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1052fd4e5da5Sopenharmony_ciOpSource GLSL 140
1053fd4e5da5Sopenharmony_ciOpName %main "main"
1054fd4e5da5Sopenharmony_ciOpName %v "v"
1055fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1056fd4e5da5Sopenharmony_ciOpName %i "i"
1057fd4e5da5Sopenharmony_ciOpName %f "f"
1058fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
1059fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1060fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
1061fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1062fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1063fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
1064fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1065fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1066fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1067fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
1068fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
1069fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Input_float Input
1070fd4e5da5Sopenharmony_ci%float_0_25 = OpConstant %float 0.25
1071fd4e5da5Sopenharmony_ci%float_0_625 = OpConstant %float 0.625
1072fd4e5da5Sopenharmony_ci%float_0_75 = OpConstant %float 0.75
1073fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1074fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
1075fd4e5da5Sopenharmony_ci)";
1076fd4e5da5Sopenharmony_ci
1077fd4e5da5Sopenharmony_ci  const std::string before =
1078fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %9
1079fd4e5da5Sopenharmony_ci%21 = OpLabel
1080fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
1081fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
1082fd4e5da5Sopenharmony_ci%22 = OpLoad %v4float %BaseColor
1083fd4e5da5Sopenharmony_ciOpStore %v %22
1084fd4e5da5Sopenharmony_ci%23 = OpLoad %float %f
1085fd4e5da5Sopenharmony_ci%24 = OpConvertFToS %int %23
1086fd4e5da5Sopenharmony_ciOpStore %i %24
1087fd4e5da5Sopenharmony_ci%25 = OpLoad %int %i
1088fd4e5da5Sopenharmony_ciOpSelectionMerge %26 None
1089fd4e5da5Sopenharmony_ciOpSwitch %25 %27 0 %28 1 %29 2 %30
1090fd4e5da5Sopenharmony_ci%27 = OpLabel
1091fd4e5da5Sopenharmony_ciOpBranch %26
1092fd4e5da5Sopenharmony_ci%28 = OpLabel
1093fd4e5da5Sopenharmony_ci%31 = OpLoad %v4float %v
1094fd4e5da5Sopenharmony_ci%32 = OpVectorTimesScalar %v4float %31 %float_0_25
1095fd4e5da5Sopenharmony_ciOpStore %v %32
1096fd4e5da5Sopenharmony_ciOpBranch %26
1097fd4e5da5Sopenharmony_ci%29 = OpLabel
1098fd4e5da5Sopenharmony_ci%33 = OpLoad %v4float %v
1099fd4e5da5Sopenharmony_ci%34 = OpVectorTimesScalar %v4float %33 %float_0_625
1100fd4e5da5Sopenharmony_ciOpStore %v %34
1101fd4e5da5Sopenharmony_ciOpBranch %26
1102fd4e5da5Sopenharmony_ci%30 = OpLabel
1103fd4e5da5Sopenharmony_ci%35 = OpLoad %v4float %v
1104fd4e5da5Sopenharmony_ci%36 = OpVectorTimesScalar %v4float %35 %float_0_75
1105fd4e5da5Sopenharmony_ciOpStore %v %36
1106fd4e5da5Sopenharmony_ciOpBranch %26
1107fd4e5da5Sopenharmony_ci%26 = OpLabel
1108fd4e5da5Sopenharmony_ci%37 = OpLoad %v4float %v
1109fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %37
1110fd4e5da5Sopenharmony_ciOpReturn
1111fd4e5da5Sopenharmony_ciOpFunctionEnd
1112fd4e5da5Sopenharmony_ci)";
1113fd4e5da5Sopenharmony_ci
1114fd4e5da5Sopenharmony_ci  const std::string after =
1115fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %9
1116fd4e5da5Sopenharmony_ci%21 = OpLabel
1117fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
1118fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
1119fd4e5da5Sopenharmony_ci%22 = OpLoad %v4float %BaseColor
1120fd4e5da5Sopenharmony_ciOpStore %v %22
1121fd4e5da5Sopenharmony_ci%23 = OpLoad %float %f
1122fd4e5da5Sopenharmony_ci%24 = OpConvertFToS %int %23
1123fd4e5da5Sopenharmony_ciOpStore %i %24
1124fd4e5da5Sopenharmony_ciOpSelectionMerge %26 None
1125fd4e5da5Sopenharmony_ciOpSwitch %24 %27 0 %28 1 %29 2 %30
1126fd4e5da5Sopenharmony_ci%27 = OpLabel
1127fd4e5da5Sopenharmony_ciOpBranch %26
1128fd4e5da5Sopenharmony_ci%28 = OpLabel
1129fd4e5da5Sopenharmony_ci%32 = OpVectorTimesScalar %v4float %22 %float_0_25
1130fd4e5da5Sopenharmony_ciOpStore %v %32
1131fd4e5da5Sopenharmony_ciOpBranch %26
1132fd4e5da5Sopenharmony_ci%29 = OpLabel
1133fd4e5da5Sopenharmony_ci%34 = OpVectorTimesScalar %v4float %22 %float_0_625
1134fd4e5da5Sopenharmony_ciOpStore %v %34
1135fd4e5da5Sopenharmony_ciOpBranch %26
1136fd4e5da5Sopenharmony_ci%30 = OpLabel
1137fd4e5da5Sopenharmony_ci%36 = OpVectorTimesScalar %v4float %22 %float_0_75
1138fd4e5da5Sopenharmony_ciOpStore %v %36
1139fd4e5da5Sopenharmony_ciOpBranch %26
1140fd4e5da5Sopenharmony_ci%26 = OpLabel
1141fd4e5da5Sopenharmony_ci%38 = OpPhi %v4float %22 %27 %32 %28 %34 %29 %36 %30
1142fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %38
1143fd4e5da5Sopenharmony_ciOpReturn
1144fd4e5da5Sopenharmony_ciOpFunctionEnd
1145fd4e5da5Sopenharmony_ci)";
1146fd4e5da5Sopenharmony_ci
1147fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
1148fd4e5da5Sopenharmony_ci                                        true);
1149fd4e5da5Sopenharmony_ci}
1150fd4e5da5Sopenharmony_ci
1151fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, SwitchWithFallThrough) {
1152fd4e5da5Sopenharmony_ci  // #version 140
1153fd4e5da5Sopenharmony_ci  //
1154fd4e5da5Sopenharmony_ci  // in vec4 BaseColor;
1155fd4e5da5Sopenharmony_ci  // in float f;
1156fd4e5da5Sopenharmony_ci  //
1157fd4e5da5Sopenharmony_ci  // void main()
1158fd4e5da5Sopenharmony_ci  // {
1159fd4e5da5Sopenharmony_ci  //     vec4 v = BaseColor;
1160fd4e5da5Sopenharmony_ci  //     int i = int(f);
1161fd4e5da5Sopenharmony_ci  //     switch (i) {
1162fd4e5da5Sopenharmony_ci  //       case 0:
1163fd4e5da5Sopenharmony_ci  //         v = v * 0.25;
1164fd4e5da5Sopenharmony_ci  //         break;
1165fd4e5da5Sopenharmony_ci  //       case 1:
1166fd4e5da5Sopenharmony_ci  //         v = v + 0.25;
1167fd4e5da5Sopenharmony_ci  //       case 2:
1168fd4e5da5Sopenharmony_ci  //         v = v * 0.75;
1169fd4e5da5Sopenharmony_ci  //         break;
1170fd4e5da5Sopenharmony_ci  //       default:
1171fd4e5da5Sopenharmony_ci  //         break;
1172fd4e5da5Sopenharmony_ci  //     }
1173fd4e5da5Sopenharmony_ci  //     gl_FragColor = v;
1174fd4e5da5Sopenharmony_ci  // }
1175fd4e5da5Sopenharmony_ci
1176fd4e5da5Sopenharmony_ci  const std::string predefs =
1177fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1178fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1179fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1180fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %f %gl_FragColor
1181fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1182fd4e5da5Sopenharmony_ciOpSource GLSL 140
1183fd4e5da5Sopenharmony_ciOpName %main "main"
1184fd4e5da5Sopenharmony_ciOpName %v "v"
1185fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1186fd4e5da5Sopenharmony_ciOpName %i "i"
1187fd4e5da5Sopenharmony_ciOpName %f "f"
1188fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
1189fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1190fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
1191fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1192fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1193fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
1194fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1195fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1196fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1197fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
1198fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
1199fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Input_float Input
1200fd4e5da5Sopenharmony_ci%float_0_25 = OpConstant %float 0.25
1201fd4e5da5Sopenharmony_ci%float_0_75 = OpConstant %float 0.75
1202fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1203fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
1204fd4e5da5Sopenharmony_ci)";
1205fd4e5da5Sopenharmony_ci
1206fd4e5da5Sopenharmony_ci  const std::string before =
1207fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %9
1208fd4e5da5Sopenharmony_ci%20 = OpLabel
1209fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
1210fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
1211fd4e5da5Sopenharmony_ci%21 = OpLoad %v4float %BaseColor
1212fd4e5da5Sopenharmony_ciOpStore %v %21
1213fd4e5da5Sopenharmony_ci%22 = OpLoad %float %f
1214fd4e5da5Sopenharmony_ci%23 = OpConvertFToS %int %22
1215fd4e5da5Sopenharmony_ciOpStore %i %23
1216fd4e5da5Sopenharmony_ci%24 = OpLoad %int %i
1217fd4e5da5Sopenharmony_ciOpSelectionMerge %25 None
1218fd4e5da5Sopenharmony_ciOpSwitch %24 %26 0 %27 1 %28 2 %29
1219fd4e5da5Sopenharmony_ci%26 = OpLabel
1220fd4e5da5Sopenharmony_ciOpBranch %25
1221fd4e5da5Sopenharmony_ci%27 = OpLabel
1222fd4e5da5Sopenharmony_ci%30 = OpLoad %v4float %v
1223fd4e5da5Sopenharmony_ci%31 = OpVectorTimesScalar %v4float %30 %float_0_25
1224fd4e5da5Sopenharmony_ciOpStore %v %31
1225fd4e5da5Sopenharmony_ciOpBranch %25
1226fd4e5da5Sopenharmony_ci%28 = OpLabel
1227fd4e5da5Sopenharmony_ci%32 = OpLoad %v4float %v
1228fd4e5da5Sopenharmony_ci%33 = OpCompositeConstruct %v4float %float_0_25 %float_0_25 %float_0_25 %float_0_25
1229fd4e5da5Sopenharmony_ci%34 = OpFAdd %v4float %32 %33
1230fd4e5da5Sopenharmony_ciOpStore %v %34
1231fd4e5da5Sopenharmony_ciOpBranch %29
1232fd4e5da5Sopenharmony_ci%29 = OpLabel
1233fd4e5da5Sopenharmony_ci%35 = OpLoad %v4float %v
1234fd4e5da5Sopenharmony_ci%36 = OpVectorTimesScalar %v4float %35 %float_0_75
1235fd4e5da5Sopenharmony_ciOpStore %v %36
1236fd4e5da5Sopenharmony_ciOpBranch %25
1237fd4e5da5Sopenharmony_ci%25 = OpLabel
1238fd4e5da5Sopenharmony_ci%37 = OpLoad %v4float %v
1239fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %37
1240fd4e5da5Sopenharmony_ciOpReturn
1241fd4e5da5Sopenharmony_ciOpFunctionEnd
1242fd4e5da5Sopenharmony_ci)";
1243fd4e5da5Sopenharmony_ci
1244fd4e5da5Sopenharmony_ci  const std::string after =
1245fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %9
1246fd4e5da5Sopenharmony_ci%20 = OpLabel
1247fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
1248fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
1249fd4e5da5Sopenharmony_ci%21 = OpLoad %v4float %BaseColor
1250fd4e5da5Sopenharmony_ciOpStore %v %21
1251fd4e5da5Sopenharmony_ci%22 = OpLoad %float %f
1252fd4e5da5Sopenharmony_ci%23 = OpConvertFToS %int %22
1253fd4e5da5Sopenharmony_ciOpStore %i %23
1254fd4e5da5Sopenharmony_ciOpSelectionMerge %25 None
1255fd4e5da5Sopenharmony_ciOpSwitch %23 %26 0 %27 1 %28 2 %29
1256fd4e5da5Sopenharmony_ci%26 = OpLabel
1257fd4e5da5Sopenharmony_ciOpBranch %25
1258fd4e5da5Sopenharmony_ci%27 = OpLabel
1259fd4e5da5Sopenharmony_ci%31 = OpVectorTimesScalar %v4float %21 %float_0_25
1260fd4e5da5Sopenharmony_ciOpStore %v %31
1261fd4e5da5Sopenharmony_ciOpBranch %25
1262fd4e5da5Sopenharmony_ci%28 = OpLabel
1263fd4e5da5Sopenharmony_ci%33 = OpCompositeConstruct %v4float %float_0_25 %float_0_25 %float_0_25 %float_0_25
1264fd4e5da5Sopenharmony_ci%34 = OpFAdd %v4float %21 %33
1265fd4e5da5Sopenharmony_ciOpStore %v %34
1266fd4e5da5Sopenharmony_ciOpBranch %29
1267fd4e5da5Sopenharmony_ci%29 = OpLabel
1268fd4e5da5Sopenharmony_ci%38 = OpPhi %v4float %21 %20 %34 %28
1269fd4e5da5Sopenharmony_ci%36 = OpVectorTimesScalar %v4float %38 %float_0_75
1270fd4e5da5Sopenharmony_ciOpStore %v %36
1271fd4e5da5Sopenharmony_ciOpBranch %25
1272fd4e5da5Sopenharmony_ci%25 = OpLabel
1273fd4e5da5Sopenharmony_ci%39 = OpPhi %v4float %21 %26 %31 %27 %36 %29
1274fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %39
1275fd4e5da5Sopenharmony_ciOpReturn
1276fd4e5da5Sopenharmony_ciOpFunctionEnd
1277fd4e5da5Sopenharmony_ci)";
1278fd4e5da5Sopenharmony_ci
1279fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(predefs + before, predefs + after, true,
1280fd4e5da5Sopenharmony_ci                                        true);
1281fd4e5da5Sopenharmony_ci}
1282fd4e5da5Sopenharmony_ci
1283fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DontPatchPhiInLoopHeaderThatIsNotAVar) {
1284fd4e5da5Sopenharmony_ci  // From https://github.com/KhronosGroup/SPIRV-Tools/issues/826
1285fd4e5da5Sopenharmony_ci  // Don't try patching the (%16 %7) value/predecessor pair in the OpPhi.
1286fd4e5da5Sopenharmony_ci  // That OpPhi is unrelated to this optimization: we did not set that up
1287fd4e5da5Sopenharmony_ci  // in the SSA initialization for the loop header block.
1288fd4e5da5Sopenharmony_ci  // The pass should be a no-op on this module.
1289fd4e5da5Sopenharmony_ci
1290fd4e5da5Sopenharmony_ci  const std::string before = R"(OpCapability Shader
1291fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1292fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %1 "main"
1293fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1294fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
1295fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1296fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
1297fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %3
1298fd4e5da5Sopenharmony_ci%6 = OpLabel
1299fd4e5da5Sopenharmony_ciOpBranch %7
1300fd4e5da5Sopenharmony_ci%7 = OpLabel
1301fd4e5da5Sopenharmony_ci%8 = OpPhi %float %float_1 %6 %9 %7
1302fd4e5da5Sopenharmony_ci%9 = OpFAdd %float %8 %float_1
1303fd4e5da5Sopenharmony_ciOpLoopMerge %10 %7 None
1304fd4e5da5Sopenharmony_ciOpBranch %7
1305fd4e5da5Sopenharmony_ci%10 = OpLabel
1306fd4e5da5Sopenharmony_ciOpReturn
1307fd4e5da5Sopenharmony_ciOpFunctionEnd
1308fd4e5da5Sopenharmony_ci)";
1309fd4e5da5Sopenharmony_ci
1310fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(before, before, true, true);
1311fd4e5da5Sopenharmony_ci}
1312fd4e5da5Sopenharmony_ci
1313fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, OptInitializedVariableLikeStore) {
1314fd4e5da5Sopenharmony_ci  // Note: SPIR-V edited to change store to v into variable initialization
1315fd4e5da5Sopenharmony_ci  //
1316fd4e5da5Sopenharmony_ci  // #version 450
1317fd4e5da5Sopenharmony_ci  //
1318fd4e5da5Sopenharmony_ci  // layout (location=0) in vec4 iColor;
1319fd4e5da5Sopenharmony_ci  // layout (location=1) in float fi;
1320fd4e5da5Sopenharmony_ci  // layout (location=0) out vec4 oColor;
1321fd4e5da5Sopenharmony_ci  //
1322fd4e5da5Sopenharmony_ci  // void main()
1323fd4e5da5Sopenharmony_ci  // {
1324fd4e5da5Sopenharmony_ci  //     vec4 v = vec4(0.0);
1325fd4e5da5Sopenharmony_ci  //     if (fi < 0.0)
1326fd4e5da5Sopenharmony_ci  //       v.x = iColor.x;
1327fd4e5da5Sopenharmony_ci  //     oColor = v;
1328fd4e5da5Sopenharmony_ci  // }
1329fd4e5da5Sopenharmony_ci
1330fd4e5da5Sopenharmony_ci  const std::string predefs =
1331fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1332fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1333fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1334fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %fi %iColor %oColor
1335fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1336fd4e5da5Sopenharmony_ciOpSource GLSL 450
1337fd4e5da5Sopenharmony_ciOpName %main "main"
1338fd4e5da5Sopenharmony_ciOpName %v "v"
1339fd4e5da5Sopenharmony_ciOpName %fi "fi"
1340fd4e5da5Sopenharmony_ciOpName %iColor "iColor"
1341fd4e5da5Sopenharmony_ciOpName %oColor "oColor"
1342fd4e5da5Sopenharmony_ciOpDecorate %fi Location 1
1343fd4e5da5Sopenharmony_ciOpDecorate %iColor Location 0
1344fd4e5da5Sopenharmony_ciOpDecorate %oColor Location 0
1345fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1346fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
1347fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1348fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1349fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
1350fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1351fd4e5da5Sopenharmony_ci%13 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
1352fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
1353fd4e5da5Sopenharmony_ci%fi = OpVariable %_ptr_Input_float Input
1354fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1355fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1356fd4e5da5Sopenharmony_ci%iColor = OpVariable %_ptr_Input_v4float Input
1357fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1358fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
1359fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1360fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1361fd4e5da5Sopenharmony_ci%oColor = OpVariable %_ptr_Output_v4float Output
1362fd4e5da5Sopenharmony_ci)";
1363fd4e5da5Sopenharmony_ci
1364fd4e5da5Sopenharmony_ci  const std::string func_before =
1365fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %8
1366fd4e5da5Sopenharmony_ci%21 = OpLabel
1367fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function %13
1368fd4e5da5Sopenharmony_ci%22 = OpLoad %float %fi
1369fd4e5da5Sopenharmony_ci%23 = OpFOrdLessThan %bool %22 %float_0
1370fd4e5da5Sopenharmony_ciOpSelectionMerge %24 None
1371fd4e5da5Sopenharmony_ciOpBranchConditional %23 %25 %24
1372fd4e5da5Sopenharmony_ci%25 = OpLabel
1373fd4e5da5Sopenharmony_ci%26 = OpAccessChain %_ptr_Input_float %iColor %uint_0
1374fd4e5da5Sopenharmony_ci%27 = OpLoad %float %26
1375fd4e5da5Sopenharmony_ci%28 = OpLoad %v4float %v
1376fd4e5da5Sopenharmony_ci%29 = OpCompositeInsert %v4float %27 %28 0
1377fd4e5da5Sopenharmony_ciOpStore %v %29
1378fd4e5da5Sopenharmony_ciOpBranch %24
1379fd4e5da5Sopenharmony_ci%24 = OpLabel
1380fd4e5da5Sopenharmony_ci%30 = OpLoad %v4float %v
1381fd4e5da5Sopenharmony_ciOpStore %oColor %30
1382fd4e5da5Sopenharmony_ciOpReturn
1383fd4e5da5Sopenharmony_ciOpFunctionEnd
1384fd4e5da5Sopenharmony_ci)";
1385fd4e5da5Sopenharmony_ci
1386fd4e5da5Sopenharmony_ci  const std::string func_after =
1387fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %8
1388fd4e5da5Sopenharmony_ci%21 = OpLabel
1389fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function %13
1390fd4e5da5Sopenharmony_ci%22 = OpLoad %float %fi
1391fd4e5da5Sopenharmony_ci%23 = OpFOrdLessThan %bool %22 %float_0
1392fd4e5da5Sopenharmony_ciOpSelectionMerge %24 None
1393fd4e5da5Sopenharmony_ciOpBranchConditional %23 %25 %24
1394fd4e5da5Sopenharmony_ci%25 = OpLabel
1395fd4e5da5Sopenharmony_ci%26 = OpAccessChain %_ptr_Input_float %iColor %uint_0
1396fd4e5da5Sopenharmony_ci%27 = OpLoad %float %26
1397fd4e5da5Sopenharmony_ci%29 = OpCompositeInsert %v4float %27 %13 0
1398fd4e5da5Sopenharmony_ciOpStore %v %29
1399fd4e5da5Sopenharmony_ciOpBranch %24
1400fd4e5da5Sopenharmony_ci%24 = OpLabel
1401fd4e5da5Sopenharmony_ci%31 = OpPhi %v4float %13 %21 %29 %25
1402fd4e5da5Sopenharmony_ciOpStore %oColor %31
1403fd4e5da5Sopenharmony_ciOpReturn
1404fd4e5da5Sopenharmony_ciOpFunctionEnd
1405fd4e5da5Sopenharmony_ci)";
1406fd4e5da5Sopenharmony_ci
1407fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(predefs + func_before,
1408fd4e5da5Sopenharmony_ci                                        predefs + func_after, true, true);
1409fd4e5da5Sopenharmony_ci}
1410fd4e5da5Sopenharmony_ci
1411fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, PointerVariable) {
1412fd4e5da5Sopenharmony_ci  // Test that checks if a pointer variable is removed.
1413fd4e5da5Sopenharmony_ci
1414fd4e5da5Sopenharmony_ci  const std::string before =
1415fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1416fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1417fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %1 "main" %2
1418fd4e5da5Sopenharmony_ciOpExecutionMode %1 OriginUpperLeft
1419fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_3 0 Offset 0
1420fd4e5da5Sopenharmony_ciOpDecorate %_runtimearr__struct_3 ArrayStride 16
1421fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_5 0 Offset 0
1422fd4e5da5Sopenharmony_ciOpDecorate %_struct_5 BufferBlock
1423fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_6 0 Offset 0
1424fd4e5da5Sopenharmony_ciOpDecorate %_struct_6 BufferBlock
1425fd4e5da5Sopenharmony_ciOpDecorate %2 Location 0
1426fd4e5da5Sopenharmony_ciOpDecorate %7 DescriptorSet 0
1427fd4e5da5Sopenharmony_ciOpDecorate %7 Binding 0
1428fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1429fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
1430fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1431fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1432fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1433fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1434fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1435fd4e5da5Sopenharmony_ci%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
1436fd4e5da5Sopenharmony_ci%_struct_3 = OpTypeStruct %v4float
1437fd4e5da5Sopenharmony_ci%_runtimearr__struct_3 = OpTypeRuntimeArray %_struct_3
1438fd4e5da5Sopenharmony_ci%_struct_5 = OpTypeStruct %_runtimearr__struct_3
1439fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_5 = OpTypePointer Uniform %_struct_5
1440fd4e5da5Sopenharmony_ci%_struct_6 = OpTypeStruct %int
1441fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_6 = OpTypePointer Uniform %_struct_6
1442fd4e5da5Sopenharmony_ci%_ptr_Function__ptr_Uniform__struct_5 = OpTypePointer Function %_ptr_Uniform__struct_5
1443fd4e5da5Sopenharmony_ci%_ptr_Function__ptr_Uniform__struct_6 = OpTypePointer Function %_ptr_Uniform__struct_6
1444fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1445fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
1446fd4e5da5Sopenharmony_ci%2 = OpVariable %_ptr_Output_v4float Output
1447fd4e5da5Sopenharmony_ci%7 = OpVariable %_ptr_Uniform__struct_5 Uniform
1448fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %10
1449fd4e5da5Sopenharmony_ci%23 = OpLabel
1450fd4e5da5Sopenharmony_ci%24 = OpVariable %_ptr_Function__ptr_Uniform__struct_5 Function
1451fd4e5da5Sopenharmony_ciOpStore %24 %7
1452fd4e5da5Sopenharmony_ci%26 = OpLoad %_ptr_Uniform__struct_5 %24
1453fd4e5da5Sopenharmony_ci%27 = OpAccessChain %_ptr_Uniform_v4float %26 %int_0 %uint_0 %int_0
1454fd4e5da5Sopenharmony_ci%28 = OpLoad %v4float %27
1455fd4e5da5Sopenharmony_ci%29 = OpCopyObject %v4float %28
1456fd4e5da5Sopenharmony_ciOpStore %2 %28
1457fd4e5da5Sopenharmony_ciOpReturn
1458fd4e5da5Sopenharmony_ciOpFunctionEnd
1459fd4e5da5Sopenharmony_ci)";
1460fd4e5da5Sopenharmony_ci
1461fd4e5da5Sopenharmony_ci  const std::string after =
1462fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1463fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1464fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %1 "main" %2
1465fd4e5da5Sopenharmony_ciOpExecutionMode %1 OriginUpperLeft
1466fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_3 0 Offset 0
1467fd4e5da5Sopenharmony_ciOpDecorate %_runtimearr__struct_3 ArrayStride 16
1468fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_5 0 Offset 0
1469fd4e5da5Sopenharmony_ciOpDecorate %_struct_5 BufferBlock
1470fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_6 0 Offset 0
1471fd4e5da5Sopenharmony_ciOpDecorate %_struct_6 BufferBlock
1472fd4e5da5Sopenharmony_ciOpDecorate %2 Location 0
1473fd4e5da5Sopenharmony_ciOpDecorate %7 DescriptorSet 0
1474fd4e5da5Sopenharmony_ciOpDecorate %7 Binding 0
1475fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1476fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
1477fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1478fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1479fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1480fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1481fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1482fd4e5da5Sopenharmony_ci%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
1483fd4e5da5Sopenharmony_ci%_struct_3 = OpTypeStruct %v4float
1484fd4e5da5Sopenharmony_ci%_runtimearr__struct_3 = OpTypeRuntimeArray %_struct_3
1485fd4e5da5Sopenharmony_ci%_struct_5 = OpTypeStruct %_runtimearr__struct_3
1486fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_5 = OpTypePointer Uniform %_struct_5
1487fd4e5da5Sopenharmony_ci%_struct_6 = OpTypeStruct %int
1488fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_6 = OpTypePointer Uniform %_struct_6
1489fd4e5da5Sopenharmony_ci%_ptr_Function__ptr_Uniform__struct_5 = OpTypePointer Function %_ptr_Uniform__struct_5
1490fd4e5da5Sopenharmony_ci%_ptr_Function__ptr_Uniform__struct_6 = OpTypePointer Function %_ptr_Uniform__struct_6
1491fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1492fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
1493fd4e5da5Sopenharmony_ci%2 = OpVariable %_ptr_Output_v4float Output
1494fd4e5da5Sopenharmony_ci%7 = OpVariable %_ptr_Uniform__struct_5 Uniform
1495fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %10
1496fd4e5da5Sopenharmony_ci%23 = OpLabel
1497fd4e5da5Sopenharmony_ci%24 = OpVariable %_ptr_Function__ptr_Uniform__struct_5 Function
1498fd4e5da5Sopenharmony_ciOpStore %24 %7
1499fd4e5da5Sopenharmony_ci%27 = OpAccessChain %_ptr_Uniform_v4float %7 %int_0 %uint_0 %int_0
1500fd4e5da5Sopenharmony_ci%28 = OpLoad %v4float %27
1501fd4e5da5Sopenharmony_ci%29 = OpCopyObject %v4float %28
1502fd4e5da5Sopenharmony_ciOpStore %2 %28
1503fd4e5da5Sopenharmony_ciOpReturn
1504fd4e5da5Sopenharmony_ciOpFunctionEnd
1505fd4e5da5Sopenharmony_ci)";
1506fd4e5da5Sopenharmony_ci
1507fd4e5da5Sopenharmony_ci  // Relax logical pointers to allow pointer allocations.
1508fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1509fd4e5da5Sopenharmony_ci  ValidatorOptions()->relax_logical_pointer = true;
1510fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(before, after, true, true);
1511fd4e5da5Sopenharmony_ci}
1512fd4e5da5Sopenharmony_ci
1513fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, VerifyInstToBlockMap) {
1514fd4e5da5Sopenharmony_ci  // #version 140
1515fd4e5da5Sopenharmony_ci  //
1516fd4e5da5Sopenharmony_ci  // in vec4 BC;
1517fd4e5da5Sopenharmony_ci  // out float fo;
1518fd4e5da5Sopenharmony_ci  //
1519fd4e5da5Sopenharmony_ci  // void main()
1520fd4e5da5Sopenharmony_ci  // {
1521fd4e5da5Sopenharmony_ci  //     float f = 0.0;
1522fd4e5da5Sopenharmony_ci  //     for (int i=0; i<4; i++) {
1523fd4e5da5Sopenharmony_ci  //       f = f + BC[i];
1524fd4e5da5Sopenharmony_ci  //     }
1525fd4e5da5Sopenharmony_ci  //     fo = f;
1526fd4e5da5Sopenharmony_ci  // }
1527fd4e5da5Sopenharmony_ci
1528fd4e5da5Sopenharmony_ci  const std::string text = R"(
1529fd4e5da5Sopenharmony_ciOpCapability Shader
1530fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1531fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1532fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
1533fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1534fd4e5da5Sopenharmony_ciOpSource GLSL 140
1535fd4e5da5Sopenharmony_ciOpName %main "main"
1536fd4e5da5Sopenharmony_ciOpName %f "f"
1537fd4e5da5Sopenharmony_ciOpName %i "i"
1538fd4e5da5Sopenharmony_ciOpName %BC "BC"
1539fd4e5da5Sopenharmony_ciOpName %fo "fo"
1540fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1541fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
1542fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1543fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1544fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1545fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1546fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
1547fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1548fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
1549fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1550fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1551fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1552fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
1553fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
1554fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
1555fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
1556fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
1557fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
1558fd4e5da5Sopenharmony_ci%22 = OpLabel
1559fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
1560fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
1561fd4e5da5Sopenharmony_ciOpStore %f %float_0
1562fd4e5da5Sopenharmony_ciOpStore %i %int_0
1563fd4e5da5Sopenharmony_ciOpBranch %23
1564fd4e5da5Sopenharmony_ci%23 = OpLabel
1565fd4e5da5Sopenharmony_ciOpLoopMerge %24 %25 None
1566fd4e5da5Sopenharmony_ciOpBranch %26
1567fd4e5da5Sopenharmony_ci%26 = OpLabel
1568fd4e5da5Sopenharmony_ci%27 = OpLoad %int %i
1569fd4e5da5Sopenharmony_ci%28 = OpSLessThan %bool %27 %int_4
1570fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %24
1571fd4e5da5Sopenharmony_ci%29 = OpLabel
1572fd4e5da5Sopenharmony_ci%30 = OpLoad %float %f
1573fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
1574fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
1575fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
1576fd4e5da5Sopenharmony_ci%34 = OpFAdd %float %30 %33
1577fd4e5da5Sopenharmony_ciOpStore %f %34
1578fd4e5da5Sopenharmony_ciOpBranch %25
1579fd4e5da5Sopenharmony_ci%25 = OpLabel
1580fd4e5da5Sopenharmony_ci%35 = OpLoad %int %i
1581fd4e5da5Sopenharmony_ci%36 = OpIAdd %int %35 %int_1
1582fd4e5da5Sopenharmony_ciOpStore %i %36
1583fd4e5da5Sopenharmony_ciOpBranch %23
1584fd4e5da5Sopenharmony_ci%24 = OpLabel
1585fd4e5da5Sopenharmony_ci%37 = OpLoad %float %f
1586fd4e5da5Sopenharmony_ciOpStore %fo %37
1587fd4e5da5Sopenharmony_ciOpReturn
1588fd4e5da5Sopenharmony_ciOpFunctionEnd
1589fd4e5da5Sopenharmony_ci)";
1590fd4e5da5Sopenharmony_ci
1591fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
1592fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, text,
1593fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1594fd4e5da5Sopenharmony_ci  EXPECT_NE(nullptr, context);
1595fd4e5da5Sopenharmony_ci
1596fd4e5da5Sopenharmony_ci  // Force the instruction to block mapping to get built.
1597fd4e5da5Sopenharmony_ci  context->get_instr_block(27u);
1598fd4e5da5Sopenharmony_ci
1599fd4e5da5Sopenharmony_ci  auto pass = MakeUnique<SSARewritePass>();
1600fd4e5da5Sopenharmony_ci  pass->SetMessageConsumer(nullptr);
1601fd4e5da5Sopenharmony_ci  const auto status = pass->Run(context.get());
1602fd4e5da5Sopenharmony_ci  EXPECT_TRUE(status == Pass::Status::SuccessWithChange);
1603fd4e5da5Sopenharmony_ci}
1604fd4e5da5Sopenharmony_ci
1605fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, CompositeExtractProblem) {
1606fd4e5da5Sopenharmony_ci  const std::string spv_asm = R"(
1607fd4e5da5Sopenharmony_ci               OpCapability Tessellation
1608fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
1609fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
1610fd4e5da5Sopenharmony_ci               OpEntryPoint TessellationControl %2 "main" %16 %17 %18 %20 %22 %26 %27 %30 %31
1611fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
1612fd4e5da5Sopenharmony_ci          %4 = OpTypeFunction %void
1613fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
1614fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
1615fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
1616fd4e5da5Sopenharmony_ci     %uint_3 = OpConstant %uint 3
1617fd4e5da5Sopenharmony_ci    %v3float = OpTypeVector %float 3
1618fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
1619fd4e5da5Sopenharmony_ci %_struct_11 = OpTypeStruct %v4float %v4float %v4float %v3float %v3float %v2float %v2float
1620fd4e5da5Sopenharmony_ci%_arr__struct_11_uint_3 = OpTypeArray %_struct_11 %uint_3
1621fd4e5da5Sopenharmony_ci%_ptr_Function__arr__struct_11_uint_3 = OpTypePointer Function %_arr__struct_11_uint_3
1622fd4e5da5Sopenharmony_ci%_arr_v4float_uint_3 = OpTypeArray %v4float %uint_3
1623fd4e5da5Sopenharmony_ci%_ptr_Input__arr_v4float_uint_3 = OpTypePointer Input %_arr_v4float_uint_3
1624fd4e5da5Sopenharmony_ci         %16 = OpVariable %_ptr_Input__arr_v4float_uint_3 Input
1625fd4e5da5Sopenharmony_ci         %17 = OpVariable %_ptr_Input__arr_v4float_uint_3 Input
1626fd4e5da5Sopenharmony_ci         %18 = OpVariable %_ptr_Input__arr_v4float_uint_3 Input
1627fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
1628fd4e5da5Sopenharmony_ci         %20 = OpVariable %_ptr_Input_uint Input
1629fd4e5da5Sopenharmony_ci%_ptr_Output__arr_v4float_uint_3 = OpTypePointer Output %_arr_v4float_uint_3
1630fd4e5da5Sopenharmony_ci         %22 = OpVariable %_ptr_Output__arr_v4float_uint_3 Output
1631fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1632fd4e5da5Sopenharmony_ci%_arr_v3float_uint_3 = OpTypeArray %v3float %uint_3
1633fd4e5da5Sopenharmony_ci%_ptr_Input__arr_v3float_uint_3 = OpTypePointer Input %_arr_v3float_uint_3
1634fd4e5da5Sopenharmony_ci         %26 = OpVariable %_ptr_Input__arr_v3float_uint_3 Input
1635fd4e5da5Sopenharmony_ci         %27 = OpVariable %_ptr_Input__arr_v3float_uint_3 Input
1636fd4e5da5Sopenharmony_ci%_arr_v2float_uint_3 = OpTypeArray %v2float %uint_3
1637fd4e5da5Sopenharmony_ci%_ptr_Input__arr_v2float_uint_3 = OpTypePointer Input %_arr_v2float_uint_3
1638fd4e5da5Sopenharmony_ci         %30 = OpVariable %_ptr_Input__arr_v2float_uint_3 Input
1639fd4e5da5Sopenharmony_ci         %31 = OpVariable %_ptr_Input__arr_v2float_uint_3 Input
1640fd4e5da5Sopenharmony_ci%_ptr_Function__struct_11 = OpTypePointer Function %_struct_11
1641fd4e5da5Sopenharmony_ci          %2 = OpFunction %void None %4
1642fd4e5da5Sopenharmony_ci         %33 = OpLabel
1643fd4e5da5Sopenharmony_ci         %66 = OpVariable %_ptr_Function__arr__struct_11_uint_3 Function
1644fd4e5da5Sopenharmony_ci         %34 = OpLoad %_arr_v4float_uint_3 %16
1645fd4e5da5Sopenharmony_ci         %35 = OpLoad %_arr_v4float_uint_3 %17
1646fd4e5da5Sopenharmony_ci         %36 = OpLoad %_arr_v4float_uint_3 %18
1647fd4e5da5Sopenharmony_ci         %37 = OpLoad %_arr_v3float_uint_3 %26
1648fd4e5da5Sopenharmony_ci         %38 = OpLoad %_arr_v3float_uint_3 %27
1649fd4e5da5Sopenharmony_ci         %39 = OpLoad %_arr_v2float_uint_3 %30
1650fd4e5da5Sopenharmony_ci         %40 = OpLoad %_arr_v2float_uint_3 %31
1651fd4e5da5Sopenharmony_ci         %41 = OpCompositeExtract %v4float %34 0
1652fd4e5da5Sopenharmony_ci         %42 = OpCompositeExtract %v4float %35 0
1653fd4e5da5Sopenharmony_ci         %43 = OpCompositeExtract %v4float %36 0
1654fd4e5da5Sopenharmony_ci         %44 = OpCompositeExtract %v3float %37 0
1655fd4e5da5Sopenharmony_ci         %45 = OpCompositeExtract %v3float %38 0
1656fd4e5da5Sopenharmony_ci         %46 = OpCompositeExtract %v2float %39 0
1657fd4e5da5Sopenharmony_ci         %47 = OpCompositeExtract %v2float %40 0
1658fd4e5da5Sopenharmony_ci         %48 = OpCompositeConstruct %_struct_11 %41 %42 %43 %44 %45 %46 %47
1659fd4e5da5Sopenharmony_ci         %49 = OpCompositeExtract %v4float %34 1
1660fd4e5da5Sopenharmony_ci         %50 = OpCompositeExtract %v4float %35 1
1661fd4e5da5Sopenharmony_ci         %51 = OpCompositeExtract %v4float %36 1
1662fd4e5da5Sopenharmony_ci         %52 = OpCompositeExtract %v3float %37 1
1663fd4e5da5Sopenharmony_ci         %53 = OpCompositeExtract %v3float %38 1
1664fd4e5da5Sopenharmony_ci         %54 = OpCompositeExtract %v2float %39 1
1665fd4e5da5Sopenharmony_ci         %55 = OpCompositeExtract %v2float %40 1
1666fd4e5da5Sopenharmony_ci         %56 = OpCompositeConstruct %_struct_11 %49 %50 %51 %52 %53 %54 %55
1667fd4e5da5Sopenharmony_ci         %57 = OpCompositeExtract %v4float %34 2
1668fd4e5da5Sopenharmony_ci         %58 = OpCompositeExtract %v4float %35 2
1669fd4e5da5Sopenharmony_ci         %59 = OpCompositeExtract %v4float %36 2
1670fd4e5da5Sopenharmony_ci         %60 = OpCompositeExtract %v3float %37 2
1671fd4e5da5Sopenharmony_ci         %61 = OpCompositeExtract %v3float %38 2
1672fd4e5da5Sopenharmony_ci         %62 = OpCompositeExtract %v2float %39 2
1673fd4e5da5Sopenharmony_ci         %63 = OpCompositeExtract %v2float %40 2
1674fd4e5da5Sopenharmony_ci         %64 = OpCompositeConstruct %_struct_11 %57 %58 %59 %60 %61 %62 %63
1675fd4e5da5Sopenharmony_ci         %65 = OpCompositeConstruct %_arr__struct_11_uint_3 %48 %56 %64
1676fd4e5da5Sopenharmony_ci         %67 = OpLoad %uint %20
1677fd4e5da5Sopenharmony_ci
1678fd4e5da5Sopenharmony_ci; CHECK OpStore {{%\d+}} [[store_source:%\d+]]
1679fd4e5da5Sopenharmony_ci               OpStore %66 %65
1680fd4e5da5Sopenharmony_ci         %68 = OpAccessChain %_ptr_Function__struct_11 %66 %67
1681fd4e5da5Sopenharmony_ci
1682fd4e5da5Sopenharmony_ci; This load was being removed, because %_ptr_Function__struct_11 was being
1683fd4e5da5Sopenharmony_ci; wrongfully considered an SSA target.
1684fd4e5da5Sopenharmony_ci; CHECK OpLoad %_struct_11 %68
1685fd4e5da5Sopenharmony_ci         %69 = OpLoad %_struct_11 %68
1686fd4e5da5Sopenharmony_ci
1687fd4e5da5Sopenharmony_ci; Similarly, %69 cannot be replaced with %65.
1688fd4e5da5Sopenharmony_ci; CHECK-NOT: OpCompositeExtract %v4float [[store_source]] 0
1689fd4e5da5Sopenharmony_ci         %70 = OpCompositeExtract %v4float %69 0
1690fd4e5da5Sopenharmony_ci
1691fd4e5da5Sopenharmony_ci         %71 = OpAccessChain %_ptr_Output_v4float %22 %67
1692fd4e5da5Sopenharmony_ci               OpStore %71 %70
1693fd4e5da5Sopenharmony_ci               OpReturn
1694fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
1695fd4e5da5Sopenharmony_ci
1696fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(spv_asm, true);
1697fd4e5da5Sopenharmony_ci}
1698fd4e5da5Sopenharmony_ci
1699fd4e5da5Sopenharmony_ci// Test that the RelaxedPrecision decoration on the variable to added to the
1700fd4e5da5Sopenharmony_ci// result of the OpPhi instruction.
1701fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DecoratedVariable) {
1702fd4e5da5Sopenharmony_ci  const std::string spv_asm = R"(
1703fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[var:%\w+]] RelaxedPrecision
1704fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[phi_id:%\w+]] RelaxedPrecision
1705fd4e5da5Sopenharmony_ci; CHECK: [[phi_id]] = OpPhi
1706fd4e5da5Sopenharmony_ci               OpCapability Shader
1707fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
1708fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
1709fd4e5da5Sopenharmony_ci               OpEntryPoint GLCompute %2 "main"
1710fd4e5da5Sopenharmony_ci               OpDecorate %v RelaxedPrecision
1711fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
1712fd4e5da5Sopenharmony_ci     %func_t = OpTypeFunction %void
1713fd4e5da5Sopenharmony_ci       %bool = OpTypeBool
1714fd4e5da5Sopenharmony_ci       %true = OpConstantTrue %bool
1715fd4e5da5Sopenharmony_ci       %int  = OpTypeInt 32 0
1716fd4e5da5Sopenharmony_ci      %int_p = OpTypePointer Function %int
1717fd4e5da5Sopenharmony_ci      %int_1 = OpConstant %int 1
1718fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
1719fd4e5da5Sopenharmony_ci          %2 = OpFunction %void None %func_t
1720fd4e5da5Sopenharmony_ci         %33 = OpLabel
1721fd4e5da5Sopenharmony_ci         %v  = OpVariable %int_p Function
1722fd4e5da5Sopenharmony_ci               OpSelectionMerge %merge None
1723fd4e5da5Sopenharmony_ci               OpBranchConditional %true %l1 %l2
1724fd4e5da5Sopenharmony_ci         %l1 = OpLabel
1725fd4e5da5Sopenharmony_ci               OpStore %v %int_1
1726fd4e5da5Sopenharmony_ci               OpBranch %merge
1727fd4e5da5Sopenharmony_ci         %l2 = OpLabel
1728fd4e5da5Sopenharmony_ci               OpStore %v %int_0
1729fd4e5da5Sopenharmony_ci               OpBranch %merge
1730fd4e5da5Sopenharmony_ci      %merge = OpLabel
1731fd4e5da5Sopenharmony_ci         %ld = OpLoad %int %v
1732fd4e5da5Sopenharmony_ci               OpReturn
1733fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
1734fd4e5da5Sopenharmony_ci
1735fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(spv_asm, true);
1736fd4e5da5Sopenharmony_ci}
1737fd4e5da5Sopenharmony_ci
1738fd4e5da5Sopenharmony_ci// Test that the RelaxedPrecision decoration on the variable to added to the
1739fd4e5da5Sopenharmony_ci// result of the OpPhi instruction.
1740fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, MultipleEdges) {
1741fd4e5da5Sopenharmony_ci  const std::string spv_asm = R"(
1742fd4e5da5Sopenharmony_ci  ; CHECK: OpSelectionMerge
1743fd4e5da5Sopenharmony_ci  ; CHECK: [[header_bb:%\w+]] = OpLabel
1744fd4e5da5Sopenharmony_ci  ; CHECK-NOT: OpLabel
1745fd4e5da5Sopenharmony_ci  ; CHECK: OpSwitch {{%\w+}} {{%\w+}} 76 [[bb1:%\w+]] 17 [[bb2:%\w+]]
1746fd4e5da5Sopenharmony_ci  ; CHECK-SAME: 4 [[bb2]]
1747fd4e5da5Sopenharmony_ci  ; CHECK: [[bb2]] = OpLabel
1748fd4e5da5Sopenharmony_ci  ; CHECK-NEXT: OpPhi [[type:%\w+]] [[val:%\w+]] [[header_bb]] %int_0 [[bb1]]
1749fd4e5da5Sopenharmony_ci          OpCapability Shader
1750fd4e5da5Sopenharmony_ci     %1 = OpExtInstImport "GLSL.std.450"
1751fd4e5da5Sopenharmony_ci          OpMemoryModel Logical GLSL450
1752fd4e5da5Sopenharmony_ci          OpEntryPoint Fragment %4 "main"
1753fd4e5da5Sopenharmony_ci          OpExecutionMode %4 OriginUpperLeft
1754fd4e5da5Sopenharmony_ci          OpSource ESSL 310
1755fd4e5da5Sopenharmony_ci  %void = OpTypeVoid
1756fd4e5da5Sopenharmony_ci     %3 = OpTypeFunction %void
1757fd4e5da5Sopenharmony_ci   %int = OpTypeInt 32 1
1758fd4e5da5Sopenharmony_ci  %_ptr_Function_int = OpTypePointer Function %int
1759fd4e5da5Sopenharmony_ci  %int_0 = OpConstant %int 0
1760fd4e5da5Sopenharmony_ci  %bool = OpTypeBool
1761fd4e5da5Sopenharmony_ci  %true = OpConstantTrue %bool
1762fd4e5da5Sopenharmony_ci  %false = OpConstantFalse %bool
1763fd4e5da5Sopenharmony_ci  %int_1 = OpConstant %int 1
1764fd4e5da5Sopenharmony_ci     %4 = OpFunction %void None %3
1765fd4e5da5Sopenharmony_ci     %5 = OpLabel
1766fd4e5da5Sopenharmony_ci     %8 = OpVariable %_ptr_Function_int Function
1767fd4e5da5Sopenharmony_ci          OpBranch %10
1768fd4e5da5Sopenharmony_ci    %10 = OpLabel
1769fd4e5da5Sopenharmony_ci          OpLoopMerge %12 %13 None
1770fd4e5da5Sopenharmony_ci          OpBranch %14
1771fd4e5da5Sopenharmony_ci    %14 = OpLabel
1772fd4e5da5Sopenharmony_ci          OpBranchConditional %true %11 %12
1773fd4e5da5Sopenharmony_ci    %11 = OpLabel
1774fd4e5da5Sopenharmony_ci          OpSelectionMerge %19 None
1775fd4e5da5Sopenharmony_ci          OpBranchConditional %false %18 %19
1776fd4e5da5Sopenharmony_ci    %18 = OpLabel
1777fd4e5da5Sopenharmony_ci          OpSelectionMerge %22 None
1778fd4e5da5Sopenharmony_ci          OpSwitch %int_0 %22 76 %20 17 %21 4 %21
1779fd4e5da5Sopenharmony_ci    %20 = OpLabel
1780fd4e5da5Sopenharmony_ci    %23 = OpLoad %int %8
1781fd4e5da5Sopenharmony_ci          OpStore %8 %int_0
1782fd4e5da5Sopenharmony_ci          OpBranch %21
1783fd4e5da5Sopenharmony_ci    %21 = OpLabel
1784fd4e5da5Sopenharmony_ci          OpBranch %22
1785fd4e5da5Sopenharmony_ci    %22 = OpLabel
1786fd4e5da5Sopenharmony_ci          OpBranch %19
1787fd4e5da5Sopenharmony_ci    %19 = OpLabel
1788fd4e5da5Sopenharmony_ci          OpBranch %13
1789fd4e5da5Sopenharmony_ci    %13 = OpLabel
1790fd4e5da5Sopenharmony_ci          OpBranch %10
1791fd4e5da5Sopenharmony_ci    %12 = OpLabel
1792fd4e5da5Sopenharmony_ci          OpReturn
1793fd4e5da5Sopenharmony_ci          OpFunctionEnd
1794fd4e5da5Sopenharmony_ci  )";
1795fd4e5da5Sopenharmony_ci
1796fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(spv_asm, true);
1797fd4e5da5Sopenharmony_ci}
1798fd4e5da5Sopenharmony_ci
1799fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, VariablePointerTest1) {
1800fd4e5da5Sopenharmony_ci  // Check that the load of the first variable is still used and that the load
1801fd4e5da5Sopenharmony_ci  // of the third variable is propagated.  The first load has to remain because
1802fd4e5da5Sopenharmony_ci  // of the store to the variable pointer.
1803fd4e5da5Sopenharmony_ci  const std::string text = R"(
1804fd4e5da5Sopenharmony_ci; CHECK: [[v1:%\w+]] = OpVariable
1805fd4e5da5Sopenharmony_ci; CHECK: [[v2:%\w+]] = OpVariable
1806fd4e5da5Sopenharmony_ci; CHECK: [[v3:%\w+]] = OpVariable
1807fd4e5da5Sopenharmony_ci; CHECK: [[ld1:%\w+]] = OpLoad %int [[v1]]
1808fd4e5da5Sopenharmony_ci; CHECK: OpIAdd %int [[ld1]] %int_0
1809fd4e5da5Sopenharmony_ci               OpCapability Shader
1810fd4e5da5Sopenharmony_ci               OpCapability VariablePointers
1811fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
1812fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
1813fd4e5da5Sopenharmony_ci               OpEntryPoint GLCompute %2 "main"
1814fd4e5da5Sopenharmony_ci               OpExecutionMode %2 LocalSize 1 1 1
1815fd4e5da5Sopenharmony_ci               OpSource GLSL 450
1816fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_3 0 Offset 0
1817fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_3 1 Offset 4
1818fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
1819fd4e5da5Sopenharmony_ci          %5 = OpTypeFunction %void
1820fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
1821fd4e5da5Sopenharmony_ci       %bool = OpTypeBool
1822fd4e5da5Sopenharmony_ci  %_struct_3 = OpTypeStruct %int %int
1823fd4e5da5Sopenharmony_ci%_ptr_Function__struct_3 = OpTypePointer Function %_struct_3
1824fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
1825fd4e5da5Sopenharmony_ci       %true = OpConstantTrue %bool
1826fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
1827fd4e5da5Sopenharmony_ci      %int_1 = OpConstant %int 1
1828fd4e5da5Sopenharmony_ci         %13 = OpConstantNull %_struct_3
1829fd4e5da5Sopenharmony_ci          %2 = OpFunction %void None %5
1830fd4e5da5Sopenharmony_ci         %14 = OpLabel
1831fd4e5da5Sopenharmony_ci         %15 = OpVariable %_ptr_Function_int Function
1832fd4e5da5Sopenharmony_ci         %16 = OpVariable %_ptr_Function_int Function
1833fd4e5da5Sopenharmony_ci         %17 = OpVariable %_ptr_Function_int Function
1834fd4e5da5Sopenharmony_ci               OpStore %15 %int_1
1835fd4e5da5Sopenharmony_ci               OpStore %17 %int_0
1836fd4e5da5Sopenharmony_ci               OpSelectionMerge %18 None
1837fd4e5da5Sopenharmony_ci               OpBranchConditional %true %19 %20
1838fd4e5da5Sopenharmony_ci         %19 = OpLabel
1839fd4e5da5Sopenharmony_ci               OpBranch %18
1840fd4e5da5Sopenharmony_ci         %20 = OpLabel
1841fd4e5da5Sopenharmony_ci               OpBranch %18
1842fd4e5da5Sopenharmony_ci         %18 = OpLabel
1843fd4e5da5Sopenharmony_ci         %21 = OpPhi %_ptr_Function_int %15 %19 %16 %20
1844fd4e5da5Sopenharmony_ci               OpStore %21 %int_0
1845fd4e5da5Sopenharmony_ci         %22 = OpLoad %int %15
1846fd4e5da5Sopenharmony_ci         %23 = OpLoad %int %17
1847fd4e5da5Sopenharmony_ci         %24 = OpIAdd %int %22 %23
1848fd4e5da5Sopenharmony_ci               OpReturn
1849fd4e5da5Sopenharmony_ci               OpFunctionEnd
1850fd4e5da5Sopenharmony_ci  )";
1851fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, false);
1852fd4e5da5Sopenharmony_ci}
1853fd4e5da5Sopenharmony_ci
1854fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, VariablePointerTest2) {
1855fd4e5da5Sopenharmony_ci  // Check that the load of the first variable is still used and that the load
1856fd4e5da5Sopenharmony_ci  // of the third variable is propagated.  The first load has to remain because
1857fd4e5da5Sopenharmony_ci  // of the store to the variable pointer.
1858fd4e5da5Sopenharmony_ci  const std::string text = R"(
1859fd4e5da5Sopenharmony_ci; CHECK: [[v1:%\w+]] = OpVariable
1860fd4e5da5Sopenharmony_ci; CHECK: [[v2:%\w+]] = OpVariable
1861fd4e5da5Sopenharmony_ci; CHECK: [[v3:%\w+]] = OpVariable
1862fd4e5da5Sopenharmony_ci; CHECK: [[ld1:%\w+]] = OpLoad %int [[v1]]
1863fd4e5da5Sopenharmony_ci; CHECK: OpIAdd %int [[ld1]] %int_0
1864fd4e5da5Sopenharmony_ci               OpCapability Shader
1865fd4e5da5Sopenharmony_ci               OpCapability VariablePointers
1866fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
1867fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
1868fd4e5da5Sopenharmony_ci               OpEntryPoint GLCompute %2 "main"
1869fd4e5da5Sopenharmony_ci               OpExecutionMode %2 LocalSize 1 1 1
1870fd4e5da5Sopenharmony_ci               OpSource GLSL 450
1871fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_3 0 Offset 0
1872fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_3 1 Offset 4
1873fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
1874fd4e5da5Sopenharmony_ci          %5 = OpTypeFunction %void
1875fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
1876fd4e5da5Sopenharmony_ci       %bool = OpTypeBool
1877fd4e5da5Sopenharmony_ci  %_struct_3 = OpTypeStruct %int %int
1878fd4e5da5Sopenharmony_ci%_ptr_Function__struct_3 = OpTypePointer Function %_struct_3
1879fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
1880fd4e5da5Sopenharmony_ci       %true = OpConstantTrue %bool
1881fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
1882fd4e5da5Sopenharmony_ci      %int_1 = OpConstant %int 1
1883fd4e5da5Sopenharmony_ci         %13 = OpConstantNull %_struct_3
1884fd4e5da5Sopenharmony_ci          %2 = OpFunction %void None %5
1885fd4e5da5Sopenharmony_ci         %14 = OpLabel
1886fd4e5da5Sopenharmony_ci         %15 = OpVariable %_ptr_Function_int Function
1887fd4e5da5Sopenharmony_ci         %16 = OpVariable %_ptr_Function_int Function
1888fd4e5da5Sopenharmony_ci         %17 = OpVariable %_ptr_Function_int Function
1889fd4e5da5Sopenharmony_ci               OpStore %15 %int_1
1890fd4e5da5Sopenharmony_ci               OpStore %17 %int_0
1891fd4e5da5Sopenharmony_ci               OpSelectionMerge %18 None
1892fd4e5da5Sopenharmony_ci               OpBranchConditional %true %19 %20
1893fd4e5da5Sopenharmony_ci         %19 = OpLabel
1894fd4e5da5Sopenharmony_ci               OpBranch %18
1895fd4e5da5Sopenharmony_ci         %20 = OpLabel
1896fd4e5da5Sopenharmony_ci               OpBranch %18
1897fd4e5da5Sopenharmony_ci         %18 = OpLabel
1898fd4e5da5Sopenharmony_ci         %21 = OpPhi %_ptr_Function_int %15 %19 %16 %20
1899fd4e5da5Sopenharmony_ci               OpStore %21 %int_0
1900fd4e5da5Sopenharmony_ci         %22 = OpLoad %int %15
1901fd4e5da5Sopenharmony_ci         %23 = OpLoad %int %17
1902fd4e5da5Sopenharmony_ci         %24 = OpIAdd %int %22 %23
1903fd4e5da5Sopenharmony_ci               OpReturn
1904fd4e5da5Sopenharmony_ci               OpFunctionEnd
1905fd4e5da5Sopenharmony_ci  )";
1906fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, false);
1907fd4e5da5Sopenharmony_ci}
1908fd4e5da5Sopenharmony_ci
1909fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, ChainedTrivialPhis) {
1910fd4e5da5Sopenharmony_ci  // Check that the copy object get the undef value implicitly assigned in the
1911fd4e5da5Sopenharmony_ci  // entry block.
1912fd4e5da5Sopenharmony_ci  const std::string text = R"(
1913fd4e5da5Sopenharmony_ci; CHECK: [[undef:%\w+]] = OpUndef %v4float
1914fd4e5da5Sopenharmony_ci; CHECK: OpCopyObject %v4float [[undef]]
1915fd4e5da5Sopenharmony_ci               OpCapability Shader
1916fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
1917fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
1918fd4e5da5Sopenharmony_ci               OpEntryPoint GLCompute %2 "main"
1919fd4e5da5Sopenharmony_ci               OpExecutionMode %2 LocalSize 1 18 6
1920fd4e5da5Sopenharmony_ci               OpSource ESSL 310
1921fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
1922fd4e5da5Sopenharmony_ci          %4 = OpTypeFunction %void
1923fd4e5da5Sopenharmony_ci       %bool = OpTypeBool
1924fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
1925fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
1926fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
1927fd4e5da5Sopenharmony_ci          %2 = OpFunction %void None %4
1928fd4e5da5Sopenharmony_ci          %9 = OpLabel
1929fd4e5da5Sopenharmony_ci         %10 = OpVariable %_ptr_Function_v4float Function
1930fd4e5da5Sopenharmony_ci               OpBranch %11
1931fd4e5da5Sopenharmony_ci         %11 = OpLabel
1932fd4e5da5Sopenharmony_ci               OpLoopMerge %12 %13 None
1933fd4e5da5Sopenharmony_ci               OpBranch %14
1934fd4e5da5Sopenharmony_ci         %14 = OpLabel
1935fd4e5da5Sopenharmony_ci         %15 = OpUndef %bool
1936fd4e5da5Sopenharmony_ci               OpBranchConditional %15 %16 %12
1937fd4e5da5Sopenharmony_ci         %16 = OpLabel
1938fd4e5da5Sopenharmony_ci         %17 = OpUndef %bool
1939fd4e5da5Sopenharmony_ci               OpSelectionMerge %18 None
1940fd4e5da5Sopenharmony_ci               OpBranchConditional %17 %19 %18
1941fd4e5da5Sopenharmony_ci         %19 = OpLabel
1942fd4e5da5Sopenharmony_ci         %20 = OpUndef %bool
1943fd4e5da5Sopenharmony_ci               OpLoopMerge %21 %22 None
1944fd4e5da5Sopenharmony_ci               OpBranchConditional %20 %23 %21
1945fd4e5da5Sopenharmony_ci         %23 = OpLabel
1946fd4e5da5Sopenharmony_ci         %24 = OpLoad %v4float %10
1947fd4e5da5Sopenharmony_ci         %25 = OpCopyObject %v4float %24
1948fd4e5da5Sopenharmony_ci         %26 = OpUndef %bool
1949fd4e5da5Sopenharmony_ci               OpBranch %22
1950fd4e5da5Sopenharmony_ci         %22 = OpLabel
1951fd4e5da5Sopenharmony_ci               OpBranch %19
1952fd4e5da5Sopenharmony_ci         %21 = OpLabel
1953fd4e5da5Sopenharmony_ci               OpBranch %12
1954fd4e5da5Sopenharmony_ci         %18 = OpLabel
1955fd4e5da5Sopenharmony_ci               OpBranch %13
1956fd4e5da5Sopenharmony_ci         %13 = OpLabel
1957fd4e5da5Sopenharmony_ci               OpBranch %11
1958fd4e5da5Sopenharmony_ci         %12 = OpLabel
1959fd4e5da5Sopenharmony_ci         %27 = OpLoad %v4float %10
1960fd4e5da5Sopenharmony_ci               OpReturn
1961fd4e5da5Sopenharmony_ci               OpFunctionEnd
1962fd4e5da5Sopenharmony_ci  )";
1963fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, false);
1964fd4e5da5Sopenharmony_ci}
1965fd4e5da5Sopenharmony_ci
1966fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, Overflowtest1) {
1967fd4e5da5Sopenharmony_ci  // Check that the copy object get the undef value implicitly assigned in the
1968fd4e5da5Sopenharmony_ci  // entry block.
1969fd4e5da5Sopenharmony_ci  const std::string text = R"(
1970fd4e5da5Sopenharmony_ciOpCapability Geometry
1971fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1972fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %4 "P2Mai" %12 %17
1973fd4e5da5Sopenharmony_ciOpExecutionMode %4 OriginUpperLeft
1974fd4e5da5Sopenharmony_ci%2 = OpTypeVoid
1975fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %2
1976fd4e5da5Sopenharmony_ci%6 = OpTypeFloat 32
1977fd4e5da5Sopenharmony_ci%7 = OpTypeVector %6 4
1978fd4e5da5Sopenharmony_ci%11 = OpTypePointer Input %7
1979fd4e5da5Sopenharmony_ci%16 = OpTypePointer Output %7
1980fd4e5da5Sopenharmony_ci%23 = OpTypePointer Function %7
1981fd4e5da5Sopenharmony_ci%12 = OpVariable %11 Input
1982fd4e5da5Sopenharmony_ci%17 = OpVariable %16 Output
1983fd4e5da5Sopenharmony_ci%4 = OpFunction %2 None %3
1984fd4e5da5Sopenharmony_ci%2177 = OpLabel
1985fd4e5da5Sopenharmony_ci%4194302 = OpVariable %23 Function
1986fd4e5da5Sopenharmony_ci%4194301 = OpLoad %7 %4194302
1987fd4e5da5Sopenharmony_ciOpStore %17 %4194301
1988fd4e5da5Sopenharmony_ciOpReturn
1989fd4e5da5Sopenharmony_ciOpFunctionEnd
1990fd4e5da5Sopenharmony_ci  )";
1991fd4e5da5Sopenharmony_ci
1992fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1993fd4e5da5Sopenharmony_ci
1994fd4e5da5Sopenharmony_ci  std::vector<Message> messages = {
1995fd4e5da5Sopenharmony_ci      {SPV_MSG_ERROR, "", 0, 0, "ID overflow. Try running compact-ids."}};
1996fd4e5da5Sopenharmony_ci  SetMessageConsumer(GetTestMessageConsumer(messages));
1997fd4e5da5Sopenharmony_ci  auto result = SinglePassRunToBinary<SSARewritePass>(text, true);
1998fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::Failure, std::get<1>(result));
1999fd4e5da5Sopenharmony_ci}
2000fd4e5da5Sopenharmony_ci
2001fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, OpConstantNull) {
2002fd4e5da5Sopenharmony_ci  const std::string text = R"(
2003fd4e5da5Sopenharmony_ciOpCapability Addresses
2004fd4e5da5Sopenharmony_ciOpCapability Kernel
2005fd4e5da5Sopenharmony_ciOpCapability Int64
2006fd4e5da5Sopenharmony_ciOpMemoryModel Physical64 OpenCL
2007fd4e5da5Sopenharmony_ciOpEntryPoint Kernel %4 "A"
2008fd4e5da5Sopenharmony_ciOpSource OpenCL_C 200000
2009fd4e5da5Sopenharmony_ci%2 = OpTypeVoid
2010fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %2
2011fd4e5da5Sopenharmony_ci%6 = OpTypeInt 32 0
2012fd4e5da5Sopenharmony_ci%11 = OpTypePointer CrossWorkgroup %6
2013fd4e5da5Sopenharmony_ci%16 = OpConstantNull %11
2014fd4e5da5Sopenharmony_ci%20 = OpConstant %6 269484031
2015fd4e5da5Sopenharmony_ci%4 = OpFunction %2 None %3
2016fd4e5da5Sopenharmony_ci%17 = OpLabel
2017fd4e5da5Sopenharmony_ci%18 = OpLoad %6 %16 Aligned 536870912
2018fd4e5da5Sopenharmony_ci%19 = OpBitwiseXor %6 %18 %20
2019fd4e5da5Sopenharmony_ciOpStore %16 %19 Aligned 536870912
2020fd4e5da5Sopenharmony_ciOpReturn
2021fd4e5da5Sopenharmony_ciOpFunctionEnd
2022fd4e5da5Sopenharmony_ci  )";
2023fd4e5da5Sopenharmony_ci
2024fd4e5da5Sopenharmony_ci  SinglePassRunToBinary<SSARewritePass>(text, false);
2025fd4e5da5Sopenharmony_ci}
2026fd4e5da5Sopenharmony_ci
2027fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DebugForLoop) {
2028fd4e5da5Sopenharmony_ci  // #version 140
2029fd4e5da5Sopenharmony_ci  //
2030fd4e5da5Sopenharmony_ci  // in vec4 BC;
2031fd4e5da5Sopenharmony_ci  // out float fo;
2032fd4e5da5Sopenharmony_ci  //
2033fd4e5da5Sopenharmony_ci  // void main()
2034fd4e5da5Sopenharmony_ci  // {
2035fd4e5da5Sopenharmony_ci  //     float f = 0.0;
2036fd4e5da5Sopenharmony_ci  //     for (int i=0; i<4; i++) {
2037fd4e5da5Sopenharmony_ci  //       f = f + BC[i];
2038fd4e5da5Sopenharmony_ci  //     }
2039fd4e5da5Sopenharmony_ci  //     fo = f;
2040fd4e5da5Sopenharmony_ci  // }
2041fd4e5da5Sopenharmony_ci
2042fd4e5da5Sopenharmony_ci  const std::string text = R"(
2043fd4e5da5Sopenharmony_ci; CHECK: [[f_name:%\w+]] = OpString "f"
2044fd4e5da5Sopenharmony_ci; CHECK: [[i_name:%\w+]] = OpString "i"
2045fd4e5da5Sopenharmony_ci; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugLocalVariable [[f_name]]
2046fd4e5da5Sopenharmony_ci; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]]
2047fd4e5da5Sopenharmony_ci
2048fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f %float_0
2049fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0
2050fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpStore %i %int_0
2051fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] %int_0
2052fd4e5da5Sopenharmony_ci
2053fd4e5da5Sopenharmony_ci; CHECK-NOT:  DebugDeclare
2054fd4e5da5Sopenharmony_ci
2055fd4e5da5Sopenharmony_ci; CHECK:      [[loop_head:%\w+]] = OpLabel
2056fd4e5da5Sopenharmony_ci; CHECK:      [[phi0:%\w+]] = OpPhi %float %float_0
2057fd4e5da5Sopenharmony_ci; CHECK:      [[phi1:%\w+]] = OpPhi %int %int_0
2058fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[phi0]]
2059fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[phi1]]
2060fd4e5da5Sopenharmony_ci; CHECK:      OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
2061fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
2062fd4e5da5Sopenharmony_ci
2063fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[loop_body]] = OpLabel
2064fd4e5da5Sopenharmony_ci; CHECK:      OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
2065fd4e5da5Sopenharmony_ci
2066fd4e5da5Sopenharmony_ci; CHECK:      [[bb]] = OpLabel
2067fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f [[f_val:%\w+]]
2068fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_val]]
2069fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_cont]]
2070fd4e5da5Sopenharmony_ci
2071fd4e5da5Sopenharmony_ci; CHECK:      [[loop_cont]] = OpLabel
2072fd4e5da5Sopenharmony_ci; CHECK:      OpStore %i [[i_val:%\w+]]
2073fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[i_val]]
2074fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_head]]
2075fd4e5da5Sopenharmony_ci
2076fd4e5da5Sopenharmony_ci; CHECK:      [[loop_merge]] = OpLabel
2077fd4e5da5Sopenharmony_ci
2078fd4e5da5Sopenharmony_ciOpCapability Shader
2079fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2080fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
2081fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2082fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
2083fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2084fd4e5da5Sopenharmony_ci%file_name = OpString "test"
2085fd4e5da5Sopenharmony_ciOpSource GLSL 140
2086fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2087fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2088fd4e5da5Sopenharmony_ci%f_name = OpString "f"
2089fd4e5da5Sopenharmony_ci%i_name = OpString "i"
2090fd4e5da5Sopenharmony_ciOpName %main "main"
2091fd4e5da5Sopenharmony_ciOpName %f "f"
2092fd4e5da5Sopenharmony_ciOpName %i "i"
2093fd4e5da5Sopenharmony_ciOpName %BC "BC"
2094fd4e5da5Sopenharmony_ciOpName %fo "fo"
2095fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2096fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
2097fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2098fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2099fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2100fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2101fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2102fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
2103fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2104fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2105fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
2106fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2107fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
2108fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
2109fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
2110fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
2111fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2112fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2113fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
2114fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
2115fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
2116fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
2117fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
2118fd4e5da5Sopenharmony_ci%dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
2119fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
2120fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
2121fd4e5da5Sopenharmony_ci%dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
2122fd4e5da5Sopenharmony_ci%dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
2123fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
2124fd4e5da5Sopenharmony_ci%22 = OpLabel
2125fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
2126fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
2127fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
2128fd4e5da5Sopenharmony_ciOpStore %f %float_0
2129fd4e5da5Sopenharmony_ciOpStore %i %int_0
2130fd4e5da5Sopenharmony_ci%decl0 = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
2131fd4e5da5Sopenharmony_ci%decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %i %null_expr
2132fd4e5da5Sopenharmony_ciOpBranch %23
2133fd4e5da5Sopenharmony_ci%23 = OpLabel
2134fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
2135fd4e5da5Sopenharmony_ciOpLoopMerge %24 %25 None
2136fd4e5da5Sopenharmony_ciOpBranch %26
2137fd4e5da5Sopenharmony_ci%26 = OpLabel
2138fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
2139fd4e5da5Sopenharmony_ci%27 = OpLoad %int %i
2140fd4e5da5Sopenharmony_ci%28 = OpSLessThan %bool %27 %int_4
2141fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %24
2142fd4e5da5Sopenharmony_ci%29 = OpLabel
2143fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
2144fd4e5da5Sopenharmony_ci%30 = OpLoad %float %f
2145fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
2146fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
2147fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
2148fd4e5da5Sopenharmony_ci%34 = OpFAdd %float %30 %33
2149fd4e5da5Sopenharmony_ciOpStore %f %34
2150fd4e5da5Sopenharmony_ciOpBranch %25
2151fd4e5da5Sopenharmony_ci%25 = OpLabel
2152fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
2153fd4e5da5Sopenharmony_ci%35 = OpLoad %int %i
2154fd4e5da5Sopenharmony_ci%36 = OpIAdd %int %35 %int_1
2155fd4e5da5Sopenharmony_ciOpStore %i %36
2156fd4e5da5Sopenharmony_ciOpBranch %23
2157fd4e5da5Sopenharmony_ci%24 = OpLabel
2158fd4e5da5Sopenharmony_ci%s5 = OpExtInst %void %ext DebugScope %dbg_main
2159fd4e5da5Sopenharmony_ci%37 = OpLoad %float %f
2160fd4e5da5Sopenharmony_ciOpStore %fo %37
2161fd4e5da5Sopenharmony_ciOpReturn
2162fd4e5da5Sopenharmony_ciOpFunctionEnd
2163fd4e5da5Sopenharmony_ci)";
2164fd4e5da5Sopenharmony_ci
2165fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
2166fd4e5da5Sopenharmony_ci}
2167fd4e5da5Sopenharmony_ci
2168fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, ShaderDebugForLoop) {
2169fd4e5da5Sopenharmony_ci  const std::string text = R"(
2170fd4e5da5Sopenharmony_ci; CHECK: [[f_name:%\w+]] = OpString "f"
2171fd4e5da5Sopenharmony_ci; CHECK: [[i_name:%\w+]] = OpString "i"
2172fd4e5da5Sopenharmony_ci; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugLocalVariable [[f_name]]
2173fd4e5da5Sopenharmony_ci; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]]
2174fd4e5da5Sopenharmony_ci
2175fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f %float_0
2176fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0
2177fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpStore %i %int_0
2178fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] %int_0
2179fd4e5da5Sopenharmony_ci
2180fd4e5da5Sopenharmony_ci; CHECK-NOT:  DebugDeclare
2181fd4e5da5Sopenharmony_ci
2182fd4e5da5Sopenharmony_ci; CHECK:      [[loop_head:%\w+]] = OpLabel
2183fd4e5da5Sopenharmony_ci; CHECK:      [[phi0:%\w+]] = OpPhi %float %float_0
2184fd4e5da5Sopenharmony_ci; CHECK:      [[phi1:%\w+]] = OpPhi %int %int_0
2185fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[phi0]]
2186fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[phi1]]
2187fd4e5da5Sopenharmony_ci; CHECK:      OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
2188fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
2189fd4e5da5Sopenharmony_ci
2190fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[loop_body]] = OpLabel
2191fd4e5da5Sopenharmony_ci; CHECK:      OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
2192fd4e5da5Sopenharmony_ci
2193fd4e5da5Sopenharmony_ci; CHECK:      [[bb]] = OpLabel
2194fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f [[f_val:%\w+]]
2195fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_val]]
2196fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_cont]]
2197fd4e5da5Sopenharmony_ci
2198fd4e5da5Sopenharmony_ci; CHECK:      [[loop_cont]] = OpLabel
2199fd4e5da5Sopenharmony_ci; CHECK:      OpStore %i [[i_val:%\w+]]
2200fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[i_val]]
2201fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_head]]
2202fd4e5da5Sopenharmony_ci
2203fd4e5da5Sopenharmony_ci; CHECK:      [[loop_merge]] = OpLabel
2204fd4e5da5Sopenharmony_ci
2205fd4e5da5Sopenharmony_ciOpCapability Shader
2206fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
2207fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2208fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
2209fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2210fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
2211fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2212fd4e5da5Sopenharmony_ci%file_name = OpString "test"
2213fd4e5da5Sopenharmony_ciOpSource GLSL 140
2214fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2215fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2216fd4e5da5Sopenharmony_ci%f_name = OpString "f"
2217fd4e5da5Sopenharmony_ci%i_name = OpString "i"
2218fd4e5da5Sopenharmony_ciOpName %main "main"
2219fd4e5da5Sopenharmony_ciOpName %f "f"
2220fd4e5da5Sopenharmony_ciOpName %i "i"
2221fd4e5da5Sopenharmony_ciOpName %BC "BC"
2222fd4e5da5Sopenharmony_ciOpName %fo "fo"
2223fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2224fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
2225fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2226fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2227fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2228fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2229fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2230fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
2231fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
2232fd4e5da5Sopenharmony_ci%uint_3 = OpConstant %uint 3
2233fd4e5da5Sopenharmony_ci%uint_4 = OpConstant %uint 4
2234fd4e5da5Sopenharmony_ci%uint_5 = OpConstant %uint 5
2235fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
2236fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
2237fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2238fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2239fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
2240fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2241fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
2242fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
2243fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
2244fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
2245fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2246fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2247fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
2248fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
2249fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
2250fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit %uint_1 %uint_4 %src %uint_5
2251fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 %uint_3 %uint_0
2252fd4e5da5Sopenharmony_ci%dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf %uint_4
2253fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction %uint_3 %dbg_v4f %dbg_v4f
2254fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src %uint_0 %uint_0 %cu %main_name %uint_3 %uint_10
2255fd4e5da5Sopenharmony_ci%dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src %uint_0 %uint_0 %dbg_main %uint_4
2256fd4e5da5Sopenharmony_ci%dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src %uint_0 %uint_0 %dbg_main %uint_4
2257fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
2258fd4e5da5Sopenharmony_ci%22 = OpLabel
2259fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
2260fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
2261fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
2262fd4e5da5Sopenharmony_ciOpStore %f %float_0
2263fd4e5da5Sopenharmony_ciOpStore %i %int_0
2264fd4e5da5Sopenharmony_ci%decl0 = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
2265fd4e5da5Sopenharmony_ci%decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %i %null_expr
2266fd4e5da5Sopenharmony_ciOpBranch %23
2267fd4e5da5Sopenharmony_ci%23 = OpLabel
2268fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
2269fd4e5da5Sopenharmony_ciOpLoopMerge %24 %25 None
2270fd4e5da5Sopenharmony_ciOpBranch %26
2271fd4e5da5Sopenharmony_ci%26 = OpLabel
2272fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
2273fd4e5da5Sopenharmony_ci%27 = OpLoad %int %i
2274fd4e5da5Sopenharmony_ci%28 = OpSLessThan %bool %27 %int_4
2275fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %24
2276fd4e5da5Sopenharmony_ci%29 = OpLabel
2277fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
2278fd4e5da5Sopenharmony_ci%30 = OpLoad %float %f
2279fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
2280fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
2281fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
2282fd4e5da5Sopenharmony_ci%34 = OpFAdd %float %30 %33
2283fd4e5da5Sopenharmony_ciOpStore %f %34
2284fd4e5da5Sopenharmony_ciOpBranch %25
2285fd4e5da5Sopenharmony_ci%25 = OpLabel
2286fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
2287fd4e5da5Sopenharmony_ci%35 = OpLoad %int %i
2288fd4e5da5Sopenharmony_ci%36 = OpIAdd %int %35 %int_1
2289fd4e5da5Sopenharmony_ciOpStore %i %36
2290fd4e5da5Sopenharmony_ciOpBranch %23
2291fd4e5da5Sopenharmony_ci%24 = OpLabel
2292fd4e5da5Sopenharmony_ci%s5 = OpExtInst %void %ext DebugScope %dbg_main
2293fd4e5da5Sopenharmony_ci%37 = OpLoad %float %f
2294fd4e5da5Sopenharmony_ciOpStore %fo %37
2295fd4e5da5Sopenharmony_ciOpReturn
2296fd4e5da5Sopenharmony_ciOpFunctionEnd
2297fd4e5da5Sopenharmony_ci)";
2298fd4e5da5Sopenharmony_ci
2299fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
2300fd4e5da5Sopenharmony_ci}
2301fd4e5da5Sopenharmony_ci
2302fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, AddDebugValueForFunctionParameterWithPhi) {
2303fd4e5da5Sopenharmony_ci  // Test the distribution of DebugValue for a parameter of an inlined function
2304fd4e5da5Sopenharmony_ci  // and the visibility of Phi instruction. The ssa-rewrite pass must add
2305fd4e5da5Sopenharmony_ci  // DebugValue for the value assignment of function argument even when it is an
2306fd4e5da5Sopenharmony_ci  // inlined function. It has to check the visibility Phi through all its value
2307fd4e5da5Sopenharmony_ci  // operands. See the DebugValue for "int i" of "foo()" in the following code.
2308fd4e5da5Sopenharmony_ci  //
2309fd4e5da5Sopenharmony_ci  // struct VS_OUTPUT {
2310fd4e5da5Sopenharmony_ci  //   float4 pos : SV_POSITION;
2311fd4e5da5Sopenharmony_ci  //   float4 color : COLOR;
2312fd4e5da5Sopenharmony_ci  // };
2313fd4e5da5Sopenharmony_ci  //
2314fd4e5da5Sopenharmony_ci  // float4 foo(int i, float4 pos) {
2315fd4e5da5Sopenharmony_ci  //   while (i < pos.x) {
2316fd4e5da5Sopenharmony_ci  //     pos = pos.x + i;
2317fd4e5da5Sopenharmony_ci  //     ++i;
2318fd4e5da5Sopenharmony_ci  //   }
2319fd4e5da5Sopenharmony_ci  //   return pos;
2320fd4e5da5Sopenharmony_ci  // }
2321fd4e5da5Sopenharmony_ci  //
2322fd4e5da5Sopenharmony_ci  // VS_OUTPUT main(float4 pos : POSITION,
2323fd4e5da5Sopenharmony_ci  //                float4 color : COLOR) {
2324fd4e5da5Sopenharmony_ci  //   VS_OUTPUT vout;
2325fd4e5da5Sopenharmony_ci  //   vout.pos = foo(4, pos);
2326fd4e5da5Sopenharmony_ci  //   vout.color = color;
2327fd4e5da5Sopenharmony_ci  //   return vout;
2328fd4e5da5Sopenharmony_ci  // }
2329fd4e5da5Sopenharmony_ci  const std::string text = R"(
2330fd4e5da5Sopenharmony_ci               OpCapability Shader
2331fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "OpenCL.DebugInfo.100"
2332fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
2333fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %in_var_POSITION %in_var_COLOR %gl_Position %out_var_COLOR
2334fd4e5da5Sopenharmony_ci          %7 = OpString "vertex.hlsl"
2335fd4e5da5Sopenharmony_ci          %8 = OpString "float"
2336fd4e5da5Sopenharmony_ci          %9 = OpString "VS_OUTPUT"
2337fd4e5da5Sopenharmony_ci         %10 = OpString "color"
2338fd4e5da5Sopenharmony_ci         %11 = OpString "pos"
2339fd4e5da5Sopenharmony_ci         %12 = OpString "int"
2340fd4e5da5Sopenharmony_ci         %13 = OpString "foo"
2341fd4e5da5Sopenharmony_ci         %14 = OpString ""
2342fd4e5da5Sopenharmony_ci         %15 = OpString "i"
2343fd4e5da5Sopenharmony_ci         %16 = OpString "main"
2344fd4e5da5Sopenharmony_ci         %17 = OpString "vout"
2345fd4e5da5Sopenharmony_ci               OpName %in_var_POSITION "in.var.POSITION"
2346fd4e5da5Sopenharmony_ci               OpName %in_var_COLOR "in.var.COLOR"
2347fd4e5da5Sopenharmony_ci               OpName %out_var_COLOR "out.var.COLOR"
2348fd4e5da5Sopenharmony_ci               OpName %main "main"
2349fd4e5da5Sopenharmony_ci               OpName %param_var_pos "param.var.pos"
2350fd4e5da5Sopenharmony_ci               OpName %param_var_color "param.var.color"
2351fd4e5da5Sopenharmony_ci               OpName %VS_OUTPUT "VS_OUTPUT"
2352fd4e5da5Sopenharmony_ci               OpMemberName %VS_OUTPUT 0 "pos"
2353fd4e5da5Sopenharmony_ci               OpMemberName %VS_OUTPUT 1 "color"
2354fd4e5da5Sopenharmony_ci               OpDecorate %gl_Position BuiltIn Position
2355fd4e5da5Sopenharmony_ci               OpDecorate %in_var_POSITION Location 0
2356fd4e5da5Sopenharmony_ci               OpDecorate %in_var_COLOR Location 1
2357fd4e5da5Sopenharmony_ci               OpDecorate %out_var_COLOR Location 0
2358fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
2359fd4e5da5Sopenharmony_ci      %int_4 = OpConstant %int 4
2360fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
2361fd4e5da5Sopenharmony_ci      %int_1 = OpConstant %int 1
2362fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
2363fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
2364fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
2365fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
2366fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
2367fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
2368fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
2369fd4e5da5Sopenharmony_ci   %uint_256 = OpConstant %uint 256
2370fd4e5da5Sopenharmony_ci   %uint_128 = OpConstant %uint 128
2371fd4e5da5Sopenharmony_ci     %uint_0 = OpConstant %uint 0
2372fd4e5da5Sopenharmony_ci         %50 = OpTypeFunction %void
2373fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
2374fd4e5da5Sopenharmony_ci  %VS_OUTPUT = OpTypeStruct %v4float %v4float
2375fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2376fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2377fd4e5da5Sopenharmony_ci       %bool = OpTypeBool
2378fd4e5da5Sopenharmony_ci%in_var_POSITION = OpVariable %_ptr_Input_v4float Input
2379fd4e5da5Sopenharmony_ci%in_var_COLOR = OpVariable %_ptr_Input_v4float Input
2380fd4e5da5Sopenharmony_ci%gl_Position = OpVariable %_ptr_Output_v4float Output
2381fd4e5da5Sopenharmony_ci%out_var_COLOR = OpVariable %_ptr_Output_v4float Output
2382fd4e5da5Sopenharmony_ci        %156 = OpExtInst %void %1 DebugInfoNone
2383fd4e5da5Sopenharmony_ci         %77 = OpExtInst %void %1 DebugExpression
2384fd4e5da5Sopenharmony_ci         %58 = OpExtInst %void %1 DebugTypeBasic %8 %uint_32 Float
2385fd4e5da5Sopenharmony_ci         %59 = OpExtInst %void %1 DebugTypeVector %58 4
2386fd4e5da5Sopenharmony_ci         %60 = OpExtInst %void %1 DebugSource %7
2387fd4e5da5Sopenharmony_ci         %61 = OpExtInst %void %1 DebugCompilationUnit 1 4 %60 HLSL
2388fd4e5da5Sopenharmony_ci         %62 = OpExtInst %void %1 DebugTypeComposite %9 Structure %60 1 8 %61 %9 %uint_256 FlagIsProtected|FlagIsPrivate %63 %64
2389fd4e5da5Sopenharmony_ci         %64 = OpExtInst %void %1 DebugTypeMember %10 %59 %60 3 10 %62 %uint_128 %uint_128 FlagIsProtected|FlagIsPrivate
2390fd4e5da5Sopenharmony_ci         %63 = OpExtInst %void %1 DebugTypeMember %11 %59 %60 2 10 %62 %uint_0 %uint_128 FlagIsProtected|FlagIsPrivate
2391fd4e5da5Sopenharmony_ci         %65 = OpExtInst %void %1 DebugTypeBasic %12 %uint_32 Signed
2392fd4e5da5Sopenharmony_ci         %66 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %59 %65 %59
2393fd4e5da5Sopenharmony_ci         %67 = OpExtInst %void %1 DebugFunction %13 %66 %60 6 1 %61 %14 FlagIsProtected|FlagIsPrivate 6 %156
2394fd4e5da5Sopenharmony_ci         %68 = OpExtInst %void %1 DebugLexicalBlock %60 6 31 %67
2395fd4e5da5Sopenharmony_ci         %69 = OpExtInst %void %1 DebugLexicalBlock %60 7 21 %68
2396fd4e5da5Sopenharmony_ci         %70 = OpExtInst %void %1 DebugLocalVariable %11 %59 %60 6 26 %67 FlagIsLocal 2
2397fd4e5da5Sopenharmony_ci
2398fd4e5da5Sopenharmony_ci; CHECK: [[color_name:%\w+]] = OpString "color"
2399fd4e5da5Sopenharmony_ci; CHECK: [[pos_name:%\w+]] = OpString "pos"
2400fd4e5da5Sopenharmony_ci; CHECK: [[i_name:%\w+]] = OpString "i"
2401fd4e5da5Sopenharmony_ci; CHECK: [[null_expr:%\w+]] = OpExtInst %void [[ext:%\w+]] DebugExpression
2402fd4e5da5Sopenharmony_ci; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]] {{%\w+}} {{%\w+}} 6 16 {{%\w+}} FlagIsLocal 1
2403fd4e5da5Sopenharmony_ci; CHECK: [[dbg_color:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[color_name]] {{%\w+}} {{%\w+}} 15 23
2404fd4e5da5Sopenharmony_ci; CHECK: [[dbg_pos:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[pos_name]] {{%\w+}} {{%\w+}} 14 23
2405fd4e5da5Sopenharmony_ci         %71 = OpExtInst %void %1 DebugLocalVariable %15 %65 %60 6 16 %67 FlagIsLocal 1
2406fd4e5da5Sopenharmony_ci         %72 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %62 %59 %59
2407fd4e5da5Sopenharmony_ci         %73 = OpExtInst %void %1 DebugFunction %16 %72 %60 14 1 %61 %14 FlagIsProtected|FlagIsPrivate 15 %156
2408fd4e5da5Sopenharmony_ci         %74 = OpExtInst %void %1 DebugLexicalBlock %60 15 38 %73
2409fd4e5da5Sopenharmony_ci         %75 = OpExtInst %void %1 DebugLocalVariable %17 %62 %60 16 13 %74 FlagIsLocal
2410fd4e5da5Sopenharmony_ci         %76 = OpExtInst %void %1 DebugLocalVariable %10 %59 %60 15 23 %73 FlagIsLocal 2
2411fd4e5da5Sopenharmony_ci         %78 = OpExtInst %void %1 DebugLocalVariable %11 %59 %60 14 23 %73 FlagIsLocal 1
2412fd4e5da5Sopenharmony_ci        %155 = OpExtInst %void %1 DebugInlinedAt 17 %74
2413fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %50
2414fd4e5da5Sopenharmony_ci         %79 = OpLabel
2415fd4e5da5Sopenharmony_ci        %168 = OpExtInst %void %1 DebugScope %74
2416fd4e5da5Sopenharmony_ci
2417fd4e5da5Sopenharmony_ci; CHECK: [[i:%\w+]] = OpVariable %_ptr_Function_int Function
2418fd4e5da5Sopenharmony_ci        %120 = OpVariable %_ptr_Function_int Function
2419fd4e5da5Sopenharmony_ci        %121 = OpVariable %_ptr_Function_v4float Function
2420fd4e5da5Sopenharmony_ci        %169 = OpExtInst %void %1 DebugNoScope
2421fd4e5da5Sopenharmony_ci%param_var_pos = OpVariable %_ptr_Function_v4float Function
2422fd4e5da5Sopenharmony_ci%param_var_color = OpVariable %_ptr_Function_v4float Function
2423fd4e5da5Sopenharmony_ci               OpLine %7 100 105
2424fd4e5da5Sopenharmony_ci         %80 = OpLoad %v4float %in_var_POSITION
2425fd4e5da5Sopenharmony_ci               OpStore %param_var_pos %80
2426fd4e5da5Sopenharmony_ci               OpNoLine
2427fd4e5da5Sopenharmony_ci               OpLine %7 200 205
2428fd4e5da5Sopenharmony_ci         %81 = OpLoad %v4float %in_var_COLOR
2429fd4e5da5Sopenharmony_ci               OpStore %param_var_color %81
2430fd4e5da5Sopenharmony_ci               OpNoLine
2431fd4e5da5Sopenharmony_ci        %170 = OpExtInst %void %1 DebugScope %73
2432fd4e5da5Sopenharmony_ci
2433fd4e5da5Sopenharmony_ci; CHECK: OpLine {{%\w+}} 100 105
2434fd4e5da5Sopenharmony_ci; CHECK: DebugValue [[dbg_pos]]
2435fd4e5da5Sopenharmony_ci        %124 = OpExtInst %void %1 DebugDeclare %78 %param_var_pos %77
2436fd4e5da5Sopenharmony_ci; CHECK: OpLine {{%\w+}} 200 205
2437fd4e5da5Sopenharmony_ci; CHECK: DebugValue [[dbg_color]]
2438fd4e5da5Sopenharmony_ci        %125 = OpExtInst %void %1 DebugDeclare %76 %param_var_color %77
2439fd4e5da5Sopenharmony_ci
2440fd4e5da5Sopenharmony_ci        %171 = OpExtInst %void %1 DebugScope %74
2441fd4e5da5Sopenharmony_ci               OpLine %7 17 18
2442fd4e5da5Sopenharmony_ci
2443fd4e5da5Sopenharmony_ci; CHECK: OpStore {{%\w+}} %int_4
2444fd4e5da5Sopenharmony_ci; CHECK: DebugValue [[dbg_i]] %int_4 [[null_expr]]
2445fd4e5da5Sopenharmony_ci               OpStore %120 %int_4
2446fd4e5da5Sopenharmony_ci               OpStore %121 %80
2447fd4e5da5Sopenharmony_ci        %172 = OpExtInst %void %1 DebugScope %67 %155
2448fd4e5da5Sopenharmony_ci        %135 = OpExtInst %void %1 DebugDeclare %71 %120 %77
2449fd4e5da5Sopenharmony_ci        %136 = OpExtInst %void %1 DebugDeclare %70 %121 %77
2450fd4e5da5Sopenharmony_ci        %173 = OpExtInst %void %1 DebugScope %68 %155
2451fd4e5da5Sopenharmony_ci               OpLine %7 7 3
2452fd4e5da5Sopenharmony_ci               OpBranch %137
2453fd4e5da5Sopenharmony_ci        %174 = OpExtInst %void %1 DebugNoScope
2454fd4e5da5Sopenharmony_ci        %137 = OpLabel
2455fd4e5da5Sopenharmony_ci
2456fd4e5da5Sopenharmony_ci; CHECK: [[phi:%\w+]] = OpPhi %int %int_4
2457fd4e5da5Sopenharmony_ci; CHECK: DebugValue [[dbg_i]] [[phi]] [[null_expr]]
2458fd4e5da5Sopenharmony_ci        %175 = OpExtInst %void %1 DebugScope %68 %155
2459fd4e5da5Sopenharmony_ci               OpLine %7 7 10
2460fd4e5da5Sopenharmony_ci        %138 = OpLoad %int %120
2461fd4e5da5Sopenharmony_ci        %139 = OpConvertSToF %float %138
2462fd4e5da5Sopenharmony_ci               OpLine %7 7 14
2463fd4e5da5Sopenharmony_ci        %140 = OpAccessChain %_ptr_Function_float %121 %int_0
2464fd4e5da5Sopenharmony_ci        %141 = OpLoad %float %140
2465fd4e5da5Sopenharmony_ci               OpLine %7 7 12
2466fd4e5da5Sopenharmony_ci        %142 = OpFOrdLessThan %bool %139 %141
2467fd4e5da5Sopenharmony_ci               OpLine %7 7 3
2468fd4e5da5Sopenharmony_ci        %176 = OpExtInst %void %1 DebugNoScope
2469fd4e5da5Sopenharmony_ci               OpLoopMerge %153 %152 None
2470fd4e5da5Sopenharmony_ci               OpBranchConditional %142 %143 %153
2471fd4e5da5Sopenharmony_ci        %177 = OpExtInst %void %1 DebugNoScope
2472fd4e5da5Sopenharmony_ci        %143 = OpLabel
2473fd4e5da5Sopenharmony_ci        %178 = OpExtInst %void %1 DebugScope %69 %155
2474fd4e5da5Sopenharmony_ci               OpLine %7 8 11
2475fd4e5da5Sopenharmony_ci        %144 = OpAccessChain %_ptr_Function_float %121 %int_0
2476fd4e5da5Sopenharmony_ci        %145 = OpLoad %float %144
2477fd4e5da5Sopenharmony_ci               OpLine %7 8 19
2478fd4e5da5Sopenharmony_ci        %146 = OpLoad %int %120
2479fd4e5da5Sopenharmony_ci        %147 = OpConvertSToF %float %146
2480fd4e5da5Sopenharmony_ci               OpLine %7 8 17
2481fd4e5da5Sopenharmony_ci        %148 = OpFAdd %float %145 %147
2482fd4e5da5Sopenharmony_ci               OpLine %7 8 11
2483fd4e5da5Sopenharmony_ci        %149 = OpCompositeConstruct %v4float %148 %148 %148 %148
2484fd4e5da5Sopenharmony_ci               OpLine %7 8 5
2485fd4e5da5Sopenharmony_ci               OpStore %121 %149
2486fd4e5da5Sopenharmony_ci               OpLine %7 9 5
2487fd4e5da5Sopenharmony_ci        %151 = OpIAdd %int %146 %int_1
2488fd4e5da5Sopenharmony_ci               OpLine %7 9 7
2489fd4e5da5Sopenharmony_ci
2490fd4e5da5Sopenharmony_ci; CHECK: OpStore [[i]] [[value:%\w+]]
2491fd4e5da5Sopenharmony_ci; CHECK: DebugValue [[dbg_i]] [[value]] [[null_expr]]
2492fd4e5da5Sopenharmony_ci               OpStore %120 %151
2493fd4e5da5Sopenharmony_ci        %179 = OpExtInst %void %1 DebugScope %68 %155
2494fd4e5da5Sopenharmony_ci               OpLine %7 10 3
2495fd4e5da5Sopenharmony_ci               OpBranch %152
2496fd4e5da5Sopenharmony_ci        %180 = OpExtInst %void %1 DebugNoScope
2497fd4e5da5Sopenharmony_ci        %152 = OpLabel
2498fd4e5da5Sopenharmony_ci        %181 = OpExtInst %void %1 DebugScope %68 %155
2499fd4e5da5Sopenharmony_ci               OpBranch %137
2500fd4e5da5Sopenharmony_ci        %182 = OpExtInst %void %1 DebugNoScope
2501fd4e5da5Sopenharmony_ci        %153 = OpLabel
2502fd4e5da5Sopenharmony_ci        %183 = OpExtInst %void %1 DebugScope %68 %155
2503fd4e5da5Sopenharmony_ci               OpLine %7 11 10
2504fd4e5da5Sopenharmony_ci        %154 = OpLoad %v4float %121
2505fd4e5da5Sopenharmony_ci        %184 = OpExtInst %void %1 DebugScope %74
2506fd4e5da5Sopenharmony_ci        %167 = OpExtInst %void %1 DebugValue %75 %154 %77 %int_0
2507fd4e5da5Sopenharmony_ci        %166 = OpExtInst %void %1 DebugValue %75 %81 %77 %int_1
2508fd4e5da5Sopenharmony_ci               OpLine %7 19 10
2509fd4e5da5Sopenharmony_ci        %165 = OpCompositeConstruct %VS_OUTPUT %154 %81
2510fd4e5da5Sopenharmony_ci        %185 = OpExtInst %void %1 DebugNoScope
2511fd4e5da5Sopenharmony_ci         %83 = OpCompositeExtract %v4float %165 0
2512fd4e5da5Sopenharmony_ci               OpStore %gl_Position %83
2513fd4e5da5Sopenharmony_ci         %84 = OpCompositeExtract %v4float %165 1
2514fd4e5da5Sopenharmony_ci               OpStore %out_var_COLOR %84
2515fd4e5da5Sopenharmony_ci               OpReturn
2516fd4e5da5Sopenharmony_ci               OpFunctionEnd
2517fd4e5da5Sopenharmony_ci)";
2518fd4e5da5Sopenharmony_ci
2519fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
2520fd4e5da5Sopenharmony_ci}
2521fd4e5da5Sopenharmony_ci
2522fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DebugValueWithIndexesInForLoop) {
2523fd4e5da5Sopenharmony_ci  // #version 140
2524fd4e5da5Sopenharmony_ci  //
2525fd4e5da5Sopenharmony_ci  // in vec4 BC;
2526fd4e5da5Sopenharmony_ci  // out float fo;
2527fd4e5da5Sopenharmony_ci  //
2528fd4e5da5Sopenharmony_ci  // struct T {
2529fd4e5da5Sopenharmony_ci  //   float a;
2530fd4e5da5Sopenharmony_ci  //   float f;
2531fd4e5da5Sopenharmony_ci  // };
2532fd4e5da5Sopenharmony_ci  //
2533fd4e5da5Sopenharmony_ci  // struct value {
2534fd4e5da5Sopenharmony_ci  //   int x;
2535fd4e5da5Sopenharmony_ci  //   int y;
2536fd4e5da5Sopenharmony_ci  //   T z;
2537fd4e5da5Sopenharmony_ci  // };
2538fd4e5da5Sopenharmony_ci  //
2539fd4e5da5Sopenharmony_ci  // void main()
2540fd4e5da5Sopenharmony_ci  // {
2541fd4e5da5Sopenharmony_ci  //     value v;
2542fd4e5da5Sopenharmony_ci  //     v.z.f = 0.0;
2543fd4e5da5Sopenharmony_ci  //     for (int i=0; i<4; i++) {
2544fd4e5da5Sopenharmony_ci  //       v.z.f = v.z.f + BC[i];
2545fd4e5da5Sopenharmony_ci  //     }
2546fd4e5da5Sopenharmony_ci  //     fo = v.z.f;
2547fd4e5da5Sopenharmony_ci  // }
2548fd4e5da5Sopenharmony_ci
2549fd4e5da5Sopenharmony_ci  const std::string text = R"(
2550fd4e5da5Sopenharmony_ci; CHECK: [[f_name:%\w+]] = OpString "f"
2551fd4e5da5Sopenharmony_ci; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugLocalVariable [[f_name]]
2552fd4e5da5Sopenharmony_ci
2553fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f %float_0
2554fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0 [[null_expr:%\d+]] %int_2 %int_1
2555fd4e5da5Sopenharmony_ci
2556fd4e5da5Sopenharmony_ci; CHECK-NOT:  DebugDeclare
2557fd4e5da5Sopenharmony_ci
2558fd4e5da5Sopenharmony_ci; CHECK:      [[loop_head:%\w+]] = OpLabel
2559fd4e5da5Sopenharmony_ci; CHECK:      [[phi0:%\w+]] = OpPhi %float %float_0
2560fd4e5da5Sopenharmony_ci; CHECK:      OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[phi0]] [[null_expr]] %int_2 %int_1
2561fd4e5da5Sopenharmony_ci; CHECK:      OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
2562fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
2563fd4e5da5Sopenharmony_ci
2564fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[loop_body]] = OpLabel
2565fd4e5da5Sopenharmony_ci; CHECK:      OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
2566fd4e5da5Sopenharmony_ci
2567fd4e5da5Sopenharmony_ci; CHECK:      [[bb]] = OpLabel
2568fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f [[f_val:%\w+]]
2569fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_val]] [[null_expr]] %int_2 %int_1
2570fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_cont]]
2571fd4e5da5Sopenharmony_ci
2572fd4e5da5Sopenharmony_ci; CHECK: [[loop_cont]] = OpLabel
2573fd4e5da5Sopenharmony_ci; CHECK: OpBranch [[loop_head]]
2574fd4e5da5Sopenharmony_ci
2575fd4e5da5Sopenharmony_ci; CHECK: [[loop_merge]] = OpLabel
2576fd4e5da5Sopenharmony_ci
2577fd4e5da5Sopenharmony_ciOpCapability Shader
2578fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2579fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
2580fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2581fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
2582fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2583fd4e5da5Sopenharmony_ci%file_name = OpString "test"
2584fd4e5da5Sopenharmony_ciOpSource GLSL 140
2585fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2586fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2587fd4e5da5Sopenharmony_ci%f_name = OpString "f"
2588fd4e5da5Sopenharmony_ci%i_name = OpString "i"
2589fd4e5da5Sopenharmony_ciOpName %main "main"
2590fd4e5da5Sopenharmony_ciOpName %f "f"
2591fd4e5da5Sopenharmony_ciOpName %i "i"
2592fd4e5da5Sopenharmony_ciOpName %BC "BC"
2593fd4e5da5Sopenharmony_ciOpName %fo "fo"
2594fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2595fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
2596fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2597fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2598fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2599fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2600fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2601fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
2602fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2603fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2604fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
2605fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2606fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
2607fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
2608fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
2609fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
2610fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2611fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
2612fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2613fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
2614fd4e5da5Sopenharmony_ci%deref = OpExtInst %void %ext DebugOperation Deref
2615fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
2616fd4e5da5Sopenharmony_ci%deref_expr = OpExtInst %void %ext DebugExpression %deref
2617fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
2618fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
2619fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
2620fd4e5da5Sopenharmony_ci%dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
2621fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
2622fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
2623fd4e5da5Sopenharmony_ci%dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
2624fd4e5da5Sopenharmony_ci%dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
2625fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
2626fd4e5da5Sopenharmony_ci%22 = OpLabel
2627fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
2628fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
2629fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
2630fd4e5da5Sopenharmony_ciOpStore %f %float_0
2631fd4e5da5Sopenharmony_ciOpStore %i %int_0
2632fd4e5da5Sopenharmony_ci%decl0 = OpExtInst %void %ext DebugValue %dbg_f %f %deref_expr %int_2 %int_1
2633fd4e5da5Sopenharmony_ci%decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %i %null_expr
2634fd4e5da5Sopenharmony_ciOpBranch %23
2635fd4e5da5Sopenharmony_ci%23 = OpLabel
2636fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
2637fd4e5da5Sopenharmony_ciOpLoopMerge %24 %25 None
2638fd4e5da5Sopenharmony_ciOpBranch %26
2639fd4e5da5Sopenharmony_ci%26 = OpLabel
2640fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
2641fd4e5da5Sopenharmony_ci%27 = OpLoad %int %i
2642fd4e5da5Sopenharmony_ci%28 = OpSLessThan %bool %27 %int_4
2643fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %24
2644fd4e5da5Sopenharmony_ci%29 = OpLabel
2645fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
2646fd4e5da5Sopenharmony_ci%30 = OpLoad %float %f
2647fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
2648fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
2649fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
2650fd4e5da5Sopenharmony_ci%34 = OpFAdd %float %30 %33
2651fd4e5da5Sopenharmony_ciOpStore %f %34
2652fd4e5da5Sopenharmony_ciOpBranch %25
2653fd4e5da5Sopenharmony_ci%25 = OpLabel
2654fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
2655fd4e5da5Sopenharmony_ci%35 = OpLoad %int %i
2656fd4e5da5Sopenharmony_ci%36 = OpIAdd %int %35 %int_1
2657fd4e5da5Sopenharmony_ciOpStore %i %36
2658fd4e5da5Sopenharmony_ciOpBranch %23
2659fd4e5da5Sopenharmony_ci%24 = OpLabel
2660fd4e5da5Sopenharmony_ci%s5 = OpExtInst %void %ext DebugScope %dbg_main
2661fd4e5da5Sopenharmony_ci%37 = OpLoad %float %f
2662fd4e5da5Sopenharmony_ciOpStore %fo %37
2663fd4e5da5Sopenharmony_ciOpReturn
2664fd4e5da5Sopenharmony_ciOpFunctionEnd
2665fd4e5da5Sopenharmony_ci)";
2666fd4e5da5Sopenharmony_ci
2667fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
2668fd4e5da5Sopenharmony_ci}
2669fd4e5da5Sopenharmony_ci
2670fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, PartiallyKillDebugDeclare) {
2671fd4e5da5Sopenharmony_ci  // For a reference variable e.g., int i in the following example,
2672fd4e5da5Sopenharmony_ci  // we do not propagate DebugValue for a store or phi instruction
2673fd4e5da5Sopenharmony_ci  // out of the variable's scope. In that case, we should not remove
2674fd4e5da5Sopenharmony_ci  // DebugDeclare for the variable that we did not add its DebugValue.
2675fd4e5da5Sopenharmony_ci  //
2676fd4e5da5Sopenharmony_ci  // #version 140
2677fd4e5da5Sopenharmony_ci  //
2678fd4e5da5Sopenharmony_ci  // in vec4 BC;
2679fd4e5da5Sopenharmony_ci  // out float fo;
2680fd4e5da5Sopenharmony_ci  //
2681fd4e5da5Sopenharmony_ci  // int j;
2682fd4e5da5Sopenharmony_ci  // void main()
2683fd4e5da5Sopenharmony_ci  // {
2684fd4e5da5Sopenharmony_ci  //     float f = 0.0;
2685fd4e5da5Sopenharmony_ci  //     for (j=0; j<4; j++) {
2686fd4e5da5Sopenharmony_ci  //       int& i = j;
2687fd4e5da5Sopenharmony_ci  //       f = f + BC[i];
2688fd4e5da5Sopenharmony_ci  //     }
2689fd4e5da5Sopenharmony_ci  //     fo = f;
2690fd4e5da5Sopenharmony_ci  // }
2691fd4e5da5Sopenharmony_ci
2692fd4e5da5Sopenharmony_ci  const std::string text = R"(
2693fd4e5da5Sopenharmony_ci; CHECK: [[f_name:%\w+]] = OpString "f"
2694fd4e5da5Sopenharmony_ci; CHECK: [[i_name:%\w+]] = OpString "i"
2695fd4e5da5Sopenharmony_ci; CHECK: [[fn:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugFunction
2696fd4e5da5Sopenharmony_ci; CHECK: [[bb:%\w+]] = OpExtInst %void [[ext]] DebugLexicalBlock
2697fd4e5da5Sopenharmony_ci; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[f_name]] {{%\w+}} {{%\w+}} 0 0 [[fn]]
2698fd4e5da5Sopenharmony_ci; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]] {{%\w+}} {{%\w+}} 0 0 [[bb]]
2699fd4e5da5Sopenharmony_ci
2700fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f %float_0
2701fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0
2702fd4e5da5Sopenharmony_ci; CHECK-NOT:  DebugDeclare [[dbg_f]]
2703fd4e5da5Sopenharmony_ci; CHECK:      OpExtInst %void [[ext]] DebugDeclare [[dbg_i]] %j
2704fd4e5da5Sopenharmony_ci
2705fd4e5da5Sopenharmony_ciOpCapability Shader
2706fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2707fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
2708fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2709fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
2710fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2711fd4e5da5Sopenharmony_ci%file_name = OpString "test"
2712fd4e5da5Sopenharmony_ciOpSource GLSL 140
2713fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2714fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2715fd4e5da5Sopenharmony_ci%f_name = OpString "f"
2716fd4e5da5Sopenharmony_ci%i_name = OpString "i"
2717fd4e5da5Sopenharmony_ci%j_name = OpString "j"
2718fd4e5da5Sopenharmony_ciOpName %main "main"
2719fd4e5da5Sopenharmony_ciOpName %f "f"
2720fd4e5da5Sopenharmony_ciOpName %j "j"
2721fd4e5da5Sopenharmony_ciOpName %BC "BC"
2722fd4e5da5Sopenharmony_ciOpName %fo "fo"
2723fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2724fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
2725fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2726fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2727fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2728fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2729fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2730fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
2731fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2732fd4e5da5Sopenharmony_ci%_ptr_Private_int = OpTypePointer Private %int
2733fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2734fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
2735fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2736fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
2737fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
2738fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
2739fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
2740fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2741fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2742fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
2743fd4e5da5Sopenharmony_ci%j = OpVariable %_ptr_Private_int Private
2744fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
2745fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
2746fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
2747fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
2748fd4e5da5Sopenharmony_ci%dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
2749fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
2750fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
2751fd4e5da5Sopenharmony_ci%bb = OpExtInst %void %ext DebugLexicalBlock %src 0 0 %dbg_main
2752fd4e5da5Sopenharmony_ci%dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
2753fd4e5da5Sopenharmony_ci%dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 0 0 %bb FlagIsLocal
2754fd4e5da5Sopenharmony_ci%dbg_j = OpExtInst %void %ext DebugGlobalVariable %j_name %dbg_v4f %src 0 0 %dbg_main %j_name %j FlagIsPrivate
2755fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
2756fd4e5da5Sopenharmony_ci%22 = OpLabel
2757fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
2758fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
2759fd4e5da5Sopenharmony_ciOpStore %f %float_0
2760fd4e5da5Sopenharmony_ciOpStore %j %int_0
2761fd4e5da5Sopenharmony_ci%decl0 = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
2762fd4e5da5Sopenharmony_ciOpBranch %23
2763fd4e5da5Sopenharmony_ci%23 = OpLabel
2764fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
2765fd4e5da5Sopenharmony_ciOpLoopMerge %24 %25 None
2766fd4e5da5Sopenharmony_ciOpBranch %26
2767fd4e5da5Sopenharmony_ci%26 = OpLabel
2768fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
2769fd4e5da5Sopenharmony_ci%27 = OpLoad %int %j
2770fd4e5da5Sopenharmony_ci%28 = OpSLessThan %bool %27 %int_4
2771fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %24
2772fd4e5da5Sopenharmony_ci%29 = OpLabel
2773fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %bb
2774fd4e5da5Sopenharmony_ci%decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %j %null_expr
2775fd4e5da5Sopenharmony_ci%30 = OpLoad %float %f
2776fd4e5da5Sopenharmony_ci%31 = OpLoad %int %j
2777fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
2778fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
2779fd4e5da5Sopenharmony_ci%34 = OpFAdd %float %30 %33
2780fd4e5da5Sopenharmony_ciOpStore %f %34
2781fd4e5da5Sopenharmony_ciOpBranch %25
2782fd4e5da5Sopenharmony_ci%25 = OpLabel
2783fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
2784fd4e5da5Sopenharmony_ci%35 = OpLoad %int %j
2785fd4e5da5Sopenharmony_ci%36 = OpIAdd %int %35 %int_1
2786fd4e5da5Sopenharmony_ciOpStore %j %36
2787fd4e5da5Sopenharmony_ciOpBranch %23
2788fd4e5da5Sopenharmony_ci%24 = OpLabel
2789fd4e5da5Sopenharmony_ci%s5 = OpExtInst %void %ext DebugScope %dbg_main
2790fd4e5da5Sopenharmony_ci%37 = OpLoad %float %f
2791fd4e5da5Sopenharmony_ciOpStore %fo %37
2792fd4e5da5Sopenharmony_ciOpReturn
2793fd4e5da5Sopenharmony_ciOpFunctionEnd
2794fd4e5da5Sopenharmony_ci)";
2795fd4e5da5Sopenharmony_ci
2796fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
2797fd4e5da5Sopenharmony_ci}
2798fd4e5da5Sopenharmony_ci
2799fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DebugValueForReferenceVariable) {
2800fd4e5da5Sopenharmony_ci  // #version 140
2801fd4e5da5Sopenharmony_ci  //
2802fd4e5da5Sopenharmony_ci  // in vec4 BC;
2803fd4e5da5Sopenharmony_ci  // out float fo;
2804fd4e5da5Sopenharmony_ci  //
2805fd4e5da5Sopenharmony_ci  // void main()
2806fd4e5da5Sopenharmony_ci  // {
2807fd4e5da5Sopenharmony_ci  //     float f = 0.0;
2808fd4e5da5Sopenharmony_ci  //     float& x = f;
2809fd4e5da5Sopenharmony_ci  //     for (int i=0; i<4; i++) {
2810fd4e5da5Sopenharmony_ci  //       x = x + BC[i];
2811fd4e5da5Sopenharmony_ci  //     }
2812fd4e5da5Sopenharmony_ci  //     fo = f;
2813fd4e5da5Sopenharmony_ci  // }
2814fd4e5da5Sopenharmony_ci
2815fd4e5da5Sopenharmony_ci  const std::string text = R"(
2816fd4e5da5Sopenharmony_ci; CHECK: [[f_name:%\w+]] = OpString "f"
2817fd4e5da5Sopenharmony_ci; CHECK: [[i_name:%\w+]] = OpString "i"
2818fd4e5da5Sopenharmony_ci; CHECK: [[x_name:%\w+]] = OpString "x"
2819fd4e5da5Sopenharmony_ci; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugLocalVariable [[f_name]]
2820fd4e5da5Sopenharmony_ci; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]]
2821fd4e5da5Sopenharmony_ci; CHECK: [[dbg_x:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[x_name]]
2822fd4e5da5Sopenharmony_ci
2823fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f %float_0
2824fd4e5da5Sopenharmony_ci; CHECK-DAG:  OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0
2825fd4e5da5Sopenharmony_ci; CHECK-DAG:  OpExtInst %void [[ext]] DebugValue [[dbg_x]] %float_0
2826fd4e5da5Sopenharmony_ci; CHECK:      OpStore %i %int_0
2827fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] %int_0
2828fd4e5da5Sopenharmony_ci
2829fd4e5da5Sopenharmony_ci; CHECK-NOT:  DebugDeclare
2830fd4e5da5Sopenharmony_ci
2831fd4e5da5Sopenharmony_ci; CHECK:      [[loop_head:%\w+]] = OpLabel
2832fd4e5da5Sopenharmony_ci; CHECK:      [[phi0:%\w+]] = OpPhi %float %float_0
2833fd4e5da5Sopenharmony_ci; CHECK:      [[phi1:%\w+]] = OpPhi %int %int_0
2834fd4e5da5Sopenharmony_ci; CHECK-DAG:  OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[phi0]]
2835fd4e5da5Sopenharmony_ci; CHECK-DAG:  OpExtInst %void [[ext]] DebugValue [[dbg_x]] [[phi0]]
2836fd4e5da5Sopenharmony_ci; CHECK:      OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[phi1]]
2837fd4e5da5Sopenharmony_ci; CHECK:      OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
2838fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
2839fd4e5da5Sopenharmony_ci
2840fd4e5da5Sopenharmony_ci; CHECK:      [[loop_body]] = OpLabel
2841fd4e5da5Sopenharmony_ci; CHECK:      OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
2842fd4e5da5Sopenharmony_ci
2843fd4e5da5Sopenharmony_ci; CHECK:      [[bb]] = OpLabel
2844fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f [[f_val:%\w+]]
2845fd4e5da5Sopenharmony_ci; CHECK-DAG:  OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_val]]
2846fd4e5da5Sopenharmony_ci; CHECK-DAG:  OpExtInst %void [[ext]] DebugValue [[dbg_x]] [[f_val]]
2847fd4e5da5Sopenharmony_ci; CHECK:      OpBranch [[loop_cont]]
2848fd4e5da5Sopenharmony_ci
2849fd4e5da5Sopenharmony_ci; CHECK:      [[loop_cont]] = OpLabel
2850fd4e5da5Sopenharmony_ci; CHECK:      OpStore %i [[i_val:%\w+]]
2851fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[i_val]]
2852fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_head]]
2853fd4e5da5Sopenharmony_ci
2854fd4e5da5Sopenharmony_ci; CHECK:      [[loop_merge]] = OpLabel
2855fd4e5da5Sopenharmony_ci
2856fd4e5da5Sopenharmony_ciOpCapability Shader
2857fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2858fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
2859fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2860fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
2861fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2862fd4e5da5Sopenharmony_ci%file_name = OpString "test"
2863fd4e5da5Sopenharmony_ciOpSource GLSL 140
2864fd4e5da5Sopenharmony_ci%float_name = OpString "float"
2865fd4e5da5Sopenharmony_ci%main_name = OpString "main"
2866fd4e5da5Sopenharmony_ci%f_name = OpString "f"
2867fd4e5da5Sopenharmony_ci%i_name = OpString "i"
2868fd4e5da5Sopenharmony_ci%x_name = OpString "x"
2869fd4e5da5Sopenharmony_ciOpName %main "main"
2870fd4e5da5Sopenharmony_ciOpName %f "f"
2871fd4e5da5Sopenharmony_ciOpName %i "i"
2872fd4e5da5Sopenharmony_ciOpName %BC "BC"
2873fd4e5da5Sopenharmony_ciOpName %fo "fo"
2874fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2875fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
2876fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2877fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2878fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2879fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2880fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2881fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
2882fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2883fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2884fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
2885fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2886fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
2887fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
2888fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
2889fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
2890fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2891fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2892fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
2893fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
2894fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
2895fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
2896fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
2897fd4e5da5Sopenharmony_ci%dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
2898fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
2899fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
2900fd4e5da5Sopenharmony_ci%dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
2901fd4e5da5Sopenharmony_ci%dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 1 0 %dbg_main FlagIsLocal
2902fd4e5da5Sopenharmony_ci%dbg_x = OpExtInst %void %ext DebugLocalVariable %x_name %dbg_v4f %src 2 0 %dbg_main FlagIsLocal
2903fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
2904fd4e5da5Sopenharmony_ci%22 = OpLabel
2905fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
2906fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
2907fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
2908fd4e5da5Sopenharmony_ciOpStore %f %float_0
2909fd4e5da5Sopenharmony_ciOpStore %i %int_0
2910fd4e5da5Sopenharmony_ci%decl0 = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
2911fd4e5da5Sopenharmony_ci%decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %i %null_expr
2912fd4e5da5Sopenharmony_ci%decl2 = OpExtInst %void %ext DebugDeclare %dbg_x %f %null_expr
2913fd4e5da5Sopenharmony_ciOpBranch %23
2914fd4e5da5Sopenharmony_ci%23 = OpLabel
2915fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
2916fd4e5da5Sopenharmony_ciOpLoopMerge %24 %25 None
2917fd4e5da5Sopenharmony_ciOpBranch %26
2918fd4e5da5Sopenharmony_ci%26 = OpLabel
2919fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
2920fd4e5da5Sopenharmony_ci%27 = OpLoad %int %i
2921fd4e5da5Sopenharmony_ci%28 = OpSLessThan %bool %27 %int_4
2922fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %24
2923fd4e5da5Sopenharmony_ci%29 = OpLabel
2924fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
2925fd4e5da5Sopenharmony_ci%30 = OpLoad %float %f
2926fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
2927fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
2928fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
2929fd4e5da5Sopenharmony_ci%34 = OpFAdd %float %30 %33
2930fd4e5da5Sopenharmony_ciOpStore %f %34
2931fd4e5da5Sopenharmony_ciOpBranch %25
2932fd4e5da5Sopenharmony_ci%25 = OpLabel
2933fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
2934fd4e5da5Sopenharmony_ci%35 = OpLoad %int %i
2935fd4e5da5Sopenharmony_ci%36 = OpIAdd %int %35 %int_1
2936fd4e5da5Sopenharmony_ciOpStore %i %36
2937fd4e5da5Sopenharmony_ciOpBranch %23
2938fd4e5da5Sopenharmony_ci%24 = OpLabel
2939fd4e5da5Sopenharmony_ci%s5 = OpExtInst %void %ext DebugScope %dbg_main
2940fd4e5da5Sopenharmony_ci%37 = OpLoad %float %f
2941fd4e5da5Sopenharmony_ciOpStore %fo %37
2942fd4e5da5Sopenharmony_ciOpReturn
2943fd4e5da5Sopenharmony_ciOpFunctionEnd
2944fd4e5da5Sopenharmony_ci)";
2945fd4e5da5Sopenharmony_ci
2946fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
2947fd4e5da5Sopenharmony_ci}
2948fd4e5da5Sopenharmony_ci
2949fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DebugValueForReferenceVariableInBB) {
2950fd4e5da5Sopenharmony_ci  // #version 140
2951fd4e5da5Sopenharmony_ci  //
2952fd4e5da5Sopenharmony_ci  // in vec4 BC;
2953fd4e5da5Sopenharmony_ci  // out float fo;
2954fd4e5da5Sopenharmony_ci  //
2955fd4e5da5Sopenharmony_ci  // void main()
2956fd4e5da5Sopenharmony_ci  // {
2957fd4e5da5Sopenharmony_ci  //     float f = 0.0;
2958fd4e5da5Sopenharmony_ci  //     for (int i=0; i<4; i++) {
2959fd4e5da5Sopenharmony_ci  //       float& x = f;
2960fd4e5da5Sopenharmony_ci  //       x = x + BC[i];
2961fd4e5da5Sopenharmony_ci  //       {
2962fd4e5da5Sopenharmony_ci  //         x = x + BC[i];
2963fd4e5da5Sopenharmony_ci  //       }
2964fd4e5da5Sopenharmony_ci  //     }
2965fd4e5da5Sopenharmony_ci  //     fo = f;
2966fd4e5da5Sopenharmony_ci  // }
2967fd4e5da5Sopenharmony_ci
2968fd4e5da5Sopenharmony_ci  const std::string text = R"(
2969fd4e5da5Sopenharmony_ci; CHECK: [[f_name:%\w+]] = OpString "f"
2970fd4e5da5Sopenharmony_ci; CHECK: [[i_name:%\w+]] = OpString "i"
2971fd4e5da5Sopenharmony_ci; CHECK: [[x_name:%\w+]] = OpString "x"
2972fd4e5da5Sopenharmony_ci; CHECK: [[dbg_main:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugFunction
2973fd4e5da5Sopenharmony_ci; CHECK: [[dbg_bb:%\w+]] = OpExtInst %void [[ext]] DebugLexicalBlock
2974fd4e5da5Sopenharmony_ci; CHECK: [[dbg_bb_child:%\w+]] = OpExtInst %void [[ext]] DebugLexicalBlock
2975fd4e5da5Sopenharmony_ci; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[f_name]]
2976fd4e5da5Sopenharmony_ci; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]]
2977fd4e5da5Sopenharmony_ci; CHECK: [[dbg_x:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[x_name]]
2978fd4e5da5Sopenharmony_ci
2979fd4e5da5Sopenharmony_ci; CHECK:      OpExtInst %void [[ext]] DebugScope [[dbg_main]]
2980fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f %float_0
2981fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_x]] %float_0
2982fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %float_0
2983fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpStore %i %int_0
2984fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] %int_0
2985fd4e5da5Sopenharmony_ci
2986fd4e5da5Sopenharmony_ci; CHECK-NOT:  DebugDeclare
2987fd4e5da5Sopenharmony_ci
2988fd4e5da5Sopenharmony_ci; CHECK:      [[loop_head:%\w+]] = OpLabel
2989fd4e5da5Sopenharmony_ci; CHECK:      OpExtInst %void [[ext]] DebugScope [[dbg_main]]
2990fd4e5da5Sopenharmony_ci; CHECK:      [[phi0:%\w+]] = OpPhi %float %float_0
2991fd4e5da5Sopenharmony_ci; CHECK:      [[phi1:%\w+]] = OpPhi %int %int_0
2992fd4e5da5Sopenharmony_ci; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[phi0]]
2993fd4e5da5Sopenharmony_ci; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_x]] [[phi0]]
2994fd4e5da5Sopenharmony_ci; CHECK-DAG: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[phi1]]
2995fd4e5da5Sopenharmony_ci; CHECK:      OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
2996fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
2997fd4e5da5Sopenharmony_ci
2998fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[loop_body]] = OpLabel
2999fd4e5da5Sopenharmony_ci; CHECK:      OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
3000fd4e5da5Sopenharmony_ci
3001fd4e5da5Sopenharmony_ci; CHECK:      [[bb]] = OpLabel
3002fd4e5da5Sopenharmony_ci; CHECK:      OpExtInst %void [[ext]] DebugScope [[dbg_bb]]
3003fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f [[f_val:%\w+]]
3004fd4e5da5Sopenharmony_ci; CHECK-DAG:  OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_val]]
3005fd4e5da5Sopenharmony_ci; CHECK-DAG:  OpExtInst %void [[ext]] DebugValue [[dbg_x]] [[f_val]]
3006fd4e5da5Sopenharmony_ci; CHECK:      OpBranch [[bb_child:%\w+]]
3007fd4e5da5Sopenharmony_ci
3008fd4e5da5Sopenharmony_ci; CHECK:      [[bb_child]] = OpLabel
3009fd4e5da5Sopenharmony_ci; CHECK:      OpExtInst %void [[ext]] DebugScope [[dbg_bb_child]]
3010fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f [[new_f_val:%\w+]]
3011fd4e5da5Sopenharmony_ci; CHECK-DAG:  OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[new_f_val]]
3012fd4e5da5Sopenharmony_ci; CHECK-DAG:  OpExtInst %void [[ext]] DebugValue [[dbg_x]] [[new_f_val]]
3013fd4e5da5Sopenharmony_ci; CHECK:      OpBranch [[loop_cont]]
3014fd4e5da5Sopenharmony_ci
3015fd4e5da5Sopenharmony_ci; CHECK:      [[loop_cont]] = OpLabel
3016fd4e5da5Sopenharmony_ci; CHECK:      OpStore %i [[i_val:%\w+]]
3017fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[i_val]]
3018fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_head]]
3019fd4e5da5Sopenharmony_ci
3020fd4e5da5Sopenharmony_ci; CHECK:      [[loop_merge]] = OpLabel
3021fd4e5da5Sopenharmony_ci
3022fd4e5da5Sopenharmony_ciOpCapability Shader
3023fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3024fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
3025fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3026fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
3027fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3028fd4e5da5Sopenharmony_ci%file_name = OpString "test"
3029fd4e5da5Sopenharmony_ciOpSource GLSL 140
3030fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3031fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3032fd4e5da5Sopenharmony_ci%f_name = OpString "f"
3033fd4e5da5Sopenharmony_ci%i_name = OpString "i"
3034fd4e5da5Sopenharmony_ci%x_name = OpString "x"
3035fd4e5da5Sopenharmony_ciOpName %main "main"
3036fd4e5da5Sopenharmony_ciOpName %f "f"
3037fd4e5da5Sopenharmony_ciOpName %i "i"
3038fd4e5da5Sopenharmony_ciOpName %BC "BC"
3039fd4e5da5Sopenharmony_ciOpName %fo "fo"
3040fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3041fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
3042fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3043fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3044fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
3045fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3046fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3047fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
3048fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
3049fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3050fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
3051fd4e5da5Sopenharmony_ci%bool = OpTypeBool
3052fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3053fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
3054fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
3055fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
3056fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
3057fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
3058fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
3059fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
3060fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
3061fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
3062fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
3063fd4e5da5Sopenharmony_ci%dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
3064fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
3065fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
3066fd4e5da5Sopenharmony_ci%bb = OpExtInst %void %ext DebugLexicalBlock %src 0 0 %dbg_main
3067fd4e5da5Sopenharmony_ci%bb_child = OpExtInst %void %ext DebugLexicalBlock %src 1 0 %bb
3068fd4e5da5Sopenharmony_ci%dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
3069fd4e5da5Sopenharmony_ci%dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 1 0 %dbg_main FlagIsLocal
3070fd4e5da5Sopenharmony_ci%dbg_x = OpExtInst %void %ext DebugLocalVariable %x_name %dbg_v4f %src 2 0 %bb FlagIsLocal
3071fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
3072fd4e5da5Sopenharmony_ci%22 = OpLabel
3073fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
3074fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
3075fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
3076fd4e5da5Sopenharmony_ciOpStore %f %float_0
3077fd4e5da5Sopenharmony_ciOpStore %i %int_0
3078fd4e5da5Sopenharmony_ci%decl0 = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
3079fd4e5da5Sopenharmony_ci%decl1 = OpExtInst %void %ext DebugDeclare %dbg_i %i %null_expr
3080fd4e5da5Sopenharmony_ciOpBranch %23
3081fd4e5da5Sopenharmony_ci%23 = OpLabel
3082fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
3083fd4e5da5Sopenharmony_ciOpLoopMerge %24 %25 None
3084fd4e5da5Sopenharmony_ciOpBranch %26
3085fd4e5da5Sopenharmony_ci%26 = OpLabel
3086fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
3087fd4e5da5Sopenharmony_ci%27 = OpLoad %int %i
3088fd4e5da5Sopenharmony_ci%28 = OpSLessThan %bool %27 %int_4
3089fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %24
3090fd4e5da5Sopenharmony_ci%29 = OpLabel
3091fd4e5da5Sopenharmony_ci%scope = OpExtInst %void %ext DebugScope %bb
3092fd4e5da5Sopenharmony_ci%decl2 = OpExtInst %void %ext DebugDeclare %dbg_x %f %null_expr
3093fd4e5da5Sopenharmony_ci%30 = OpLoad %float %f
3094fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
3095fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
3096fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
3097fd4e5da5Sopenharmony_ci%34 = OpFAdd %float %30 %33
3098fd4e5da5Sopenharmony_ciOpStore %f %34
3099fd4e5da5Sopenharmony_ciOpBranch %38
3100fd4e5da5Sopenharmony_ci%38 = OpLabel
3101fd4e5da5Sopenharmony_ci%child_scope = OpExtInst %void %ext DebugScope %bb_child
3102fd4e5da5Sopenharmony_ci%39 = OpLoad %float %f
3103fd4e5da5Sopenharmony_ci%40 = OpFAdd %float %39 %33
3104fd4e5da5Sopenharmony_ciOpStore %f %40
3105fd4e5da5Sopenharmony_ciOpBranch %25
3106fd4e5da5Sopenharmony_ci%25 = OpLabel
3107fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
3108fd4e5da5Sopenharmony_ci%35 = OpLoad %int %i
3109fd4e5da5Sopenharmony_ci%36 = OpIAdd %int %35 %int_1
3110fd4e5da5Sopenharmony_ciOpStore %i %36
3111fd4e5da5Sopenharmony_ciOpBranch %23
3112fd4e5da5Sopenharmony_ci%24 = OpLabel
3113fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
3114fd4e5da5Sopenharmony_ci%37 = OpLoad %float %f
3115fd4e5da5Sopenharmony_ciOpStore %fo %37
3116fd4e5da5Sopenharmony_ciOpReturn
3117fd4e5da5Sopenharmony_ciOpFunctionEnd
3118fd4e5da5Sopenharmony_ci)";
3119fd4e5da5Sopenharmony_ci
3120fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
3121fd4e5da5Sopenharmony_ci}
3122fd4e5da5Sopenharmony_ci
3123fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DebugForLoopUseDebugValueInsteadOfDebugDeclare) {
3124fd4e5da5Sopenharmony_ci  // #version 140
3125fd4e5da5Sopenharmony_ci  //
3126fd4e5da5Sopenharmony_ci  // in vec4 BC;
3127fd4e5da5Sopenharmony_ci  // out float fo;
3128fd4e5da5Sopenharmony_ci  //
3129fd4e5da5Sopenharmony_ci  // struct S {
3130fd4e5da5Sopenharmony_ci  //     float f;
3131fd4e5da5Sopenharmony_ci  //     int i;
3132fd4e5da5Sopenharmony_ci  // };
3133fd4e5da5Sopenharmony_ci  //
3134fd4e5da5Sopenharmony_ci  // void main()
3135fd4e5da5Sopenharmony_ci  // {
3136fd4e5da5Sopenharmony_ci  //     S foo = {0.0, 0};
3137fd4e5da5Sopenharmony_ci  //     for (; foo.i<4; foo.i++) {
3138fd4e5da5Sopenharmony_ci  //       foo.f = foo.f + BC[foo.i];
3139fd4e5da5Sopenharmony_ci  //     }
3140fd4e5da5Sopenharmony_ci  //     fo = foo.f;
3141fd4e5da5Sopenharmony_ci  // }
3142fd4e5da5Sopenharmony_ci
3143fd4e5da5Sopenharmony_ci  const std::string text = R"(
3144fd4e5da5Sopenharmony_ci; CHECK: [[f_name:%\w+]] = OpString "f"
3145fd4e5da5Sopenharmony_ci; CHECK: [[empty_expr:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugExpression
3146fd4e5da5Sopenharmony_ci; CHECK: [[deref_op:%\w+]] = OpExtInst %void [[ext]] DebugOperation Deref
3147fd4e5da5Sopenharmony_ci; CHECK: [[deref:%\w+]] = OpExtInst %void [[ext]] DebugExpression [[deref_op]]
3148fd4e5da5Sopenharmony_ci; CHECK: [[dbg_foo:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[f_name]]
3149fd4e5da5Sopenharmony_ci
3150fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f %float_0
3151fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] %float_0 [[empty_expr]] %uint_0
3152fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpStore %i %int_0
3153fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] %int_0 [[empty_expr]] %uint_1
3154fd4e5da5Sopenharmony_ci
3155fd4e5da5Sopenharmony_ci; CHECK:      [[loop_head:%\w+]] = OpLabel
3156fd4e5da5Sopenharmony_ci; CHECK:      [[phi0:%\w+]] = OpPhi %float %float_0
3157fd4e5da5Sopenharmony_ci; CHECK:      [[phi1:%\w+]] = OpPhi %int %int_0
3158fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] [[phi0]] [[empty_expr]] %uint_0
3159fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] [[phi1]] [[empty_expr]] %uint_1
3160fd4e5da5Sopenharmony_ci; CHECK:      OpLoopMerge [[loop_merge:%\w+]] [[loop_cont:%\w+]] None
3161fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_body:%\w+]]
3162fd4e5da5Sopenharmony_ci
3163fd4e5da5Sopenharmony_ci; CHECK:      [[loop_body]] = OpLabel
3164fd4e5da5Sopenharmony_ci; CHECK:      OpBranchConditional {{%\w+}} [[bb:%\w+]] [[loop_merge]]
3165fd4e5da5Sopenharmony_ci
3166fd4e5da5Sopenharmony_ci; CHECK:      [[bb]] = OpLabel
3167fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f [[f_val:%\w+]]
3168fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] [[f_val]] [[empty_expr]] %uint_0
3169fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_cont]]
3170fd4e5da5Sopenharmony_ci
3171fd4e5da5Sopenharmony_ci; CHECK:      [[loop_cont]] = OpLabel
3172fd4e5da5Sopenharmony_ci; CHECK:      OpStore %i [[i_val:%\w+]]
3173fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_foo]] [[i_val]] [[empty_expr]] %uint_1
3174fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[loop_head]]
3175fd4e5da5Sopenharmony_ci
3176fd4e5da5Sopenharmony_ciOpCapability Shader
3177fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3178fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
3179fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3180fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
3181fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3182fd4e5da5Sopenharmony_ci%file_name = OpString "test"
3183fd4e5da5Sopenharmony_ciOpSource GLSL 140
3184fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3185fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3186fd4e5da5Sopenharmony_ci%f_name = OpString "f"
3187fd4e5da5Sopenharmony_ciOpName %main "main"
3188fd4e5da5Sopenharmony_ciOpName %f "f"
3189fd4e5da5Sopenharmony_ciOpName %i "i"
3190fd4e5da5Sopenharmony_ciOpName %BC "BC"
3191fd4e5da5Sopenharmony_ciOpName %fo "fo"
3192fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3193fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
3194fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3195fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3196fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
3197fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3198fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3199fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
3200fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
3201fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
3202fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
3203fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3204fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
3205fd4e5da5Sopenharmony_ci%bool = OpTypeBool
3206fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3207fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
3208fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
3209fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
3210fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
3211fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
3212fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
3213fd4e5da5Sopenharmony_ci%deref_op = OpExtInst %void %ext DebugOperation Deref
3214fd4e5da5Sopenharmony_ci%deref = OpExtInst %void %ext DebugExpression %deref_op
3215fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
3216fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
3217fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
3218fd4e5da5Sopenharmony_ci%dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
3219fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
3220fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
3221fd4e5da5Sopenharmony_ci%dbg_foo = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
3222fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
3223fd4e5da5Sopenharmony_ci%22 = OpLabel
3224fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
3225fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
3226fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
3227fd4e5da5Sopenharmony_ciOpStore %f %float_0
3228fd4e5da5Sopenharmony_ciOpStore %i %int_0
3229fd4e5da5Sopenharmony_ci%decl0 = OpExtInst %void %ext DebugValue %dbg_foo %f %deref %uint_0
3230fd4e5da5Sopenharmony_ci%decl1 = OpExtInst %void %ext DebugValue %dbg_foo %i %deref %uint_1
3231fd4e5da5Sopenharmony_ciOpBranch %23
3232fd4e5da5Sopenharmony_ci%23 = OpLabel
3233fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
3234fd4e5da5Sopenharmony_ciOpLoopMerge %24 %25 None
3235fd4e5da5Sopenharmony_ciOpBranch %26
3236fd4e5da5Sopenharmony_ci%26 = OpLabel
3237fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
3238fd4e5da5Sopenharmony_ci%27 = OpLoad %int %i
3239fd4e5da5Sopenharmony_ci%28 = OpSLessThan %bool %27 %int_4
3240fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %24
3241fd4e5da5Sopenharmony_ci%29 = OpLabel
3242fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
3243fd4e5da5Sopenharmony_ci%30 = OpLoad %float %f
3244fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
3245fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
3246fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
3247fd4e5da5Sopenharmony_ci%34 = OpFAdd %float %30 %33
3248fd4e5da5Sopenharmony_ciOpStore %f %34
3249fd4e5da5Sopenharmony_ciOpBranch %25
3250fd4e5da5Sopenharmony_ci%25 = OpLabel
3251fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
3252fd4e5da5Sopenharmony_ci%35 = OpLoad %int %i
3253fd4e5da5Sopenharmony_ci%36 = OpIAdd %int %35 %int_1
3254fd4e5da5Sopenharmony_ciOpStore %i %36
3255fd4e5da5Sopenharmony_ciOpBranch %23
3256fd4e5da5Sopenharmony_ci%24 = OpLabel
3257fd4e5da5Sopenharmony_ci%s5 = OpExtInst %void %ext DebugScope %dbg_main
3258fd4e5da5Sopenharmony_ci%37 = OpLoad %float %f
3259fd4e5da5Sopenharmony_ciOpStore %fo %37
3260fd4e5da5Sopenharmony_ciOpReturn
3261fd4e5da5Sopenharmony_ciOpFunctionEnd
3262fd4e5da5Sopenharmony_ci)";
3263fd4e5da5Sopenharmony_ci
3264fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
3265fd4e5da5Sopenharmony_ci}
3266fd4e5da5Sopenharmony_ci
3267fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DebugValueNotUsedForDebugDeclare) {
3268fd4e5da5Sopenharmony_ci  // #version 140
3269fd4e5da5Sopenharmony_ci  //
3270fd4e5da5Sopenharmony_ci  // in vec4 BC;
3271fd4e5da5Sopenharmony_ci  // out float fo;
3272fd4e5da5Sopenharmony_ci  //
3273fd4e5da5Sopenharmony_ci  // void main()
3274fd4e5da5Sopenharmony_ci  // {
3275fd4e5da5Sopenharmony_ci  //     float f = 0.0;
3276fd4e5da5Sopenharmony_ci  //     for (int i=0; i<4; i++) {
3277fd4e5da5Sopenharmony_ci  //       f = f + BC[i];
3278fd4e5da5Sopenharmony_ci  //     }
3279fd4e5da5Sopenharmony_ci  //     fo = f;
3280fd4e5da5Sopenharmony_ci  // }
3281fd4e5da5Sopenharmony_ci
3282fd4e5da5Sopenharmony_ci  const std::string text = R"(
3283fd4e5da5Sopenharmony_ci; CHECK: [[f_name:%\w+]] = OpString "f"
3284fd4e5da5Sopenharmony_ci; CHECK: [[i_name:%\w+]] = OpString "i"
3285fd4e5da5Sopenharmony_ci; CHECK: [[dbg_f:%\w+]] = OpExtInst %void [[ext:%\d+]] DebugLocalVariable [[f_name]]
3286fd4e5da5Sopenharmony_ci; CHECK: [[dbg_i:%\w+]] = OpExtInst %void [[ext]] DebugLocalVariable [[i_name]]
3287fd4e5da5Sopenharmony_ci
3288fd4e5da5Sopenharmony_ci; CHECK:      OpStore %f %float_0
3289fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpStore %i %int_0
3290fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_f]] %f
3291fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpExtInst %void [[ext]] DebugValue [[dbg_i]] %i
3292fd4e5da5Sopenharmony_ci
3293fd4e5da5Sopenharmony_ci; CHECK-NOT:  DebugValue
3294fd4e5da5Sopenharmony_ci; CHECK-NOT:  DebugDeclare
3295fd4e5da5Sopenharmony_ci
3296fd4e5da5Sopenharmony_ciOpCapability Shader
3297fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3298fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
3299fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3300fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
3301fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3302fd4e5da5Sopenharmony_ci%file_name = OpString "test"
3303fd4e5da5Sopenharmony_ciOpSource GLSL 140
3304fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3305fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3306fd4e5da5Sopenharmony_ci%f_name = OpString "f"
3307fd4e5da5Sopenharmony_ci%i_name = OpString "i"
3308fd4e5da5Sopenharmony_ciOpName %main "main"
3309fd4e5da5Sopenharmony_ciOpName %f "f"
3310fd4e5da5Sopenharmony_ciOpName %i "i"
3311fd4e5da5Sopenharmony_ciOpName %BC "BC"
3312fd4e5da5Sopenharmony_ciOpName %fo "fo"
3313fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3314fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
3315fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3316fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3317fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
3318fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3319fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3320fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
3321fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
3322fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3323fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
3324fd4e5da5Sopenharmony_ci%bool = OpTypeBool
3325fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3326fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
3327fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
3328fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
3329fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
3330fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
3331fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
3332fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
3333fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
3334fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
3335fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
3336fd4e5da5Sopenharmony_ci%dbg_v4f = OpExtInst %void %ext DebugTypeVector %dbg_tf 4
3337fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %dbg_v4f %dbg_v4f
3338fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
3339fd4e5da5Sopenharmony_ci%dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_v4f %src 0 0 %dbg_main FlagIsLocal
3340fd4e5da5Sopenharmony_ci%dbg_i = OpExtInst %void %ext DebugLocalVariable %i_name %dbg_v4f %src 1 0 %dbg_main FlagIsLocal
3341fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
3342fd4e5da5Sopenharmony_ci%22 = OpLabel
3343fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
3344fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
3345fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
3346fd4e5da5Sopenharmony_ciOpStore %f %float_0
3347fd4e5da5Sopenharmony_ciOpStore %i %int_0
3348fd4e5da5Sopenharmony_ci%decl0 = OpExtInst %void %ext DebugValue %dbg_f %f %null_expr
3349fd4e5da5Sopenharmony_ci%decl1 = OpExtInst %void %ext DebugValue %dbg_i %i %null_expr
3350fd4e5da5Sopenharmony_ciOpBranch %23
3351fd4e5da5Sopenharmony_ci%23 = OpLabel
3352fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
3353fd4e5da5Sopenharmony_ciOpLoopMerge %24 %25 None
3354fd4e5da5Sopenharmony_ciOpBranch %26
3355fd4e5da5Sopenharmony_ci%26 = OpLabel
3356fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
3357fd4e5da5Sopenharmony_ci%27 = OpLoad %int %i
3358fd4e5da5Sopenharmony_ci%28 = OpSLessThan %bool %27 %int_4
3359fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %24
3360fd4e5da5Sopenharmony_ci%29 = OpLabel
3361fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
3362fd4e5da5Sopenharmony_ci%30 = OpLoad %float %f
3363fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
3364fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
3365fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
3366fd4e5da5Sopenharmony_ci%34 = OpFAdd %float %30 %33
3367fd4e5da5Sopenharmony_ciOpStore %f %34
3368fd4e5da5Sopenharmony_ciOpBranch %25
3369fd4e5da5Sopenharmony_ci%25 = OpLabel
3370fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
3371fd4e5da5Sopenharmony_ci%35 = OpLoad %int %i
3372fd4e5da5Sopenharmony_ci%36 = OpIAdd %int %35 %int_1
3373fd4e5da5Sopenharmony_ciOpStore %i %36
3374fd4e5da5Sopenharmony_ciOpBranch %23
3375fd4e5da5Sopenharmony_ci%24 = OpLabel
3376fd4e5da5Sopenharmony_ci%s5 = OpExtInst %void %ext DebugScope %dbg_main
3377fd4e5da5Sopenharmony_ci%37 = OpLoad %float %f
3378fd4e5da5Sopenharmony_ciOpStore %fo %37
3379fd4e5da5Sopenharmony_ciOpReturn
3380fd4e5da5Sopenharmony_ciOpFunctionEnd
3381fd4e5da5Sopenharmony_ci)";
3382fd4e5da5Sopenharmony_ci
3383fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
3384fd4e5da5Sopenharmony_ci}
3385fd4e5da5Sopenharmony_ci
3386fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DebugNestedForLoop) {
3387fd4e5da5Sopenharmony_ci  const std::string text = R"(
3388fd4e5da5Sopenharmony_ci; CHECK: = OpFunction
3389fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[entry:%\w+]] = OpLabel
3390fd4e5da5Sopenharmony_ci; CHECK: OpStore %f %float_0
3391fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext:%\w+]] DebugValue [[dbg_f:%\w+]] %float_0
3392fd4e5da5Sopenharmony_ci
3393fd4e5da5Sopenharmony_ci; CHECK: [[outer_header:%\w+]] = OpLabel
3394fd4e5da5Sopenharmony_ci; CHECK: [[outer_f:%\w+]] = OpPhi %float %float_0 [[entry]] [[inner_f:%\w+]] [[outer_be:%\w+]]
3395fd4e5da5Sopenharmony_ci; CHECK: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[outer_f]]
3396fd4e5da5Sopenharmony_ci
3397fd4e5da5Sopenharmony_ci; CHECK: [[inner_pre_header:%\w+]] = OpLabel
3398fd4e5da5Sopenharmony_ci; CHECK: [[inner_header:%\w+]] = OpLabel
3399fd4e5da5Sopenharmony_ci; CHECK: [[inner_f]] = OpPhi %float [[outer_f]] [[inner_pre_header]] [[f_next:%\w+]] [[inner_be:%\w+]]
3400fd4e5da5Sopenharmony_ci; CHECK: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[inner_f]]
3401fd4e5da5Sopenharmony_ci
3402fd4e5da5Sopenharmony_ci; CHECK: [[inner_be]] = OpLabel
3403fd4e5da5Sopenharmony_ci; CHECK: [[f_next]] = OpFAdd %float [[inner_f]]
3404fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpStore %f [[f_next]]
3405fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_next]]
3406fd4e5da5Sopenharmony_ci
3407fd4e5da5Sopenharmony_ciOpCapability Shader
3408fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3409fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
3410fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3411fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
3412fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3413fd4e5da5Sopenharmony_ci%file_name = OpString "test"
3414fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3415fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3416fd4e5da5Sopenharmony_ci%f_name = OpString "f"
3417fd4e5da5Sopenharmony_ciOpSource GLSL 450
3418fd4e5da5Sopenharmony_ciOpName %main "main"
3419fd4e5da5Sopenharmony_ciOpName %f "f"
3420fd4e5da5Sopenharmony_ciOpName %i "i"
3421fd4e5da5Sopenharmony_ciOpName %j "j"
3422fd4e5da5Sopenharmony_ciOpName %BC "BC"
3423fd4e5da5Sopenharmony_ciOpName %fo "fo"
3424fd4e5da5Sopenharmony_ciOpDecorate %BC Location 0
3425fd4e5da5Sopenharmony_ciOpDecorate %fo Location 0
3426fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3427fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
3428fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3429fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3430fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
3431fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3432fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
3433fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3434fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
3435fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3436fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
3437fd4e5da5Sopenharmony_ci%bool = OpTypeBool
3438fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3439fd4e5da5Sopenharmony_ci%mat4v4float = OpTypeMatrix %v4float 4
3440fd4e5da5Sopenharmony_ci%_ptr_Input_mat4v4float = OpTypePointer Input %mat4v4float
3441fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_mat4v4float Input
3442fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
3443fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
3444fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
3445fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
3446fd4e5da5Sopenharmony_ci
3447fd4e5da5Sopenharmony_ci; Debug information
3448fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
3449fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
3450fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
3451fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
3452fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %void
3453fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
3454fd4e5da5Sopenharmony_ci%dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
3455fd4e5da5Sopenharmony_ci
3456fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
3457fd4e5da5Sopenharmony_ci%24 = OpLabel
3458fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
3459fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
3460fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
3461fd4e5da5Sopenharmony_ci%j = OpVariable %_ptr_Function_int Function
3462fd4e5da5Sopenharmony_ci
3463fd4e5da5Sopenharmony_ci; DebugDeclare
3464fd4e5da5Sopenharmony_ciOpStore %f %float_0
3465fd4e5da5Sopenharmony_ci%decl = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
3466fd4e5da5Sopenharmony_ci
3467fd4e5da5Sopenharmony_ciOpStore %i %int_0
3468fd4e5da5Sopenharmony_ciOpBranch %25
3469fd4e5da5Sopenharmony_ci%25 = OpLabel
3470fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
3471fd4e5da5Sopenharmony_ci%26 = OpLoad %int %i
3472fd4e5da5Sopenharmony_ci%27 = OpSLessThan %bool %26 %int_4
3473fd4e5da5Sopenharmony_ciOpLoopMerge %28 %29 None
3474fd4e5da5Sopenharmony_ciOpBranchConditional %27 %30 %28
3475fd4e5da5Sopenharmony_ci%30 = OpLabel
3476fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
3477fd4e5da5Sopenharmony_ciOpStore %j %int_0
3478fd4e5da5Sopenharmony_ciOpBranch %31
3479fd4e5da5Sopenharmony_ci%31 = OpLabel
3480fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
3481fd4e5da5Sopenharmony_ci%32 = OpLoad %int %j
3482fd4e5da5Sopenharmony_ci%33 = OpSLessThan %bool %32 %int_4
3483fd4e5da5Sopenharmony_ciOpLoopMerge %50 %34 None
3484fd4e5da5Sopenharmony_ciOpBranchConditional %33 %34 %50
3485fd4e5da5Sopenharmony_ci%34 = OpLabel
3486fd4e5da5Sopenharmony_ci%s5 = OpExtInst %void %ext DebugScope %dbg_main
3487fd4e5da5Sopenharmony_ci%35 = OpLoad %float %f
3488fd4e5da5Sopenharmony_ci%36 = OpLoad %int %i
3489fd4e5da5Sopenharmony_ci%37 = OpLoad %int %j
3490fd4e5da5Sopenharmony_ci%38 = OpAccessChain %_ptr_Input_float %BC %36 %37
3491fd4e5da5Sopenharmony_ci%39 = OpLoad %float %38
3492fd4e5da5Sopenharmony_ci%40 = OpFAdd %float %35 %39
3493fd4e5da5Sopenharmony_ciOpStore %f %40
3494fd4e5da5Sopenharmony_ci%41 = OpLoad %int %j
3495fd4e5da5Sopenharmony_ci%42 = OpIAdd %int %41 %int_1
3496fd4e5da5Sopenharmony_ciOpStore %j %42
3497fd4e5da5Sopenharmony_ciOpBranch %31
3498fd4e5da5Sopenharmony_ci%50 = OpLabel
3499fd4e5da5Sopenharmony_ci%s6 = OpExtInst %void %ext DebugScope %dbg_main
3500fd4e5da5Sopenharmony_ciOpBranch %29
3501fd4e5da5Sopenharmony_ci%29 = OpLabel
3502fd4e5da5Sopenharmony_ci%s7 = OpExtInst %void %ext DebugScope %dbg_main
3503fd4e5da5Sopenharmony_ci%43 = OpLoad %int %i
3504fd4e5da5Sopenharmony_ci%44 = OpIAdd %int %43 %int_1
3505fd4e5da5Sopenharmony_ciOpStore %i %44
3506fd4e5da5Sopenharmony_ciOpBranch %25
3507fd4e5da5Sopenharmony_ci%28 = OpLabel
3508fd4e5da5Sopenharmony_ci%s8 = OpExtInst %void %ext DebugScope %dbg_main
3509fd4e5da5Sopenharmony_ci%45 = OpLoad %float %f
3510fd4e5da5Sopenharmony_ciOpStore %fo %45
3511fd4e5da5Sopenharmony_ciOpReturn
3512fd4e5da5Sopenharmony_ciOpFunctionEnd
3513fd4e5da5Sopenharmony_ci)";
3514fd4e5da5Sopenharmony_ci
3515fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
3516fd4e5da5Sopenharmony_ci}
3517fd4e5da5Sopenharmony_ci
3518fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DebugForLoopWithContinue) {
3519fd4e5da5Sopenharmony_ci  const std::string text = R"(
3520fd4e5da5Sopenharmony_ci; CHECK: = OpFunction
3521fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[entry:%\w+]] = OpLabel
3522fd4e5da5Sopenharmony_ci; CHECK: OpStore %f %float_0
3523fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext:%\w+]] DebugValue [[dbg_f:%\w+]] %float_0
3524fd4e5da5Sopenharmony_ci
3525fd4e5da5Sopenharmony_ci; CHECK: [[outer_header:%\w+]] = OpLabel
3526fd4e5da5Sopenharmony_ci; CHECK: [[outer_f:%\w+]] = OpPhi %float %float_0 [[entry]] [[inner_f:%\w+]] [[cont:%\w+]]
3527fd4e5da5Sopenharmony_ci; CHECK: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[outer_f]]
3528fd4e5da5Sopenharmony_ci
3529fd4e5da5Sopenharmony_ci; CHECK: [[f_next:%\w+]] = OpFAdd %float [[outer_f]]
3530fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpStore %f [[f_next]]
3531fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[f_next]]
3532fd4e5da5Sopenharmony_ci
3533fd4e5da5Sopenharmony_ci; CHECK: [[cont]] = OpLabel
3534fd4e5da5Sopenharmony_ci; CHECK: [[inner_f]] = OpPhi %float [[outer_f]] {{%\d+}} [[f_next]] {{%\d+}}
3535fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f]] [[inner_f]]
3536fd4e5da5Sopenharmony_ci
3537fd4e5da5Sopenharmony_ciOpCapability Shader
3538fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3539fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
3540fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3541fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BC %fo
3542fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3543fd4e5da5Sopenharmony_ci%file_name = OpString "test"
3544fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3545fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3546fd4e5da5Sopenharmony_ci%f_name = OpString "f"
3547fd4e5da5Sopenharmony_ciOpSource GLSL 140
3548fd4e5da5Sopenharmony_ciOpName %main "main"
3549fd4e5da5Sopenharmony_ciOpName %f "f"
3550fd4e5da5Sopenharmony_ciOpName %i "i"
3551fd4e5da5Sopenharmony_ciOpName %t "t"
3552fd4e5da5Sopenharmony_ciOpName %BC "BC"
3553fd4e5da5Sopenharmony_ciOpName %fo "fo"
3554fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3555fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
3556fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3557fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3558fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
3559fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3560fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
3561fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3562fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
3563fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3564fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
3565fd4e5da5Sopenharmony_ci%bool = OpTypeBool
3566fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3567fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
3568fd4e5da5Sopenharmony_ci%BC = OpVariable %_ptr_Input_v4float Input
3569fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
3570fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
3571fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
3572fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
3573fd4e5da5Sopenharmony_ci
3574fd4e5da5Sopenharmony_ci; Debug information
3575fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
3576fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
3577fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
3578fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
3579fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %void
3580fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
3581fd4e5da5Sopenharmony_ci%dbg_f = OpExtInst %void %ext DebugLocalVariable %f_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
3582fd4e5da5Sopenharmony_ci
3583fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
3584fd4e5da5Sopenharmony_ci%23 = OpLabel
3585fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
3586fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
3587fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
3588fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
3589fd4e5da5Sopenharmony_ci
3590fd4e5da5Sopenharmony_ci; DebugDeclare
3591fd4e5da5Sopenharmony_ciOpStore %f %float_0
3592fd4e5da5Sopenharmony_ci%decl = OpExtInst %void %ext DebugDeclare %dbg_f %f %null_expr
3593fd4e5da5Sopenharmony_ci
3594fd4e5da5Sopenharmony_ciOpStore %i %int_0
3595fd4e5da5Sopenharmony_ciOpBranch %24
3596fd4e5da5Sopenharmony_ci%24 = OpLabel
3597fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
3598fd4e5da5Sopenharmony_ciOpLoopMerge %25 %26 None
3599fd4e5da5Sopenharmony_ciOpBranch %27
3600fd4e5da5Sopenharmony_ci%27 = OpLabel
3601fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
3602fd4e5da5Sopenharmony_ci%28 = OpLoad %int %i
3603fd4e5da5Sopenharmony_ci%29 = OpSLessThan %bool %28 %int_4
3604fd4e5da5Sopenharmony_ciOpBranchConditional %29 %30 %25
3605fd4e5da5Sopenharmony_ci%30 = OpLabel
3606fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
3607fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
3608fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Input_float %BC %31
3609fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
3610fd4e5da5Sopenharmony_ciOpStore %t %33
3611fd4e5da5Sopenharmony_ci%34 = OpLoad %float %t
3612fd4e5da5Sopenharmony_ci%35 = OpFOrdLessThan %bool %34 %float_0
3613fd4e5da5Sopenharmony_ciOpSelectionMerge %36 None
3614fd4e5da5Sopenharmony_ciOpBranchConditional %35 %37 %36
3615fd4e5da5Sopenharmony_ci%37 = OpLabel
3616fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
3617fd4e5da5Sopenharmony_ciOpBranch %26
3618fd4e5da5Sopenharmony_ci%36 = OpLabel
3619fd4e5da5Sopenharmony_ci%s5 = OpExtInst %void %ext DebugScope %dbg_main
3620fd4e5da5Sopenharmony_ci%38 = OpLoad %float %f
3621fd4e5da5Sopenharmony_ci%39 = OpLoad %float %t
3622fd4e5da5Sopenharmony_ci%40 = OpFAdd %float %38 %39
3623fd4e5da5Sopenharmony_ciOpStore %f %40
3624fd4e5da5Sopenharmony_ciOpBranch %26
3625fd4e5da5Sopenharmony_ci%26 = OpLabel
3626fd4e5da5Sopenharmony_ci%s6 = OpExtInst %void %ext DebugScope %dbg_main
3627fd4e5da5Sopenharmony_ci%41 = OpLoad %int %i
3628fd4e5da5Sopenharmony_ci%42 = OpIAdd %int %41 %int_1
3629fd4e5da5Sopenharmony_ciOpStore %i %42
3630fd4e5da5Sopenharmony_ciOpBranch %24
3631fd4e5da5Sopenharmony_ci%25 = OpLabel
3632fd4e5da5Sopenharmony_ci%s7 = OpExtInst %void %ext DebugScope %dbg_main
3633fd4e5da5Sopenharmony_ci%43 = OpLoad %float %f
3634fd4e5da5Sopenharmony_ciOpStore %fo %43
3635fd4e5da5Sopenharmony_ciOpReturn
3636fd4e5da5Sopenharmony_ciOpFunctionEnd
3637fd4e5da5Sopenharmony_ci)";
3638fd4e5da5Sopenharmony_ci
3639fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
3640fd4e5da5Sopenharmony_ci}
3641fd4e5da5Sopenharmony_ci
3642fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DebugIfElse) {
3643fd4e5da5Sopenharmony_ci  const std::string text = R"(
3644fd4e5da5Sopenharmony_ciOpCapability Shader
3645fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3646fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
3647fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3648fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %f %BaseColor %gl_FragColor
3649fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3650fd4e5da5Sopenharmony_ci%file_name = OpString "test"
3651fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3652fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3653fd4e5da5Sopenharmony_ci%v_name = OpString "v"
3654fd4e5da5Sopenharmony_ciOpSource GLSL 140
3655fd4e5da5Sopenharmony_ciOpName %main "main"
3656fd4e5da5Sopenharmony_ciOpName %f "f"
3657fd4e5da5Sopenharmony_ciOpName %v "v"
3658fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
3659fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
3660fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3661fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
3662fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3663fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
3664fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Input_float Input
3665fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
3666fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3667fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
3668fd4e5da5Sopenharmony_ci%bool = OpTypeBool
3669fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3670fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
3671fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
3672fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
3673fd4e5da5Sopenharmony_ci%float_0_5 = OpConstant %float 0.5
3674fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
3675fd4e5da5Sopenharmony_ci%18 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
3676fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
3677fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
3678fd4e5da5Sopenharmony_ci
3679fd4e5da5Sopenharmony_ci; Debug information
3680fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
3681fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
3682fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
3683fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
3684fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %void
3685fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
3686fd4e5da5Sopenharmony_ci%dbg_v = OpExtInst %void %ext DebugLocalVariable %v_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
3687fd4e5da5Sopenharmony_ci
3688fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
3689fd4e5da5Sopenharmony_ci%20 = OpLabel
3690fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
3691fd4e5da5Sopenharmony_ci
3692fd4e5da5Sopenharmony_ci; DebugDeclare
3693fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
3694fd4e5da5Sopenharmony_ci%decl = OpExtInst %void %ext DebugDeclare %dbg_v %v %null_expr
3695fd4e5da5Sopenharmony_ci
3696fd4e5da5Sopenharmony_ci%21 = OpLoad %float %f
3697fd4e5da5Sopenharmony_ci%22 = OpFOrdGreaterThanEqual %bool %21 %float_0
3698fd4e5da5Sopenharmony_ciOpSelectionMerge %23 None
3699fd4e5da5Sopenharmony_ciOpBranchConditional %22 %24 %25
3700fd4e5da5Sopenharmony_ci
3701fd4e5da5Sopenharmony_ci; CHECK: OpBranchConditional
3702fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[br0:%\w+]] = OpLabel
3703fd4e5da5Sopenharmony_ci; CHECK: OpStore %v [[v0:%\w+]]
3704fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext:%\w+]] DebugValue [[dbg_v:%\w+]] [[v0]]
3705fd4e5da5Sopenharmony_ci%24 = OpLabel
3706fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
3707fd4e5da5Sopenharmony_ci%26 = OpLoad %v4float %BaseColor
3708fd4e5da5Sopenharmony_ci%27 = OpVectorTimesScalar %v4float %26 %float_0_5
3709fd4e5da5Sopenharmony_ciOpStore %v %27
3710fd4e5da5Sopenharmony_ciOpBranch %23
3711fd4e5da5Sopenharmony_ci
3712fd4e5da5Sopenharmony_ci; CHECK: [[br1:%\w+]] = OpLabel
3713fd4e5da5Sopenharmony_ci; CHECK: OpStore %v [[v1:%\w+]]
3714fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[v1]]
3715fd4e5da5Sopenharmony_ci%25 = OpLabel
3716fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
3717fd4e5da5Sopenharmony_ci%28 = OpLoad %v4float %BaseColor
3718fd4e5da5Sopenharmony_ci%29 = OpFAdd %v4float %28 %18
3719fd4e5da5Sopenharmony_ciOpStore %v %29
3720fd4e5da5Sopenharmony_ciOpBranch %23
3721fd4e5da5Sopenharmony_ci
3722fd4e5da5Sopenharmony_ci; CHECK: [[phi:%\w+]] = OpPhi %v4float [[v0]] [[br0]] [[v1]] [[br1]]
3723fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[phi]]
3724fd4e5da5Sopenharmony_ci%23 = OpLabel
3725fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
3726fd4e5da5Sopenharmony_ci%30 = OpLoad %v4float %v
3727fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %30
3728fd4e5da5Sopenharmony_ciOpReturn
3729fd4e5da5Sopenharmony_ciOpFunctionEnd
3730fd4e5da5Sopenharmony_ci)";
3731fd4e5da5Sopenharmony_ci
3732fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
3733fd4e5da5Sopenharmony_ci}
3734fd4e5da5Sopenharmony_ci
3735fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DebugSwitch) {
3736fd4e5da5Sopenharmony_ci  const std::string text = R"(
3737fd4e5da5Sopenharmony_ciOpCapability Shader
3738fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3739fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
3740fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3741fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %f %gl_FragColor
3742fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3743fd4e5da5Sopenharmony_ci%file_name = OpString "test"
3744fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3745fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3746fd4e5da5Sopenharmony_ci%v_name = OpString "v"
3747fd4e5da5Sopenharmony_ciOpSource GLSL 140
3748fd4e5da5Sopenharmony_ciOpName %main "main"
3749fd4e5da5Sopenharmony_ciOpName %v "v"
3750fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
3751fd4e5da5Sopenharmony_ciOpName %i "i"
3752fd4e5da5Sopenharmony_ciOpName %f "f"
3753fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
3754fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3755fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
3756fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3757fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3758fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3759fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
3760fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
3761fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
3762fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
3763fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3764fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
3765fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
3766fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Input_float Input
3767fd4e5da5Sopenharmony_ci%float_0_25 = OpConstant %float 0.25
3768fd4e5da5Sopenharmony_ci%float_0_75 = OpConstant %float 0.75
3769fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
3770fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
3771fd4e5da5Sopenharmony_ci
3772fd4e5da5Sopenharmony_ci; Debug information
3773fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
3774fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
3775fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
3776fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
3777fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %void
3778fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
3779fd4e5da5Sopenharmony_ci%dbg_v = OpExtInst %void %ext DebugLocalVariable %v_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
3780fd4e5da5Sopenharmony_ci
3781fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
3782fd4e5da5Sopenharmony_ci%20 = OpLabel
3783fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
3784fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
3785fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
3786fd4e5da5Sopenharmony_ci%21 = OpLoad %v4float %BaseColor
3787fd4e5da5Sopenharmony_ci
3788fd4e5da5Sopenharmony_ci; DebugDeclare
3789fd4e5da5Sopenharmony_ciOpStore %v %21
3790fd4e5da5Sopenharmony_ci%decl = OpExtInst %void %ext DebugDeclare %dbg_v %v %null_expr
3791fd4e5da5Sopenharmony_ci
3792fd4e5da5Sopenharmony_ci; CHECK: %main = OpFunction %void None
3793fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[entry:%\w+]] = OpLabel
3794fd4e5da5Sopenharmony_ci; CHECK: OpStore %v [[v0:%\w+]]
3795fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext:%\w+]] DebugValue [[dbg_v:%\w+]] [[v0]]
3796fd4e5da5Sopenharmony_ci; CHECK: OpSwitch {{%\w+}} [[case0:%\w+]] 0 [[case1:%\w+]] 1 [[case2:%\w+]] 2 [[case3:%\w+]]
3797fd4e5da5Sopenharmony_ci; CHECK: OpStore %v [[v1:%\w+]]
3798fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[v1]]
3799fd4e5da5Sopenharmony_ci; CHECK: OpStore %v [[v2:%\w+]]
3800fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[v2]]
3801fd4e5da5Sopenharmony_ci; CHECK: [[phi0:%\w+]] = OpPhi %v4float [[v0]] [[entry]] [[v2]] [[case2]]
3802fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[phi0]]
3803fd4e5da5Sopenharmony_ci; CHECK: OpStore %v [[v3:%\w+]]
3804fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[v3]]
3805fd4e5da5Sopenharmony_ci; CHECK: [[phi1:%\w+]] = OpPhi %v4float [[v0]] [[case0]] [[v1]] [[case1]] [[v3]] [[case3]]
3806fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_v]] [[phi1]]
3807fd4e5da5Sopenharmony_ci
3808fd4e5da5Sopenharmony_ci%22 = OpLoad %float %f
3809fd4e5da5Sopenharmony_ci%23 = OpConvertFToS %int %22
3810fd4e5da5Sopenharmony_ciOpStore %i %23
3811fd4e5da5Sopenharmony_ci%24 = OpLoad %int %i
3812fd4e5da5Sopenharmony_ciOpSelectionMerge %25 None
3813fd4e5da5Sopenharmony_ciOpSwitch %24 %26 0 %27 1 %28 2 %29
3814fd4e5da5Sopenharmony_ci%26 = OpLabel
3815fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
3816fd4e5da5Sopenharmony_ciOpBranch %25
3817fd4e5da5Sopenharmony_ci%27 = OpLabel
3818fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
3819fd4e5da5Sopenharmony_ci%30 = OpLoad %v4float %v
3820fd4e5da5Sopenharmony_ci%31 = OpVectorTimesScalar %v4float %30 %float_0_25
3821fd4e5da5Sopenharmony_ciOpStore %v %31
3822fd4e5da5Sopenharmony_ciOpBranch %25
3823fd4e5da5Sopenharmony_ci%28 = OpLabel
3824fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
3825fd4e5da5Sopenharmony_ci%32 = OpLoad %v4float %v
3826fd4e5da5Sopenharmony_ci%33 = OpCompositeConstruct %v4float %float_0_25 %float_0_25 %float_0_25 %float_0_25
3827fd4e5da5Sopenharmony_ci%34 = OpFAdd %v4float %32 %33
3828fd4e5da5Sopenharmony_ciOpStore %v %34
3829fd4e5da5Sopenharmony_ciOpBranch %29
3830fd4e5da5Sopenharmony_ci%29 = OpLabel
3831fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
3832fd4e5da5Sopenharmony_ci%35 = OpLoad %v4float %v
3833fd4e5da5Sopenharmony_ci%36 = OpVectorTimesScalar %v4float %35 %float_0_75
3834fd4e5da5Sopenharmony_ciOpStore %v %36
3835fd4e5da5Sopenharmony_ciOpBranch %25
3836fd4e5da5Sopenharmony_ci%25 = OpLabel
3837fd4e5da5Sopenharmony_ci%s5 = OpExtInst %void %ext DebugScope %dbg_main
3838fd4e5da5Sopenharmony_ci%37 = OpLoad %v4float %v
3839fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %37
3840fd4e5da5Sopenharmony_ciOpReturn
3841fd4e5da5Sopenharmony_ciOpFunctionEnd
3842fd4e5da5Sopenharmony_ci)";
3843fd4e5da5Sopenharmony_ci
3844fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
3845fd4e5da5Sopenharmony_ci}
3846fd4e5da5Sopenharmony_ci
3847fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, DebugSwapProblem) {
3848fd4e5da5Sopenharmony_ci  // #version 140
3849fd4e5da5Sopenharmony_ci  //
3850fd4e5da5Sopenharmony_ci  // in float fe;
3851fd4e5da5Sopenharmony_ci  // out float fo;
3852fd4e5da5Sopenharmony_ci  //
3853fd4e5da5Sopenharmony_ci  // void main()
3854fd4e5da5Sopenharmony_ci  // {
3855fd4e5da5Sopenharmony_ci  //     float f1 = 0.0;
3856fd4e5da5Sopenharmony_ci  //     float f2 = 1.0;
3857fd4e5da5Sopenharmony_ci  //     int ie = int(fe);
3858fd4e5da5Sopenharmony_ci  //     for (int i=0; i<ie; i++) {
3859fd4e5da5Sopenharmony_ci  //       float t = f1;
3860fd4e5da5Sopenharmony_ci  //       f1 = f2;
3861fd4e5da5Sopenharmony_ci  //       f2 = t;
3862fd4e5da5Sopenharmony_ci  //     }
3863fd4e5da5Sopenharmony_ci  //     fo = f1;
3864fd4e5da5Sopenharmony_ci  // }
3865fd4e5da5Sopenharmony_ci  //
3866fd4e5da5Sopenharmony_ci  // Because of the swap in the for loop, it generates the following phi
3867fd4e5da5Sopenharmony_ci  // instructions:
3868fd4e5da5Sopenharmony_ci  //
3869fd4e5da5Sopenharmony_ci  // [[phi_f2]] = OpPhi %float %float_1 [[entry]] [[phi_f1]] ..
3870fd4e5da5Sopenharmony_ci  // [[phi_f1]] = OpPhi %float %float_0 [[entry]] [[phi_f2]] ..
3871fd4e5da5Sopenharmony_ci  //
3872fd4e5da5Sopenharmony_ci  // Since they are used as operands by each other, we want to clearly check
3873fd4e5da5Sopenharmony_ci  // what DebugValue we have to add for them.
3874fd4e5da5Sopenharmony_ci
3875fd4e5da5Sopenharmony_ci  const std::string text = R"(
3876fd4e5da5Sopenharmony_ciOpCapability Shader
3877fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3878fd4e5da5Sopenharmony_ci%ext = OpExtInstImport "OpenCL.DebugInfo.100"
3879fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3880fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %fe %fo
3881fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3882fd4e5da5Sopenharmony_ciOpSource GLSL 140
3883fd4e5da5Sopenharmony_ci%file_name = OpString "test"
3884fd4e5da5Sopenharmony_ci%float_name = OpString "float"
3885fd4e5da5Sopenharmony_ci%main_name = OpString "main"
3886fd4e5da5Sopenharmony_ci%t_name = OpString "t"
3887fd4e5da5Sopenharmony_ciOpName %main "main"
3888fd4e5da5Sopenharmony_ciOpName %f1 "f1"
3889fd4e5da5Sopenharmony_ciOpName %f2 "f2"
3890fd4e5da5Sopenharmony_ciOpName %ie "ie"
3891fd4e5da5Sopenharmony_ciOpName %fe "fe"
3892fd4e5da5Sopenharmony_ciOpName %i "i"
3893fd4e5da5Sopenharmony_ciOpName %t "t"
3894fd4e5da5Sopenharmony_ciOpName %fo "fo"
3895fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3896fd4e5da5Sopenharmony_ci%11 = OpTypeFunction %void
3897fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3898fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3899fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
3900fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
3901fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3902fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
3903fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
3904fd4e5da5Sopenharmony_ci%fe = OpVariable %_ptr_Input_float Input
3905fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3906fd4e5da5Sopenharmony_ci%bool = OpTypeBool
3907fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
3908fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3909fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
3910fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
3911fd4e5da5Sopenharmony_ci%fo = OpVariable %_ptr_Output_float Output
3912fd4e5da5Sopenharmony_ci
3913fd4e5da5Sopenharmony_ci; Debug information
3914fd4e5da5Sopenharmony_ci%null_expr = OpExtInst %void %ext DebugExpression
3915fd4e5da5Sopenharmony_ci%src = OpExtInst %void %ext DebugSource %file_name
3916fd4e5da5Sopenharmony_ci%cu = OpExtInst %void %ext DebugCompilationUnit 1 4 %src HLSL
3917fd4e5da5Sopenharmony_ci%dbg_tf = OpExtInst %void %ext DebugTypeBasic %float_name %uint_32 Float
3918fd4e5da5Sopenharmony_ci%main_ty = OpExtInst %void %ext DebugTypeFunction FlagIsProtected|FlagIsPrivate %void
3919fd4e5da5Sopenharmony_ci%dbg_main = OpExtInst %void %ext DebugFunction %main_name %main_ty %src 0 0 %cu %main_name FlagIsProtected|FlagIsPrivate 10 %main
3920fd4e5da5Sopenharmony_ci%dbg_f1 = OpExtInst %void %ext DebugLocalVariable %t_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
3921fd4e5da5Sopenharmony_ci%dbg_f2 = OpExtInst %void %ext DebugLocalVariable %t_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
3922fd4e5da5Sopenharmony_ci%dbg_i = OpExtInst %void %ext DebugLocalVariable %t_name %dbg_tf %src 0 0 %dbg_main FlagIsLocal
3923fd4e5da5Sopenharmony_ci
3924fd4e5da5Sopenharmony_ci%main = OpFunction %void None %11
3925fd4e5da5Sopenharmony_ci%23 = OpLabel
3926fd4e5da5Sopenharmony_ci%s0 = OpExtInst %void %ext DebugScope %dbg_main
3927fd4e5da5Sopenharmony_ci%f1 = OpVariable %_ptr_Function_float Function
3928fd4e5da5Sopenharmony_ci%f2 = OpVariable %_ptr_Function_float Function
3929fd4e5da5Sopenharmony_ci%ie = OpVariable %_ptr_Function_int Function
3930fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
3931fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
3932fd4e5da5Sopenharmony_ciOpStore %f1 %float_0
3933fd4e5da5Sopenharmony_ciOpStore %f2 %float_1
3934fd4e5da5Sopenharmony_ci%24 = OpLoad %float %fe
3935fd4e5da5Sopenharmony_ci%25 = OpConvertFToS %int %24
3936fd4e5da5Sopenharmony_ciOpStore %ie %25
3937fd4e5da5Sopenharmony_ciOpStore %i %int_0
3938fd4e5da5Sopenharmony_ci
3939fd4e5da5Sopenharmony_ci; DebugDeclare
3940fd4e5da5Sopenharmony_ci%decl0 = OpExtInst %void %ext DebugDeclare %dbg_f1 %f1 %null_expr
3941fd4e5da5Sopenharmony_ci%decl1 = OpExtInst %void %ext DebugDeclare %dbg_f2 %f2 %null_expr
3942fd4e5da5Sopenharmony_ci%decl2 = OpExtInst %void %ext DebugDeclare %dbg_i  %i  %null_expr
3943fd4e5da5Sopenharmony_ci
3944fd4e5da5Sopenharmony_ci; CHECK: %main = OpFunction %void None
3945fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[entry:%\w+]] = OpLabel
3946fd4e5da5Sopenharmony_ci
3947fd4e5da5Sopenharmony_ci; CHECK: OpStore %f1 %float_0
3948fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext:%\w+]] DebugValue [[dbg_f1:%\w+]] %float_0
3949fd4e5da5Sopenharmony_ci; CHECK: OpStore %f2 %float_1
3950fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f2:%\w+]] %float_1
3951fd4e5da5Sopenharmony_ci; CHECK: OpStore %i %int_0
3952fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_i:%\w+]] %int_0
3953fd4e5da5Sopenharmony_ci
3954fd4e5da5Sopenharmony_ci; CHECK: [[phi_f2:%\w+]] = OpPhi %float %float_1 [[entry]] [[phi_f1:%\w+]]
3955fd4e5da5Sopenharmony_ci; CHECK: [[phi_f1]] = OpPhi %float %float_0 [[entry]] [[phi_f2]]
3956fd4e5da5Sopenharmony_ci; CHECK: [[phi_i:%\w+]] = OpPhi %int %int_0 [[entry]]
3957fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f2]] [[phi_f2]]
3958fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_f1]] [[phi_f1]]
3959fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpExtInst %void [[ext]] DebugValue [[dbg_i]] [[phi_i]]
3960fd4e5da5Sopenharmony_ci
3961fd4e5da5Sopenharmony_ciOpBranch %26
3962fd4e5da5Sopenharmony_ci%26 = OpLabel
3963fd4e5da5Sopenharmony_ci%s1 = OpExtInst %void %ext DebugScope %dbg_main
3964fd4e5da5Sopenharmony_ciOpLoopMerge %27 %28 None
3965fd4e5da5Sopenharmony_ciOpBranch %29
3966fd4e5da5Sopenharmony_ci%29 = OpLabel
3967fd4e5da5Sopenharmony_ci%s2 = OpExtInst %void %ext DebugScope %dbg_main
3968fd4e5da5Sopenharmony_ci%30 = OpLoad %int %i
3969fd4e5da5Sopenharmony_ci%31 = OpLoad %int %ie
3970fd4e5da5Sopenharmony_ci%32 = OpSLessThan %bool %30 %31
3971fd4e5da5Sopenharmony_ciOpBranchConditional %32 %33 %27
3972fd4e5da5Sopenharmony_ci%33 = OpLabel
3973fd4e5da5Sopenharmony_ci%s3 = OpExtInst %void %ext DebugScope %dbg_main
3974fd4e5da5Sopenharmony_ci%34 = OpLoad %float %f1
3975fd4e5da5Sopenharmony_ciOpStore %t %34
3976fd4e5da5Sopenharmony_ci%35 = OpLoad %float %f2
3977fd4e5da5Sopenharmony_ciOpStore %f1 %35
3978fd4e5da5Sopenharmony_ci%36 = OpLoad %float %t
3979fd4e5da5Sopenharmony_ciOpStore %f2 %36
3980fd4e5da5Sopenharmony_ciOpBranch %28
3981fd4e5da5Sopenharmony_ci%28 = OpLabel
3982fd4e5da5Sopenharmony_ci%s4 = OpExtInst %void %ext DebugScope %dbg_main
3983fd4e5da5Sopenharmony_ci%37 = OpLoad %int %i
3984fd4e5da5Sopenharmony_ci%38 = OpIAdd %int %37 %int_1
3985fd4e5da5Sopenharmony_ciOpStore %i %38
3986fd4e5da5Sopenharmony_ciOpBranch %26
3987fd4e5da5Sopenharmony_ci%27 = OpLabel
3988fd4e5da5Sopenharmony_ci%s5 = OpExtInst %void %ext DebugScope %dbg_main
3989fd4e5da5Sopenharmony_ci%39 = OpLoad %float %f1
3990fd4e5da5Sopenharmony_ciOpStore %fo %39
3991fd4e5da5Sopenharmony_ciOpReturn
3992fd4e5da5Sopenharmony_ciOpFunctionEnd
3993fd4e5da5Sopenharmony_ci)";
3994fd4e5da5Sopenharmony_ci
3995fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
3996fd4e5da5Sopenharmony_ci}
3997fd4e5da5Sopenharmony_ci
3998fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, RemoveDebugDeclareWithoutLoads) {
3999fd4e5da5Sopenharmony_ci  // Check that the DebugDeclare for c is removed even though its loads
4000fd4e5da5Sopenharmony_ci  // had been removed previously by single block store/load optimization.
4001fd4e5da5Sopenharmony_ci  // In the presence of DebugDeclare, single-block can and does remove loads,
4002fd4e5da5Sopenharmony_ci  // but cannot change the stores into DebugValues and remove the DebugDeclare
4003fd4e5da5Sopenharmony_ci  // because it is only a per block optimization, not a function optimization.
4004fd4e5da5Sopenharmony_ci  // So SSA-rewrite must perform this role.
4005fd4e5da5Sopenharmony_ci  //
4006fd4e5da5Sopenharmony_ci  // Texture2D g_tColor;
4007fd4e5da5Sopenharmony_ci  // SamplerState g_sAniso;
4008fd4e5da5Sopenharmony_ci  //
4009fd4e5da5Sopenharmony_ci  // struct PS_INPUT
4010fd4e5da5Sopenharmony_ci  // {
4011fd4e5da5Sopenharmony_ci  //   float2 vTextureCoords2 : TEXCOORD2;
4012fd4e5da5Sopenharmony_ci  //   float2 vTextureCoords3 : TEXCOORD3;
4013fd4e5da5Sopenharmony_ci  // };
4014fd4e5da5Sopenharmony_ci  //
4015fd4e5da5Sopenharmony_ci  // struct PS_OUTPUT
4016fd4e5da5Sopenharmony_ci  // {
4017fd4e5da5Sopenharmony_ci  //   float4 vColor : SV_Target0;
4018fd4e5da5Sopenharmony_ci  // };
4019fd4e5da5Sopenharmony_ci  //
4020fd4e5da5Sopenharmony_ci  // PS_OUTPUT MainPs(PS_INPUT i)
4021fd4e5da5Sopenharmony_ci  // {
4022fd4e5da5Sopenharmony_ci  //   PS_OUTPUT ps_output;
4023fd4e5da5Sopenharmony_ci  //   float4 c;
4024fd4e5da5Sopenharmony_ci  //   c = g_tColor.Sample(g_sAniso, i.vTextureCoords2.xy);
4025fd4e5da5Sopenharmony_ci  //   c += g_tColor.Sample(g_sAniso, i.vTextureCoords3.xy);
4026fd4e5da5Sopenharmony_ci  //   ps_output.vColor = c;
4027fd4e5da5Sopenharmony_ci  //   return ps_output;
4028fd4e5da5Sopenharmony_ci  // }
4029fd4e5da5Sopenharmony_ci
4030fd4e5da5Sopenharmony_ci  const std::string text = R"(
4031fd4e5da5Sopenharmony_ci               OpCapability Shader
4032fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "OpenCL.DebugInfo.100"
4033fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
4034fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %g_sAniso %in_var_TEXCOORD2 %in_var_TEXCOORD3 %out_var_SV_Target0
4035fd4e5da5Sopenharmony_ci               OpExecutionMode %MainPs OriginUpperLeft
4036fd4e5da5Sopenharmony_ci         %22 = OpString "foo.frag"
4037fd4e5da5Sopenharmony_ci         %26 = OpString "PS_OUTPUT"
4038fd4e5da5Sopenharmony_ci         %30 = OpString "float"
4039fd4e5da5Sopenharmony_ci         %33 = OpString "vColor"
4040fd4e5da5Sopenharmony_ci         %35 = OpString "PS_INPUT"
4041fd4e5da5Sopenharmony_ci         %40 = OpString "vTextureCoords3"
4042fd4e5da5Sopenharmony_ci         %42 = OpString "vTextureCoords2"
4043fd4e5da5Sopenharmony_ci         %44 = OpString "@type.2d.image"
4044fd4e5da5Sopenharmony_ci         %45 = OpString "type.2d.image"
4045fd4e5da5Sopenharmony_ci         %47 = OpString "Texture2D.TemplateParam"
4046fd4e5da5Sopenharmony_ci         %51 = OpString "src.MainPs"
4047fd4e5da5Sopenharmony_ci         %55 = OpString "c"
4048fd4e5da5Sopenharmony_ci         %57 = OpString "ps_output"
4049fd4e5da5Sopenharmony_ci         %60 = OpString "i"
4050fd4e5da5Sopenharmony_ci         %62 = OpString "@type.sampler"
4051fd4e5da5Sopenharmony_ci         %63 = OpString "type.sampler"
4052fd4e5da5Sopenharmony_ci         %65 = OpString "g_sAniso"
4053fd4e5da5Sopenharmony_ci         %67 = OpString "g_tColor"
4054fd4e5da5Sopenharmony_ci               OpName %type_2d_image "type.2d.image"
4055fd4e5da5Sopenharmony_ci               OpName %g_tColor "g_tColor"
4056fd4e5da5Sopenharmony_ci               OpName %type_sampler "type.sampler"
4057fd4e5da5Sopenharmony_ci               OpName %g_sAniso "g_sAniso"
4058fd4e5da5Sopenharmony_ci               OpName %in_var_TEXCOORD2 "in.var.TEXCOORD2"
4059fd4e5da5Sopenharmony_ci               OpName %in_var_TEXCOORD3 "in.var.TEXCOORD3"
4060fd4e5da5Sopenharmony_ci               OpName %out_var_SV_Target0 "out.var.SV_Target0"
4061fd4e5da5Sopenharmony_ci               OpName %MainPs "MainPs"
4062fd4e5da5Sopenharmony_ci               OpName %PS_INPUT "PS_INPUT"
4063fd4e5da5Sopenharmony_ci               OpMemberName %PS_INPUT 0 "vTextureCoords2"
4064fd4e5da5Sopenharmony_ci               OpMemberName %PS_INPUT 1 "vTextureCoords3"
4065fd4e5da5Sopenharmony_ci               OpName %param_var_i "param.var.i"
4066fd4e5da5Sopenharmony_ci               OpName %PS_OUTPUT "PS_OUTPUT"
4067fd4e5da5Sopenharmony_ci               OpMemberName %PS_OUTPUT 0 "vColor"
4068fd4e5da5Sopenharmony_ci               OpName %type_sampled_image "type.sampled.image"
4069fd4e5da5Sopenharmony_ci               OpDecorate %in_var_TEXCOORD2 Location 0
4070fd4e5da5Sopenharmony_ci               OpDecorate %in_var_TEXCOORD3 Location 1
4071fd4e5da5Sopenharmony_ci               OpDecorate %out_var_SV_Target0 Location 0
4072fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor DescriptorSet 0
4073fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor Binding 0
4074fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso DescriptorSet 0
4075fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso Binding 1
4076fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
4077fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
4078fd4e5da5Sopenharmony_ci      %int_1 = OpConstant %int 1
4079fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
4080fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
4081fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
4082fd4e5da5Sopenharmony_ci%type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
4083fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
4084fd4e5da5Sopenharmony_ci%type_sampler = OpTypeSampler
4085fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %type_sampler
4086fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
4087fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
4088fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
4089fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
4090fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
4091fd4e5da5Sopenharmony_ci   %uint_128 = OpConstant %uint 128
4092fd4e5da5Sopenharmony_ci     %uint_0 = OpConstant %uint 0
4093fd4e5da5Sopenharmony_ci    %uint_64 = OpConstant %uint 64
4094fd4e5da5Sopenharmony_ci         %69 = OpTypeFunction %void
4095fd4e5da5Sopenharmony_ci   %PS_INPUT = OpTypeStruct %v2float %v2float
4096fd4e5da5Sopenharmony_ci%_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
4097fd4e5da5Sopenharmony_ci  %PS_OUTPUT = OpTypeStruct %v4float
4098fd4e5da5Sopenharmony_ci%_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
4099fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
4100fd4e5da5Sopenharmony_ci%_ptr_Function_v2float = OpTypePointer Function %v2float
4101fd4e5da5Sopenharmony_ci%type_sampled_image = OpTypeSampledImage %type_2d_image
4102fd4e5da5Sopenharmony_ci   %g_tColor = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
4103fd4e5da5Sopenharmony_ci   %g_sAniso = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
4104fd4e5da5Sopenharmony_ci%in_var_TEXCOORD2 = OpVariable %_ptr_Input_v2float Input
4105fd4e5da5Sopenharmony_ci%in_var_TEXCOORD3 = OpVariable %_ptr_Input_v2float Input
4106fd4e5da5Sopenharmony_ci%out_var_SV_Target0 = OpVariable %_ptr_Output_v4float Output
4107fd4e5da5Sopenharmony_ci         %43 = OpExtInst %void %1 DebugInfoNone
4108fd4e5da5Sopenharmony_ci         %59 = OpExtInst %void %1 DebugExpression
4109fd4e5da5Sopenharmony_ci         %24 = OpExtInst %void %1 DebugSource %22
4110fd4e5da5Sopenharmony_ci         %25 = OpExtInst %void %1 DebugCompilationUnit 1 4 %24 HLSL
4111fd4e5da5Sopenharmony_ci         %28 = OpExtInst %void %1 DebugTypeComposite %26 Structure %24 11 1 %25 %26 %uint_128 FlagIsProtected|FlagIsPrivate %29
4112fd4e5da5Sopenharmony_ci         %31 = OpExtInst %void %1 DebugTypeBasic %30 %uint_32 Float
4113fd4e5da5Sopenharmony_ci         %32 = OpExtInst %void %1 DebugTypeVector %31 4
4114fd4e5da5Sopenharmony_ci         %29 = OpExtInst %void %1 DebugTypeMember %33 %32 %24 13 5 %28 %uint_0 %uint_128 FlagIsProtected|FlagIsPrivate
4115fd4e5da5Sopenharmony_ci         %36 = OpExtInst %void %1 DebugTypeComposite %35 Structure %24 5 1 %25 %35 %uint_128 FlagIsProtected|FlagIsPrivate %37 %38
4116fd4e5da5Sopenharmony_ci         %39 = OpExtInst %void %1 DebugTypeVector %31 2
4117fd4e5da5Sopenharmony_ci         %38 = OpExtInst %void %1 DebugTypeMember %40 %39 %24 8 5 %36 %uint_64 %uint_64 FlagIsProtected|FlagIsPrivate
4118fd4e5da5Sopenharmony_ci         %37 = OpExtInst %void %1 DebugTypeMember %42 %39 %24 7 5 %36 %uint_0 %uint_64 FlagIsProtected|FlagIsPrivate
4119fd4e5da5Sopenharmony_ci         %46 = OpExtInst %void %1 DebugTypeComposite %44 Class %24 0 0 %25 %45 %43 FlagIsProtected|FlagIsPrivate
4120fd4e5da5Sopenharmony_ci         %50 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %28 %36
4121fd4e5da5Sopenharmony_ci         %52 = OpExtInst %void %1 DebugFunction %51 %50 %24 16 1 %25 %51 FlagIsProtected|FlagIsPrivate 17 %43
4122fd4e5da5Sopenharmony_ci         %54 = OpExtInst %void %1 DebugLexicalBlock %24 17 1 %52
4123fd4e5da5Sopenharmony_ci         %56 = OpExtInst %void %1 DebugLocalVariable %55 %32 %24 20 12 %54 FlagIsLocal
4124fd4e5da5Sopenharmony_ci         %58 = OpExtInst %void %1 DebugLocalVariable %57 %28 %24 18 15 %54 FlagIsLocal
4125fd4e5da5Sopenharmony_ci         %61 = OpExtInst %void %1 DebugLocalVariable %60 %36 %24 16 29 %52 FlagIsLocal 1
4126fd4e5da5Sopenharmony_ci         %64 = OpExtInst %void %1 DebugTypeComposite %62 Structure %24 0 0 %25 %63 %43 FlagIsProtected|FlagIsPrivate
4127fd4e5da5Sopenharmony_ci         %66 = OpExtInst %void %1 DebugGlobalVariable %65 %64 %24 3 14 %25 %65 %g_sAniso FlagIsDefinition
4128fd4e5da5Sopenharmony_ci         %68 = OpExtInst %void %1 DebugGlobalVariable %67 %46 %24 1 11 %25 %67 %g_tColor FlagIsDefinition
4129fd4e5da5Sopenharmony_ci     %MainPs = OpFunction %void None %69
4130fd4e5da5Sopenharmony_ci         %70 = OpLabel
4131fd4e5da5Sopenharmony_ci        %135 = OpExtInst %void %1 DebugScope %54
4132fd4e5da5Sopenharmony_ci        %111 = OpVariable %_ptr_Function_PS_OUTPUT Function
4133fd4e5da5Sopenharmony_ci        %112 = OpVariable %_ptr_Function_v4float Function
4134fd4e5da5Sopenharmony_ci        %136 = OpExtInst %void %1 DebugNoScope
4135fd4e5da5Sopenharmony_ci%param_var_i = OpVariable %_ptr_Function_PS_INPUT Function
4136fd4e5da5Sopenharmony_ci         %74 = OpLoad %v2float %in_var_TEXCOORD2
4137fd4e5da5Sopenharmony_ci         %75 = OpLoad %v2float %in_var_TEXCOORD3
4138fd4e5da5Sopenharmony_ci         %76 = OpCompositeConstruct %PS_INPUT %74 %75
4139fd4e5da5Sopenharmony_ci               OpStore %param_var_i %76
4140fd4e5da5Sopenharmony_ci        %137 = OpExtInst %void %1 DebugScope %52
4141fd4e5da5Sopenharmony_ci        %115 = OpExtInst %void %1 DebugDeclare %61 %param_var_i %59
4142fd4e5da5Sopenharmony_ci        %138 = OpExtInst %void %1 DebugScope %54
4143fd4e5da5Sopenharmony_ci        %116 = OpExtInst %void %1 DebugDeclare %58 %111 %59
4144fd4e5da5Sopenharmony_ci        %117 = OpExtInst %void %1 DebugDeclare %56 %112 %59
4145fd4e5da5Sopenharmony_ci;CHECK-NOT: %117 = OpExtInst %void %1 DebugDeclare %56 %112 %59
4146fd4e5da5Sopenharmony_ci               OpLine %22 21 9
4147fd4e5da5Sopenharmony_ci        %118 = OpLoad %type_2d_image %g_tColor
4148fd4e5da5Sopenharmony_ci               OpLine %22 21 29
4149fd4e5da5Sopenharmony_ci        %119 = OpLoad %type_sampler %g_sAniso
4150fd4e5da5Sopenharmony_ci               OpLine %22 21 40
4151fd4e5da5Sopenharmony_ci        %120 = OpAccessChain %_ptr_Function_v2float %param_var_i %int_0
4152fd4e5da5Sopenharmony_ci        %121 = OpLoad %v2float %120
4153fd4e5da5Sopenharmony_ci               OpLine %22 21 9
4154fd4e5da5Sopenharmony_ci        %122 = OpSampledImage %type_sampled_image %118 %119
4155fd4e5da5Sopenharmony_ci        %123 = OpImageSampleImplicitLod %v4float %122 %121 None
4156fd4e5da5Sopenharmony_ci               OpLine %22 21 5
4157fd4e5da5Sopenharmony_ci               OpStore %112 %123
4158fd4e5da5Sopenharmony_ci;CHECK: %140 = OpExtInst %void %1 DebugValue %56 %123 %59
4159fd4e5da5Sopenharmony_ci               OpLine %22 22 10
4160fd4e5da5Sopenharmony_ci        %124 = OpLoad %type_2d_image %g_tColor
4161fd4e5da5Sopenharmony_ci               OpLine %22 22 30
4162fd4e5da5Sopenharmony_ci        %125 = OpLoad %type_sampler %g_sAniso
4163fd4e5da5Sopenharmony_ci               OpLine %22 22 41
4164fd4e5da5Sopenharmony_ci        %126 = OpAccessChain %_ptr_Function_v2float %param_var_i %int_1
4165fd4e5da5Sopenharmony_ci        %127 = OpLoad %v2float %126
4166fd4e5da5Sopenharmony_ci               OpLine %22 22 10
4167fd4e5da5Sopenharmony_ci        %128 = OpSampledImage %type_sampled_image %124 %125
4168fd4e5da5Sopenharmony_ci        %129 = OpImageSampleImplicitLod %v4float %128 %127 None
4169fd4e5da5Sopenharmony_ci               OpLine %22 22 7
4170fd4e5da5Sopenharmony_ci        %131 = OpFAdd %v4float %123 %129
4171fd4e5da5Sopenharmony_ci               OpLine %22 22 5
4172fd4e5da5Sopenharmony_ci               OpStore %112 %131
4173fd4e5da5Sopenharmony_ci;CHECK: %141 = OpExtInst %void %1 DebugValue %56 %131 %59
4174fd4e5da5Sopenharmony_ci               OpLine %22 23 5
4175fd4e5da5Sopenharmony_ci        %133 = OpAccessChain %_ptr_Function_v4float %111 %int_0
4176fd4e5da5Sopenharmony_ci               OpStore %133 %131
4177fd4e5da5Sopenharmony_ci               OpLine %22 24 12
4178fd4e5da5Sopenharmony_ci        %134 = OpLoad %PS_OUTPUT %111
4179fd4e5da5Sopenharmony_ci        %139 = OpExtInst %void %1 DebugNoScope
4180fd4e5da5Sopenharmony_ci         %79 = OpCompositeExtract %v4float %134 0
4181fd4e5da5Sopenharmony_ci               OpStore %out_var_SV_Target0 %79
4182fd4e5da5Sopenharmony_ci               OpReturn
4183fd4e5da5Sopenharmony_ci               OpFunctionEnd
4184fd4e5da5Sopenharmony_ci)";
4185fd4e5da5Sopenharmony_ci
4186fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
4187fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
4188fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
4189fd4e5da5Sopenharmony_ci}
4190fd4e5da5Sopenharmony_ci
4191fd4e5da5Sopenharmony_ci// Check support for pointer variables. When pointer variables are used, the
4192fd4e5da5Sopenharmony_ci// computation of reaching definitions may need to follow pointer chains.
4193fd4e5da5Sopenharmony_ci// See https://github.com/KhronosGroup/SPIRV-Tools/issues/3873 for details.
4194fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, PointerVariables) {
4195fd4e5da5Sopenharmony_ci  const std::string text = R"(
4196fd4e5da5Sopenharmony_ci               OpCapability Shader
4197fd4e5da5Sopenharmony_ci               OpCapability VariablePointers
4198fd4e5da5Sopenharmony_ci               OpExtension "SPV_KHR_variable_pointers"
4199fd4e5da5Sopenharmony_ci               OpMemoryModel Logical Simple
4200fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %1 "main" %2 %3
4201fd4e5da5Sopenharmony_ci               OpExecutionMode %1 OriginUpperLeft
4202fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
4203fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
4204fd4e5da5Sopenharmony_ci          %6 = OpTypeFunction %void
4205fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
4206fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
4207fd4e5da5Sopenharmony_ci%_ptr_Function__ptr_Input_float = OpTypePointer Function %_ptr_Input_float
4208fd4e5da5Sopenharmony_ci          %2 = OpVariable %_ptr_Input_float Input
4209fd4e5da5Sopenharmony_ci          %3 = OpVariable %_ptr_Output_float Output
4210fd4e5da5Sopenharmony_ci          %1 = OpFunction %void None %6
4211fd4e5da5Sopenharmony_ci         %10 = OpLabel
4212fd4e5da5Sopenharmony_ci         %11 = OpVariable %_ptr_Function__ptr_Input_float Function
4213fd4e5da5Sopenharmony_ci               OpStore %11 %2
4214fd4e5da5Sopenharmony_ci
4215fd4e5da5Sopenharmony_ci; CHECK-NOT: %12 = OpLoad %_ptr_Input_float %11
4216fd4e5da5Sopenharmony_ci         %12 = OpLoad %_ptr_Input_float %11
4217fd4e5da5Sopenharmony_ci
4218fd4e5da5Sopenharmony_ci; CHECK: %13 = OpLoad %float %2
4219fd4e5da5Sopenharmony_ci         %13 = OpLoad %float %12
4220fd4e5da5Sopenharmony_ci
4221fd4e5da5Sopenharmony_ci               OpStore %3 %13
4222fd4e5da5Sopenharmony_ci               OpReturn
4223fd4e5da5Sopenharmony_ci               OpFunctionEnd
4224fd4e5da5Sopenharmony_ci)";
4225fd4e5da5Sopenharmony_ci
4226fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
4227fd4e5da5Sopenharmony_ci}
4228fd4e5da5Sopenharmony_ci
4229fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, FunctionDeclaration) {
4230fd4e5da5Sopenharmony_ci  // Make sure the pass works with a function declaration that is called.
4231fd4e5da5Sopenharmony_ci  const std::string text = R"(OpCapability Addresses
4232fd4e5da5Sopenharmony_ciOpCapability Linkage
4233fd4e5da5Sopenharmony_ciOpCapability Kernel
4234fd4e5da5Sopenharmony_ciOpCapability Int8
4235fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "OpenCL.std"
4236fd4e5da5Sopenharmony_ciOpMemoryModel Physical64 OpenCL
4237fd4e5da5Sopenharmony_ciOpEntryPoint Kernel %2 "_Z23julia__1166_kernel_77094Bool"
4238fd4e5da5Sopenharmony_ciOpExecutionMode %2 ContractionOff
4239fd4e5da5Sopenharmony_ciOpSource Unknown 0
4240fd4e5da5Sopenharmony_ciOpDecorate %3 LinkageAttributes "julia_error_7712" Import
4241fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4242fd4e5da5Sopenharmony_ci%5 = OpTypeFunction %void
4243fd4e5da5Sopenharmony_ci%3 = OpFunction %void None %5
4244fd4e5da5Sopenharmony_ciOpFunctionEnd
4245fd4e5da5Sopenharmony_ci%2 = OpFunction %void None %5
4246fd4e5da5Sopenharmony_ci%6 = OpLabel
4247fd4e5da5Sopenharmony_ci%7 = OpFunctionCall %void %3
4248fd4e5da5Sopenharmony_ciOpReturn
4249fd4e5da5Sopenharmony_ciOpFunctionEnd
4250fd4e5da5Sopenharmony_ci)";
4251fd4e5da5Sopenharmony_ci
4252fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<SSARewritePass>(text, text, false);
4253fd4e5da5Sopenharmony_ci}
4254fd4e5da5Sopenharmony_ci
4255fd4e5da5Sopenharmony_ciTEST_F(LocalSSAElimTest, MissingDebugValue) {
4256fd4e5da5Sopenharmony_ci  // Make sure DebugValue for final fragcolor assignment is generated.
4257fd4e5da5Sopenharmony_ci
4258fd4e5da5Sopenharmony_ci  const std::string text =
4259fd4e5da5Sopenharmony_ci      R"(
4260fd4e5da5Sopenharmony_ci               OpCapability Shader
4261fd4e5da5Sopenharmony_ci               OpCapability ImageQuery
4262fd4e5da5Sopenharmony_ci               OpExtension "SPV_KHR_non_semantic_info"
4263fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
4264fd4e5da5Sopenharmony_ci          %2 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
4265fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
4266fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %main "main" %in_var_TEXCOORD0 %out_var_SV_TARGET %textureposition %samplerposition %textureNormal %samplerNormal %textureAlbedo %samplerAlbedo %textureShadowMap %samplerShadowMap %ubo
4267fd4e5da5Sopenharmony_ci               OpExecutionMode %main OriginUpperLeft
4268fd4e5da5Sopenharmony_ci         %15 = OpString "d2.frag"
4269fd4e5da5Sopenharmony_ci         %55 = OpString "float"
4270fd4e5da5Sopenharmony_ci         %63 = OpString "// Copyright 2020 Google LLC
4271fd4e5da5Sopenharmony_ci
4272fd4e5da5Sopenharmony_ciTexture2D textureposition : register(t1);
4273fd4e5da5Sopenharmony_ciSamplerState samplerposition : register(s1);
4274fd4e5da5Sopenharmony_ciTexture2D textureNormal : register(t2);
4275fd4e5da5Sopenharmony_ciSamplerState samplerNormal : register(s2);
4276fd4e5da5Sopenharmony_ciTexture2D textureAlbedo : register(t3);
4277fd4e5da5Sopenharmony_ciSamplerState samplerAlbedo : register(s3);
4278fd4e5da5Sopenharmony_ci// Depth from the light's point of view
4279fd4e5da5Sopenharmony_ci//layout (binding = 5) uniform sampler2DShadow samplerShadowMap;
4280fd4e5da5Sopenharmony_ciTexture2DArray textureShadowMap : register(t5);
4281fd4e5da5Sopenharmony_ciSamplerState samplerShadowMap : register(s5);
4282fd4e5da5Sopenharmony_ci
4283fd4e5da5Sopenharmony_ci#define LIGHT_COUNT 3
4284fd4e5da5Sopenharmony_ci#define SHADOW_FACTOR 0.25
4285fd4e5da5Sopenharmony_ci#define AMBIENT_LIGHT 0.1
4286fd4e5da5Sopenharmony_ci#define USE_PCF
4287fd4e5da5Sopenharmony_ci
4288fd4e5da5Sopenharmony_cistruct Light
4289fd4e5da5Sopenharmony_ci{
4290fd4e5da5Sopenharmony_ci	float4 position;
4291fd4e5da5Sopenharmony_ci	float4 target;
4292fd4e5da5Sopenharmony_ci	float4 color;
4293fd4e5da5Sopenharmony_ci	float4x4 viewMatrix;
4294fd4e5da5Sopenharmony_ci};
4295fd4e5da5Sopenharmony_ci
4296fd4e5da5Sopenharmony_cistruct UBO
4297fd4e5da5Sopenharmony_ci{
4298fd4e5da5Sopenharmony_ci	float4 viewPos;
4299fd4e5da5Sopenharmony_ci	Light lights[LIGHT_COUNT];
4300fd4e5da5Sopenharmony_ci	int useShadows;
4301fd4e5da5Sopenharmony_ci	int displayDebugTarget;
4302fd4e5da5Sopenharmony_ci};
4303fd4e5da5Sopenharmony_ci
4304fd4e5da5Sopenharmony_cicbuffer ubo : register(b4) { UBO ubo; }
4305fd4e5da5Sopenharmony_ci
4306fd4e5da5Sopenharmony_cifloat textureProj(float4 P, float layer, float2 offset)
4307fd4e5da5Sopenharmony_ci{
4308fd4e5da5Sopenharmony_ci	float shadow = 1.0;
4309fd4e5da5Sopenharmony_ci	float4 shadowCoord = P / P.w;
4310fd4e5da5Sopenharmony_ci	shadowCoord.xy = shadowCoord.xy * 0.5 + 0.5;
4311fd4e5da5Sopenharmony_ci
4312fd4e5da5Sopenharmony_ci	if (shadowCoord.z > -1.0 && shadowCoord.z < 1.0)
4313fd4e5da5Sopenharmony_ci	{
4314fd4e5da5Sopenharmony_ci		float dist = textureShadowMap.Sample(samplerShadowMap, float3(shadowCoord.xy + offset, layer)).r;
4315fd4e5da5Sopenharmony_ci		if (shadowCoord.w > 0.0 && dist < shadowCoord.z)
4316fd4e5da5Sopenharmony_ci		{
4317fd4e5da5Sopenharmony_ci			shadow = SHADOW_FACTOR;
4318fd4e5da5Sopenharmony_ci		}
4319fd4e5da5Sopenharmony_ci	}
4320fd4e5da5Sopenharmony_ci	return shadow;
4321fd4e5da5Sopenharmony_ci}
4322fd4e5da5Sopenharmony_ci
4323fd4e5da5Sopenharmony_cifloat filterPCF(float4 sc, float layer)
4324fd4e5da5Sopenharmony_ci{
4325fd4e5da5Sopenharmony_ci	int2 texDim; int elements; int levels;
4326fd4e5da5Sopenharmony_ci	textureShadowMap.GetDimensions(0, texDim.x, texDim.y, elements, levels);
4327fd4e5da5Sopenharmony_ci	float scale = 1.5;
4328fd4e5da5Sopenharmony_ci	float dx = scale * 1.0 / float(texDim.x);
4329fd4e5da5Sopenharmony_ci	float dy = scale * 1.0 / float(texDim.y);
4330fd4e5da5Sopenharmony_ci
4331fd4e5da5Sopenharmony_ci	float shadowFactor = 0.0;
4332fd4e5da5Sopenharmony_ci	int count = 0;
4333fd4e5da5Sopenharmony_ci	int range = 1;
4334fd4e5da5Sopenharmony_ci
4335fd4e5da5Sopenharmony_ci	for (int x = -range; x <= range; x++)
4336fd4e5da5Sopenharmony_ci	{
4337fd4e5da5Sopenharmony_ci		for (int y = -range; y <= range; y++)
4338fd4e5da5Sopenharmony_ci		{
4339fd4e5da5Sopenharmony_ci			shadowFactor += textureProj(sc, layer, float2(dx*x, dy*y));
4340fd4e5da5Sopenharmony_ci			count++;
4341fd4e5da5Sopenharmony_ci		}
4342fd4e5da5Sopenharmony_ci
4343fd4e5da5Sopenharmony_ci	}
4344fd4e5da5Sopenharmony_ci	return shadowFactor / count;
4345fd4e5da5Sopenharmony_ci}
4346fd4e5da5Sopenharmony_ci
4347fd4e5da5Sopenharmony_cifloat3 shadow(float3 fragcolor, float3 fragPos) {
4348fd4e5da5Sopenharmony_ci	for (int i = 0; i < LIGHT_COUNT; ++i)
4349fd4e5da5Sopenharmony_ci	{
4350fd4e5da5Sopenharmony_ci		float4 shadowClip = mul(ubo.lights[i].viewMatrix, float4(fragPos.xyz, 1.0));
4351fd4e5da5Sopenharmony_ci
4352fd4e5da5Sopenharmony_ci		float shadowFactor;
4353fd4e5da5Sopenharmony_ci		#ifdef USE_PCF
4354fd4e5da5Sopenharmony_ci			shadowFactor= filterPCF(shadowClip, i);
4355fd4e5da5Sopenharmony_ci		#else
4356fd4e5da5Sopenharmony_ci			shadowFactor = textureProj(shadowClip, i, float2(0.0, 0.0));
4357fd4e5da5Sopenharmony_ci		#endif
4358fd4e5da5Sopenharmony_ci
4359fd4e5da5Sopenharmony_ci		fragcolor *= shadowFactor;
4360fd4e5da5Sopenharmony_ci	}
4361fd4e5da5Sopenharmony_ci	return fragcolor;
4362fd4e5da5Sopenharmony_ci}
4363fd4e5da5Sopenharmony_ci
4364fd4e5da5Sopenharmony_cifloat4 main([[vk::location(0)]] float2 inUV : TEXCOORD0) : SV_TARGET
4365fd4e5da5Sopenharmony_ci{
4366fd4e5da5Sopenharmony_ci	// Get G-Buffer values
4367fd4e5da5Sopenharmony_ci	float3 fragPos = textureposition.Sample(samplerposition, inUV).rgb;
4368fd4e5da5Sopenharmony_ci	float3 normal = textureNormal.Sample(samplerNormal, inUV).rgb;
4369fd4e5da5Sopenharmony_ci	float4 albedo = textureAlbedo.Sample(samplerAlbedo, inUV);
4370fd4e5da5Sopenharmony_ci
4371fd4e5da5Sopenharmony_ci	// Ambient part
4372fd4e5da5Sopenharmony_ci	float3 fragcolor  = albedo.rgb * AMBIENT_LIGHT;
4373fd4e5da5Sopenharmony_ci
4374fd4e5da5Sopenharmony_ci	float3 N = normalize(normal);
4375fd4e5da5Sopenharmony_ci
4376fd4e5da5Sopenharmony_ci	for(int i = 0; i < LIGHT_COUNT; ++i)
4377fd4e5da5Sopenharmony_ci	{
4378fd4e5da5Sopenharmony_ci		// Vector to light
4379fd4e5da5Sopenharmony_ci		float3 L = ubo.lights[i].position.xyz - fragPos;
4380fd4e5da5Sopenharmony_ci		// Distance from light to fragment position
4381fd4e5da5Sopenharmony_ci		float dist = length(L);
4382fd4e5da5Sopenharmony_ci		L = normalize(L);
4383fd4e5da5Sopenharmony_ci
4384fd4e5da5Sopenharmony_ci		// Viewer to fragment
4385fd4e5da5Sopenharmony_ci		float3 V = ubo.viewPos.xyz - fragPos;
4386fd4e5da5Sopenharmony_ci		V = normalize(V);
4387fd4e5da5Sopenharmony_ci
4388fd4e5da5Sopenharmony_ci		float lightCosInnerAngle = cos(radians(15.0));
4389fd4e5da5Sopenharmony_ci		float lightCosOuterAngle = cos(radians(25.0));
4390fd4e5da5Sopenharmony_ci		float lightRange = 100.0;
4391fd4e5da5Sopenharmony_ci
4392fd4e5da5Sopenharmony_ci		// Direction vector from source to target
4393fd4e5da5Sopenharmony_ci		float3 dir = normalize(ubo.lights[i].position.xyz - ubo.lights[i].target.xyz);
4394fd4e5da5Sopenharmony_ci
4395fd4e5da5Sopenharmony_ci		// Dual cone spot light with smooth transition between inner and outer angle
4396fd4e5da5Sopenharmony_ci		float cosDir = dot(L, dir);
4397fd4e5da5Sopenharmony_ci		float spotEffect = smoothstep(lightCosOuterAngle, lightCosInnerAngle, cosDir);
4398fd4e5da5Sopenharmony_ci		float heightAttenuation = smoothstep(lightRange, 0.0f, dist);
4399fd4e5da5Sopenharmony_ci
4400fd4e5da5Sopenharmony_ci		// Diffuse lighting
4401fd4e5da5Sopenharmony_ci		float NdotL = max(0.0, dot(N, L));
4402fd4e5da5Sopenharmony_ci		float3 diff = NdotL.xxx;
4403fd4e5da5Sopenharmony_ci
4404fd4e5da5Sopenharmony_ci		// Specular lighting
4405fd4e5da5Sopenharmony_ci		float3 R = reflect(-L, N);
4406fd4e5da5Sopenharmony_ci		float NdotR = max(0.0, dot(R, V));
4407fd4e5da5Sopenharmony_ci		float3 spec = (pow(NdotR, 16.0) * albedo.a * 2.5).xxx;
4408fd4e5da5Sopenharmony_ci
4409fd4e5da5Sopenharmony_ci		fragcolor += float3((diff + spec) * spotEffect * heightAttenuation) * ubo.lights[i].color.rgb * albedo.rgb;
4410fd4e5da5Sopenharmony_ci	}
4411fd4e5da5Sopenharmony_ci
4412fd4e5da5Sopenharmony_ci	// Shadow calculations in a separate pass
4413fd4e5da5Sopenharmony_ci	if (ubo.useShadows > 0)
4414fd4e5da5Sopenharmony_ci	{
4415fd4e5da5Sopenharmony_ci		fragcolor = shadow(fragcolor, fragPos);
4416fd4e5da5Sopenharmony_ci	}
4417fd4e5da5Sopenharmony_ci
4418fd4e5da5Sopenharmony_ci	return float4(fragcolor, 1);
4419fd4e5da5Sopenharmony_ci}
4420fd4e5da5Sopenharmony_ci"
4421fd4e5da5Sopenharmony_ci         %68 = OpString "textureProj"
4422fd4e5da5Sopenharmony_ci         %69 = OpString ""
4423fd4e5da5Sopenharmony_ci         %78 = OpString "dist"
4424fd4e5da5Sopenharmony_ci         %82 = OpString "shadowCoord"
4425fd4e5da5Sopenharmony_ci         %85 = OpString "shadow"
4426fd4e5da5Sopenharmony_ci         %89 = OpString "offset"
4427fd4e5da5Sopenharmony_ci         %92 = OpString "layer"
4428fd4e5da5Sopenharmony_ci         %95 = OpString "P"
4429fd4e5da5Sopenharmony_ci         %99 = OpString "filterPCF"
4430fd4e5da5Sopenharmony_ci        %108 = OpString "int"
4431fd4e5da5Sopenharmony_ci        %110 = OpString "y"
4432fd4e5da5Sopenharmony_ci        %114 = OpString "x"
4433fd4e5da5Sopenharmony_ci        %118 = OpString "range"
4434fd4e5da5Sopenharmony_ci        %122 = OpString "count"
4435fd4e5da5Sopenharmony_ci        %125 = OpString "shadowFactor"
4436fd4e5da5Sopenharmony_ci        %128 = OpString "dy"
4437fd4e5da5Sopenharmony_ci        %131 = OpString "dx"
4438fd4e5da5Sopenharmony_ci        %134 = OpString "scale"
4439fd4e5da5Sopenharmony_ci        %137 = OpString "levels"
4440fd4e5da5Sopenharmony_ci        %141 = OpString "elements"
4441fd4e5da5Sopenharmony_ci        %145 = OpString "texDim"
4442fd4e5da5Sopenharmony_ci        %150 = OpString "sc"
4443fd4e5da5Sopenharmony_ci        %162 = OpString "shadowClip"
4444fd4e5da5Sopenharmony_ci        %166 = OpString "i"
4445fd4e5da5Sopenharmony_ci        %169 = OpString "fragPos"
4446fd4e5da5Sopenharmony_ci        %171 = OpString "fragcolor"
4447fd4e5da5Sopenharmony_ci        %175 = OpString "main"
4448fd4e5da5Sopenharmony_ci        %184 = OpString "spec"
4449fd4e5da5Sopenharmony_ci        %187 = OpString "NdotR"
4450fd4e5da5Sopenharmony_ci        %190 = OpString "R"
4451fd4e5da5Sopenharmony_ci        %193 = OpString "diff"
4452fd4e5da5Sopenharmony_ci        %196 = OpString "NdotL"
4453fd4e5da5Sopenharmony_ci        %199 = OpString "heightAttenuation"
4454fd4e5da5Sopenharmony_ci        %202 = OpString "spotEffect"
4455fd4e5da5Sopenharmony_ci        %205 = OpString "cosDir"
4456fd4e5da5Sopenharmony_ci        %208 = OpString "dir"
4457fd4e5da5Sopenharmony_ci        %211 = OpString "lightRange"
4458fd4e5da5Sopenharmony_ci        %214 = OpString "lightCosOuterAngle"
4459fd4e5da5Sopenharmony_ci        %217 = OpString "lightCosInnerAngle"
4460fd4e5da5Sopenharmony_ci        %220 = OpString "V"
4461fd4e5da5Sopenharmony_ci        %225 = OpString "L"
4462fd4e5da5Sopenharmony_ci        %230 = OpString "N"
4463fd4e5da5Sopenharmony_ci        %235 = OpString "albedo"
4464fd4e5da5Sopenharmony_ci        %238 = OpString "normal"
4465fd4e5da5Sopenharmony_ci        %244 = OpString "inUV"
4466fd4e5da5Sopenharmony_ci        %246 = OpString "viewPos"
4467fd4e5da5Sopenharmony_ci        %249 = OpString "position"
4468fd4e5da5Sopenharmony_ci        %252 = OpString "target"
4469fd4e5da5Sopenharmony_ci        %254 = OpString "color"
4470fd4e5da5Sopenharmony_ci        %259 = OpString "viewMatrix"
4471fd4e5da5Sopenharmony_ci        %263 = OpString "Light"
4472fd4e5da5Sopenharmony_ci        %267 = OpString "lights"
4473fd4e5da5Sopenharmony_ci        %271 = OpString "useShadows"
4474fd4e5da5Sopenharmony_ci        %275 = OpString "displayDebugTarget"
4475fd4e5da5Sopenharmony_ci        %278 = OpString "UBO"
4476fd4e5da5Sopenharmony_ci        %282 = OpString "ubo"
4477fd4e5da5Sopenharmony_ci        %285 = OpString "type.ubo"
4478fd4e5da5Sopenharmony_ci        %289 = OpString "@type.sampler"
4479fd4e5da5Sopenharmony_ci        %290 = OpString "type.sampler"
4480fd4e5da5Sopenharmony_ci        %292 = OpString "samplerShadowMap"
4481fd4e5da5Sopenharmony_ci        %295 = OpString "@type.2d.image.array"
4482fd4e5da5Sopenharmony_ci        %296 = OpString "type.2d.image.array"
4483fd4e5da5Sopenharmony_ci        %298 = OpString "TemplateParam"
4484fd4e5da5Sopenharmony_ci        %301 = OpString "textureShadowMap"
4485fd4e5da5Sopenharmony_ci        %304 = OpString "samplerAlbedo"
4486fd4e5da5Sopenharmony_ci        %306 = OpString "@type.2d.image"
4487fd4e5da5Sopenharmony_ci        %307 = OpString "type.2d.image"
4488fd4e5da5Sopenharmony_ci        %311 = OpString "textureAlbedo"
4489fd4e5da5Sopenharmony_ci        %313 = OpString "samplerNormal"
4490fd4e5da5Sopenharmony_ci        %315 = OpString "textureNormal"
4491fd4e5da5Sopenharmony_ci        %317 = OpString "samplerposition"
4492fd4e5da5Sopenharmony_ci        %319 = OpString "textureposition"
4493fd4e5da5Sopenharmony_ci               OpName %type_2d_image "type.2d.image"
4494fd4e5da5Sopenharmony_ci               OpName %textureposition "textureposition"
4495fd4e5da5Sopenharmony_ci               OpName %type_sampler "type.sampler"
4496fd4e5da5Sopenharmony_ci               OpName %samplerposition "samplerposition"
4497fd4e5da5Sopenharmony_ci               OpName %textureNormal "textureNormal"
4498fd4e5da5Sopenharmony_ci               OpName %samplerNormal "samplerNormal"
4499fd4e5da5Sopenharmony_ci               OpName %textureAlbedo "textureAlbedo"
4500fd4e5da5Sopenharmony_ci               OpName %samplerAlbedo "samplerAlbedo"
4501fd4e5da5Sopenharmony_ci               OpName %type_2d_image_array "type.2d.image.array"
4502fd4e5da5Sopenharmony_ci               OpName %textureShadowMap "textureShadowMap"
4503fd4e5da5Sopenharmony_ci               OpName %samplerShadowMap "samplerShadowMap"
4504fd4e5da5Sopenharmony_ci               OpName %type_ubo "type.ubo"
4505fd4e5da5Sopenharmony_ci               OpMemberName %type_ubo 0 "ubo"
4506fd4e5da5Sopenharmony_ci               OpName %UBO "UBO"
4507fd4e5da5Sopenharmony_ci               OpMemberName %UBO 0 "viewPos"
4508fd4e5da5Sopenharmony_ci               OpMemberName %UBO 1 "lights"
4509fd4e5da5Sopenharmony_ci               OpMemberName %UBO 2 "useShadows"
4510fd4e5da5Sopenharmony_ci               OpMemberName %UBO 3 "displayDebugTarget"
4511fd4e5da5Sopenharmony_ci               OpName %Light "Light"
4512fd4e5da5Sopenharmony_ci               OpMemberName %Light 0 "position"
4513fd4e5da5Sopenharmony_ci               OpMemberName %Light 1 "target"
4514fd4e5da5Sopenharmony_ci               OpMemberName %Light 2 "color"
4515fd4e5da5Sopenharmony_ci               OpMemberName %Light 3 "viewMatrix"
4516fd4e5da5Sopenharmony_ci               OpName %ubo "ubo"
4517fd4e5da5Sopenharmony_ci               OpName %in_var_TEXCOORD0 "in.var.TEXCOORD0"
4518fd4e5da5Sopenharmony_ci               OpName %out_var_SV_TARGET "out.var.SV_TARGET"
4519fd4e5da5Sopenharmony_ci               OpName %main "main"
4520fd4e5da5Sopenharmony_ci               OpName %param_var_inUV "param.var.inUV"
4521fd4e5da5Sopenharmony_ci               OpName %type_sampled_image "type.sampled.image"
4522fd4e5da5Sopenharmony_ci               OpName %type_sampled_image_0 "type.sampled.image"
4523fd4e5da5Sopenharmony_ci               OpDecorate %in_var_TEXCOORD0 Location 0
4524fd4e5da5Sopenharmony_ci               OpDecorate %out_var_SV_TARGET Location 0
4525fd4e5da5Sopenharmony_ci               OpDecorate %textureposition DescriptorSet 0
4526fd4e5da5Sopenharmony_ci               OpDecorate %textureposition Binding 1
4527fd4e5da5Sopenharmony_ci               OpDecorate %samplerposition DescriptorSet 0
4528fd4e5da5Sopenharmony_ci               OpDecorate %samplerposition Binding 1
4529fd4e5da5Sopenharmony_ci               OpDecorate %textureNormal DescriptorSet 0
4530fd4e5da5Sopenharmony_ci               OpDecorate %textureNormal Binding 2
4531fd4e5da5Sopenharmony_ci               OpDecorate %samplerNormal DescriptorSet 0
4532fd4e5da5Sopenharmony_ci               OpDecorate %samplerNormal Binding 2
4533fd4e5da5Sopenharmony_ci               OpDecorate %textureAlbedo DescriptorSet 0
4534fd4e5da5Sopenharmony_ci               OpDecorate %textureAlbedo Binding 3
4535fd4e5da5Sopenharmony_ci               OpDecorate %samplerAlbedo DescriptorSet 0
4536fd4e5da5Sopenharmony_ci               OpDecorate %samplerAlbedo Binding 3
4537fd4e5da5Sopenharmony_ci               OpDecorate %textureShadowMap DescriptorSet 0
4538fd4e5da5Sopenharmony_ci               OpDecorate %textureShadowMap Binding 5
4539fd4e5da5Sopenharmony_ci               OpDecorate %samplerShadowMap DescriptorSet 0
4540fd4e5da5Sopenharmony_ci               OpDecorate %samplerShadowMap Binding 5
4541fd4e5da5Sopenharmony_ci               OpDecorate %ubo DescriptorSet 0
4542fd4e5da5Sopenharmony_ci               OpDecorate %ubo Binding 4
4543fd4e5da5Sopenharmony_ci               OpMemberDecorate %Light 0 Offset 0
4544fd4e5da5Sopenharmony_ci               OpMemberDecorate %Light 1 Offset 16
4545fd4e5da5Sopenharmony_ci               OpMemberDecorate %Light 2 Offset 32
4546fd4e5da5Sopenharmony_ci               OpMemberDecorate %Light 3 Offset 48
4547fd4e5da5Sopenharmony_ci               OpMemberDecorate %Light 3 MatrixStride 16
4548fd4e5da5Sopenharmony_ci               OpMemberDecorate %Light 3 RowMajor
4549fd4e5da5Sopenharmony_ci               OpDecorate %_arr_Light_uint_3 ArrayStride 112
4550fd4e5da5Sopenharmony_ci               OpMemberDecorate %UBO 0 Offset 0
4551fd4e5da5Sopenharmony_ci               OpMemberDecorate %UBO 1 Offset 16
4552fd4e5da5Sopenharmony_ci               OpMemberDecorate %UBO 2 Offset 352
4553fd4e5da5Sopenharmony_ci               OpMemberDecorate %UBO 3 Offset 356
4554fd4e5da5Sopenharmony_ci               OpMemberDecorate %type_ubo 0 Offset 0
4555fd4e5da5Sopenharmony_ci               OpDecorate %type_ubo Block
4556fd4e5da5Sopenharmony_ci)"
4557fd4e5da5Sopenharmony_ci      R"(   %float = OpTypeFloat 32
4558fd4e5da5Sopenharmony_ci%float_0_100000001 = OpConstant %float 0.100000001
4559fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
4560fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
4561fd4e5da5Sopenharmony_ci      %int_3 = OpConstant %int 3
4562fd4e5da5Sopenharmony_ci      %int_1 = OpConstant %int 1
4563fd4e5da5Sopenharmony_ci   %float_15 = OpConstant %float 15
4564fd4e5da5Sopenharmony_ci   %float_25 = OpConstant %float 25
4565fd4e5da5Sopenharmony_ci  %float_100 = OpConstant %float 100
4566fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
4567fd4e5da5Sopenharmony_ci   %float_16 = OpConstant %float 16
4568fd4e5da5Sopenharmony_ci  %float_2_5 = OpConstant %float 2.5
4569fd4e5da5Sopenharmony_ci      %int_2 = OpConstant %int 2
4570fd4e5da5Sopenharmony_ci    %float_1 = OpConstant %float 1
4571fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
4572fd4e5da5Sopenharmony_ci     %uint_0 = OpConstant %uint 0
4573fd4e5da5Sopenharmony_ci  %float_1_5 = OpConstant %float 1.5
4574fd4e5da5Sopenharmony_ci  %float_0_5 = OpConstant %float 0.5
4575fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
4576fd4e5da5Sopenharmony_ci         %35 = OpConstantComposite %v2float %float_0_5 %float_0_5
4577fd4e5da5Sopenharmony_ci   %float_n1 = OpConstant %float -1
4578fd4e5da5Sopenharmony_ci %float_0_25 = OpConstant %float 0.25
4579fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
4580fd4e5da5Sopenharmony_ci%type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
4581fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
4582fd4e5da5Sopenharmony_ci%type_sampler = OpTypeSampler
4583fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %type_sampler
4584fd4e5da5Sopenharmony_ci%type_2d_image_array = OpTypeImage %float 2D 2 1 0 1 Unknown
4585fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_2d_image_array = OpTypePointer UniformConstant %type_2d_image_array
4586fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
4587fd4e5da5Sopenharmony_ci     %uint_3 = OpConstant %uint 3
4588fd4e5da5Sopenharmony_ci%mat4v4float = OpTypeMatrix %v4float 4
4589fd4e5da5Sopenharmony_ci      %Light = OpTypeStruct %v4float %v4float %v4float %mat4v4float
4590fd4e5da5Sopenharmony_ci%_arr_Light_uint_3 = OpTypeArray %Light %uint_3
4591fd4e5da5Sopenharmony_ci        %UBO = OpTypeStruct %v4float %_arr_Light_uint_3 %int %int
4592fd4e5da5Sopenharmony_ci   %type_ubo = OpTypeStruct %UBO
4593fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_ubo = OpTypePointer Uniform %type_ubo
4594fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
4595fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
4596fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
4597fd4e5da5Sopenharmony_ci     %uint_4 = OpConstant %uint 4
4598fd4e5da5Sopenharmony_ci     %uint_2 = OpConstant %uint 2
4599fd4e5da5Sopenharmony_ci     %uint_1 = OpConstant %uint 1
4600fd4e5da5Sopenharmony_ci     %uint_5 = OpConstant %uint 5
4601fd4e5da5Sopenharmony_ci    %uint_37 = OpConstant %uint 37
4602fd4e5da5Sopenharmony_ci    %uint_38 = OpConstant %uint 38
4603fd4e5da5Sopenharmony_ci    %uint_44 = OpConstant %uint 44
4604fd4e5da5Sopenharmony_ci    %uint_47 = OpConstant %uint 47
4605fd4e5da5Sopenharmony_ci    %uint_45 = OpConstant %uint 45
4606fd4e5da5Sopenharmony_ci     %uint_9 = OpConstant %uint 9
4607fd4e5da5Sopenharmony_ci    %uint_40 = OpConstant %uint 40
4608fd4e5da5Sopenharmony_ci    %uint_39 = OpConstant %uint 39
4609fd4e5da5Sopenharmony_ci     %uint_8 = OpConstant %uint 8
4610fd4e5da5Sopenharmony_ci    %uint_49 = OpConstant %uint 49
4611fd4e5da5Sopenharmony_ci    %uint_35 = OpConstant %uint 35
4612fd4e5da5Sopenharmony_ci    %uint_26 = OpConstant %uint 26
4613fd4e5da5Sopenharmony_ci    %uint_54 = OpConstant %uint 54
4614fd4e5da5Sopenharmony_ci    %uint_55 = OpConstant %uint 55
4615fd4e5da5Sopenharmony_ci    %uint_67 = OpConstant %uint 67
4616fd4e5da5Sopenharmony_ci    %uint_69 = OpConstant %uint 69
4617fd4e5da5Sopenharmony_ci    %uint_68 = OpConstant %uint 68
4618fd4e5da5Sopenharmony_ci    %uint_12 = OpConstant %uint 12
4619fd4e5da5Sopenharmony_ci    %uint_66 = OpConstant %uint 66
4620fd4e5da5Sopenharmony_ci    %uint_11 = OpConstant %uint 11
4621fd4e5da5Sopenharmony_ci    %uint_64 = OpConstant %uint 64
4622fd4e5da5Sopenharmony_ci     %uint_6 = OpConstant %uint 6
4623fd4e5da5Sopenharmony_ci    %uint_63 = OpConstant %uint 63
4624fd4e5da5Sopenharmony_ci    %uint_62 = OpConstant %uint 62
4625fd4e5da5Sopenharmony_ci    %uint_60 = OpConstant %uint 60
4626fd4e5da5Sopenharmony_ci    %uint_59 = OpConstant %uint 59
4627fd4e5da5Sopenharmony_ci    %uint_58 = OpConstant %uint 58
4628fd4e5da5Sopenharmony_ci    %uint_56 = OpConstant %uint 56
4629fd4e5da5Sopenharmony_ci    %uint_33 = OpConstant %uint 33
4630fd4e5da5Sopenharmony_ci    %uint_19 = OpConstant %uint 19
4631fd4e5da5Sopenharmony_ci     %uint_7 = OpConstant %uint 7
4632fd4e5da5Sopenharmony_ci    %uint_34 = OpConstant %uint 34
4633fd4e5da5Sopenharmony_ci    %uint_24 = OpConstant %uint 24
4634fd4e5da5Sopenharmony_ci    %uint_78 = OpConstant %uint 78
4635fd4e5da5Sopenharmony_ci    %uint_80 = OpConstant %uint 80
4636fd4e5da5Sopenharmony_ci    %uint_83 = OpConstant %uint 83
4637fd4e5da5Sopenharmony_ci    %uint_81 = OpConstant %uint 81
4638fd4e5da5Sopenharmony_ci    %uint_10 = OpConstant %uint 10
4639fd4e5da5Sopenharmony_ci    %uint_79 = OpConstant %uint 79
4640fd4e5da5Sopenharmony_ci    %uint_22 = OpConstant %uint 22
4641fd4e5da5Sopenharmony_ci    %uint_95 = OpConstant %uint 95
4642fd4e5da5Sopenharmony_ci    %uint_96 = OpConstant %uint 96
4643fd4e5da5Sopenharmony_ci   %uint_145 = OpConstant %uint 145
4644fd4e5da5Sopenharmony_ci   %uint_108 = OpConstant %uint 108
4645fd4e5da5Sopenharmony_ci   %uint_138 = OpConstant %uint 138
4646fd4e5da5Sopenharmony_ci   %uint_137 = OpConstant %uint 137
4647fd4e5da5Sopenharmony_ci   %uint_136 = OpConstant %uint 136
4648fd4e5da5Sopenharmony_ci   %uint_133 = OpConstant %uint 133
4649fd4e5da5Sopenharmony_ci   %uint_132 = OpConstant %uint 132
4650fd4e5da5Sopenharmony_ci   %uint_129 = OpConstant %uint 129
4651fd4e5da5Sopenharmony_ci   %uint_128 = OpConstant %uint 128
4652fd4e5da5Sopenharmony_ci   %uint_127 = OpConstant %uint 127
4653fd4e5da5Sopenharmony_ci   %uint_124 = OpConstant %uint 124
4654fd4e5da5Sopenharmony_ci   %uint_121 = OpConstant %uint 121
4655fd4e5da5Sopenharmony_ci   %uint_120 = OpConstant %uint 120
4656fd4e5da5Sopenharmony_ci   %uint_119 = OpConstant %uint 119
4657fd4e5da5Sopenharmony_ci   %uint_116 = OpConstant %uint 116
4658fd4e5da5Sopenharmony_ci   %uint_112 = OpConstant %uint 112
4659fd4e5da5Sopenharmony_ci   %uint_110 = OpConstant %uint 110
4660fd4e5da5Sopenharmony_ci   %uint_107 = OpConstant %uint 107
4661fd4e5da5Sopenharmony_ci   %uint_105 = OpConstant %uint 105
4662fd4e5da5Sopenharmony_ci   %uint_103 = OpConstant %uint 103
4663fd4e5da5Sopenharmony_ci   %uint_100 = OpConstant %uint 100
4664fd4e5da5Sopenharmony_ci    %uint_99 = OpConstant %uint 99
4665fd4e5da5Sopenharmony_ci    %uint_98 = OpConstant %uint 98
4666fd4e5da5Sopenharmony_ci    %uint_29 = OpConstant %uint 29
4667fd4e5da5Sopenharmony_ci    %uint_21 = OpConstant %uint 21
4668fd4e5da5Sopenharmony_ci   %uint_256 = OpConstant %uint 256
4669fd4e5da5Sopenharmony_ci    %uint_23 = OpConstant %uint 23
4670fd4e5da5Sopenharmony_ci   %uint_384 = OpConstant %uint 384
4671fd4e5da5Sopenharmony_ci   %uint_512 = OpConstant %uint 512
4672fd4e5da5Sopenharmony_ci   %uint_896 = OpConstant %uint 896
4673fd4e5da5Sopenharmony_ci  %uint_2688 = OpConstant %uint 2688
4674fd4e5da5Sopenharmony_ci    %uint_30 = OpConstant %uint 30
4675fd4e5da5Sopenharmony_ci  %uint_2816 = OpConstant %uint 2816
4676fd4e5da5Sopenharmony_ci    %uint_31 = OpConstant %uint 31
4677fd4e5da5Sopenharmony_ci  %uint_2848 = OpConstant %uint 2848
4678fd4e5da5Sopenharmony_ci  %uint_2880 = OpConstant %uint 2880
4679fd4e5da5Sopenharmony_ci    %uint_27 = OpConstant %uint 27
4680fd4e5da5Sopenharmony_ci  %uint_2944 = OpConstant %uint 2944
4681fd4e5da5Sopenharmony_ci    %uint_14 = OpConstant %uint 14
4682fd4e5da5Sopenharmony_ci    %uint_16 = OpConstant %uint 16
4683fd4e5da5Sopenharmony_ci        %321 = OpTypeFunction %void
4684fd4e5da5Sopenharmony_ci%_ptr_Function_v2float = OpTypePointer Function %v2float
4685fd4e5da5Sopenharmony_ci   %uint_150 = OpConstant %uint 150
4686fd4e5da5Sopenharmony_ci    %v3float = OpTypeVector %float 3
4687fd4e5da5Sopenharmony_ci%_ptr_Function_v3float = OpTypePointer Function %v3float
4688fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
4689fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
4690fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
4691fd4e5da5Sopenharmony_ci    %uint_42 = OpConstant %uint 42
4692fd4e5da5Sopenharmony_ci%type_sampled_image = OpTypeSampledImage %type_2d_image
4693fd4e5da5Sopenharmony_ci    %uint_65 = OpConstant %uint 65
4694fd4e5da5Sopenharmony_ci    %uint_18 = OpConstant %uint 18
4695fd4e5da5Sopenharmony_ci    %uint_13 = OpConstant %uint 13
4696fd4e5da5Sopenharmony_ci    %uint_15 = OpConstant %uint 15
4697fd4e5da5Sopenharmony_ci    %uint_17 = OpConstant %uint 17
4698fd4e5da5Sopenharmony_ci       %bool = OpTypeBool
4699fd4e5da5Sopenharmony_ci    %uint_25 = OpConstant %uint 25
4700fd4e5da5Sopenharmony_ci%_ptr_Uniform_UBO = OpTypePointer Uniform %UBO
4701fd4e5da5Sopenharmony_ci%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
4702fd4e5da5Sopenharmony_ci    %uint_28 = OpConstant %uint 28
4703fd4e5da5Sopenharmony_ci    %uint_43 = OpConstant %uint 43
4704fd4e5da5Sopenharmony_ci   %uint_113 = OpConstant %uint 113
4705fd4e5da5Sopenharmony_ci   %uint_117 = OpConstant %uint 117
4706fd4e5da5Sopenharmony_ci    %uint_46 = OpConstant %uint 46
4707fd4e5da5Sopenharmony_ci    %uint_76 = OpConstant %uint 76
4708fd4e5da5Sopenharmony_ci    %uint_53 = OpConstant %uint 53
4709fd4e5da5Sopenharmony_ci    %uint_73 = OpConstant %uint 73
4710fd4e5da5Sopenharmony_ci    %uint_48 = OpConstant %uint 48
4711fd4e5da5Sopenharmony_ci   %uint_140 = OpConstant %uint 140
4712fd4e5da5Sopenharmony_ci    %uint_52 = OpConstant %uint 52
4713fd4e5da5Sopenharmony_ci    %uint_93 = OpConstant %uint 93
4714fd4e5da5Sopenharmony_ci    %uint_87 = OpConstant %uint 87
4715fd4e5da5Sopenharmony_ci   %uint_106 = OpConstant %uint 106
4716fd4e5da5Sopenharmony_ci    %uint_36 = OpConstant %uint 36
4717fd4e5da5Sopenharmony_ci   %uint_144 = OpConstant %uint 144
4718fd4e5da5Sopenharmony_ci%_ptr_Uniform_int = OpTypePointer Uniform %int
4719fd4e5da5Sopenharmony_ci   %uint_146 = OpConstant %uint 146
4720fd4e5da5Sopenharmony_ci   %uint_147 = OpConstant %uint 147
4721fd4e5da5Sopenharmony_ci   %uint_149 = OpConstant %uint 149
4722fd4e5da5Sopenharmony_ci    %uint_41 = OpConstant %uint 41
4723fd4e5da5Sopenharmony_ci%_ptr_Uniform_mat4v4float = OpTypePointer Uniform %mat4v4float
4724fd4e5da5Sopenharmony_ci    %uint_77 = OpConstant %uint 77
4725fd4e5da5Sopenharmony_ci    %uint_85 = OpConstant %uint 85
4726fd4e5da5Sopenharmony_ci    %uint_90 = OpConstant %uint 90
4727fd4e5da5Sopenharmony_ci    %uint_92 = OpConstant %uint 92
4728fd4e5da5Sopenharmony_ci      %v2int = OpTypeVector %int 2
4729fd4e5da5Sopenharmony_ci%_ptr_Function_v2int = OpTypePointer Function %v2int
4730fd4e5da5Sopenharmony_ci    %uint_57 = OpConstant %uint 57
4731fd4e5da5Sopenharmony_ci     %v3uint = OpTypeVector %uint 3
4732fd4e5da5Sopenharmony_ci    %uint_72 = OpConstant %uint 72
4733fd4e5da5Sopenharmony_ci    %uint_70 = OpConstant %uint 70
4734fd4e5da5Sopenharmony_ci    %uint_50 = OpConstant %uint 50
4735fd4e5da5Sopenharmony_ci    %uint_61 = OpConstant %uint 61
4736fd4e5da5Sopenharmony_ci    %uint_71 = OpConstant %uint 71
4737fd4e5da5Sopenharmony_ci    %uint_75 = OpConstant %uint 75
4738fd4e5da5Sopenharmony_ci    %uint_82 = OpConstant %uint 82
4739fd4e5da5Sopenharmony_ci%type_sampled_image_0 = OpTypeSampledImage %type_2d_image_array
4740fd4e5da5Sopenharmony_ci    %uint_51 = OpConstant %uint 51
4741fd4e5da5Sopenharmony_ci%textureposition = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
4742fd4e5da5Sopenharmony_ci%samplerposition = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
4743fd4e5da5Sopenharmony_ci%textureNormal = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
4744fd4e5da5Sopenharmony_ci%samplerNormal = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
4745fd4e5da5Sopenharmony_ci%textureAlbedo = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
4746fd4e5da5Sopenharmony_ci%samplerAlbedo = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
4747fd4e5da5Sopenharmony_ci%textureShadowMap = OpVariable %_ptr_UniformConstant_type_2d_image_array UniformConstant
4748fd4e5da5Sopenharmony_ci%samplerShadowMap = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
4749fd4e5da5Sopenharmony_ci        %ubo = OpVariable %_ptr_Uniform_type_ubo Uniform
4750fd4e5da5Sopenharmony_ci%in_var_TEXCOORD0 = OpVariable %_ptr_Input_v2float Input
4751fd4e5da5Sopenharmony_ci%out_var_SV_TARGET = OpVariable %_ptr_Output_v4float Output
4752fd4e5da5Sopenharmony_ci  %uint_1792 = OpConstant %uint 1792
4753fd4e5da5Sopenharmony_ci  %uint_1869 = OpConstant %uint 1869
4754fd4e5da5Sopenharmony_ci  %uint_2060 = OpConstant %uint 2060
4755fd4e5da5Sopenharmony_ci        %288 = OpExtInst %void %2 DebugInfoNone
4756fd4e5da5Sopenharmony_ci        %243 = OpExtInst %void %2 DebugExpression
4757fd4e5da5Sopenharmony_ci         %57 = OpExtInst %void %2 DebugTypeBasic %55 %uint_32 %uint_3 %uint_0
4758fd4e5da5Sopenharmony_ci         %58 = OpExtInst %void %2 DebugTypeVector %57 %uint_4
4759fd4e5da5Sopenharmony_ci         %60 = OpExtInst %void %2 DebugTypeVector %57 %uint_2
4760fd4e5da5Sopenharmony_ci         %62 = OpExtInst %void %2 DebugTypeFunction %uint_3 %57 %58 %57 %60
4761fd4e5da5Sopenharmony_ci         %64 = OpExtInst %void %2 DebugSource %15 %63
4762fd4e5da5Sopenharmony_ci         %65 = OpExtInst %void %2 DebugCompilationUnit %uint_1 %uint_4 %64 %uint_5
4763fd4e5da5Sopenharmony_ci         %70 = OpExtInst %void %2 DebugFunction %68 %62 %64 %uint_37 %uint_1 %65 %69 %uint_3 %uint_38
4764fd4e5da5Sopenharmony_ci         %73 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_38 %uint_1 %70
4765fd4e5da5Sopenharmony_ci         %74 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_44 %uint_2 %73
4766fd4e5da5Sopenharmony_ci         %76 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_47 %uint_3 %74
4767fd4e5da5Sopenharmony_ci         %79 = OpExtInst %void %2 DebugLocalVariable %78 %57 %64 %uint_45 %uint_9 %74 %uint_4
4768fd4e5da5Sopenharmony_ci         %83 = OpExtInst %void %2 DebugLocalVariable %82 %58 %64 %uint_40 %uint_9 %73 %uint_4
4769fd4e5da5Sopenharmony_ci         %86 = OpExtInst %void %2 DebugLocalVariable %85 %57 %64 %uint_39 %uint_8 %73 %uint_4
4770fd4e5da5Sopenharmony_ci         %90 = OpExtInst %void %2 DebugLocalVariable %89 %60 %64 %uint_37 %uint_49 %70 %uint_4 %uint_3
4771fd4e5da5Sopenharmony_ci         %93 = OpExtInst %void %2 DebugLocalVariable %92 %57 %64 %uint_37 %uint_35 %70 %uint_4 %uint_2
4772fd4e5da5Sopenharmony_ci         %96 = OpExtInst %void %2 DebugLocalVariable %95 %58 %64 %uint_37 %uint_26 %70 %uint_4 %uint_1
4773fd4e5da5Sopenharmony_ci         %98 = OpExtInst %void %2 DebugTypeFunction %uint_3 %57 %58 %57
4774fd4e5da5Sopenharmony_ci        %100 = OpExtInst %void %2 DebugFunction %99 %98 %64 %uint_54 %uint_1 %65 %69 %uint_3 %uint_55
4775fd4e5da5Sopenharmony_ci        %103 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_55 %uint_1 %100
4776fd4e5da5Sopenharmony_ci        %104 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_67 %uint_2 %103
4777fd4e5da5Sopenharmony_ci        %106 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_69 %uint_3 %104
4778fd4e5da5Sopenharmony_ci        %109 = OpExtInst %void %2 DebugTypeBasic %108 %uint_32 %uint_4 %uint_0
4779fd4e5da5Sopenharmony_ci        %111 = OpExtInst %void %2 DebugLocalVariable %110 %109 %64 %uint_68 %uint_12 %104 %uint_4
4780fd4e5da5Sopenharmony_ci        %115 = OpExtInst %void %2 DebugLocalVariable %114 %109 %64 %uint_66 %uint_11 %103 %uint_4
4781fd4e5da5Sopenharmony_ci        %119 = OpExtInst %void %2 DebugLocalVariable %118 %109 %64 %uint_64 %uint_6 %103 %uint_4
4782fd4e5da5Sopenharmony_ci        %123 = OpExtInst %void %2 DebugLocalVariable %122 %109 %64 %uint_63 %uint_6 %103 %uint_4
4783fd4e5da5Sopenharmony_ci        %126 = OpExtInst %void %2 DebugLocalVariable %125 %57 %64 %uint_62 %uint_8 %103 %uint_4
4784fd4e5da5Sopenharmony_ci        %129 = OpExtInst %void %2 DebugLocalVariable %128 %57 %64 %uint_60 %uint_8 %103 %uint_4
4785fd4e5da5Sopenharmony_ci        %132 = OpExtInst %void %2 DebugLocalVariable %131 %57 %64 %uint_59 %uint_8 %103 %uint_4
4786fd4e5da5Sopenharmony_ci        %135 = OpExtInst %void %2 DebugLocalVariable %134 %57 %64 %uint_58 %uint_8 %103 %uint_4
4787fd4e5da5Sopenharmony_ci        %138 = OpExtInst %void %2 DebugLocalVariable %137 %109 %64 %uint_56 %uint_33 %103 %uint_4
4788fd4e5da5Sopenharmony_ci        %142 = OpExtInst %void %2 DebugLocalVariable %141 %109 %64 %uint_56 %uint_19 %103 %uint_4
4789fd4e5da5Sopenharmony_ci        %144 = OpExtInst %void %2 DebugTypeVector %109 %uint_2
4790fd4e5da5Sopenharmony_ci        %146 = OpExtInst %void %2 DebugLocalVariable %145 %144 %64 %uint_56 %uint_7 %103 %uint_4
4791fd4e5da5Sopenharmony_ci        %148 = OpExtInst %void %2 DebugLocalVariable %92 %57 %64 %uint_54 %uint_34 %100 %uint_4 %uint_2
4792fd4e5da5Sopenharmony_ci        %151 = OpExtInst %void %2 DebugLocalVariable %150 %58 %64 %uint_54 %uint_24 %100 %uint_4 %uint_1
4793fd4e5da5Sopenharmony_ci        %153 = OpExtInst %void %2 DebugTypeVector %57 %uint_3
4794fd4e5da5Sopenharmony_ci        %154 = OpExtInst %void %2 DebugTypeFunction %uint_3 %153 %153 %153
4795fd4e5da5Sopenharmony_ci        %155 = OpExtInst %void %2 DebugFunction %85 %154 %64 %uint_78 %uint_1 %65 %69 %uint_3 %uint_78
4796fd4e5da5Sopenharmony_ci        %157 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_78 %uint_49 %155
4797fd4e5da5Sopenharmony_ci        %158 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_80 %uint_2 %157
4798fd4e5da5Sopenharmony_ci        %160 = OpExtInst %void %2 DebugLocalVariable %125 %57 %64 %uint_83 %uint_9 %158 %uint_4
4799fd4e5da5Sopenharmony_ci        %163 = OpExtInst %void %2 DebugLocalVariable %162 %58 %64 %uint_81 %uint_10 %158 %uint_4
4800fd4e5da5Sopenharmony_ci        %167 = OpExtInst %void %2 DebugLocalVariable %166 %109 %64 %uint_79 %uint_11 %157 %uint_4
4801fd4e5da5Sopenharmony_ci        %170 = OpExtInst %void %2 DebugLocalVariable %169 %153 %64 %uint_78 %uint_40 %155 %uint_4 %uint_2
4802fd4e5da5Sopenharmony_ci        %172 = OpExtInst %void %2 DebugLocalVariable %171 %153 %64 %uint_78 %uint_22 %155 %uint_4 %uint_1
4803fd4e5da5Sopenharmony_ci        %174 = OpExtInst %void %2 DebugTypeFunction %uint_3 %58 %60
4804fd4e5da5Sopenharmony_ci        %176 = OpExtInst %void %2 DebugFunction %175 %174 %64 %uint_95 %uint_1 %65 %69 %uint_3 %uint_96
4805fd4e5da5Sopenharmony_ci        %179 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_96 %uint_1 %176
4806fd4e5da5Sopenharmony_ci        %180 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_145 %uint_2 %179
4807fd4e5da5Sopenharmony_ci        %182 = OpExtInst %void %2 DebugLexicalBlock %64 %uint_108 %uint_2 %179
4808fd4e5da5Sopenharmony_ci        %185 = OpExtInst %void %2 DebugLocalVariable %184 %153 %64 %uint_138 %uint_10 %182 %uint_4
4809fd4e5da5Sopenharmony_ci        %188 = OpExtInst %void %2 DebugLocalVariable %187 %57 %64 %uint_137 %uint_9 %182 %uint_4
4810fd4e5da5Sopenharmony_ci        %191 = OpExtInst %void %2 DebugLocalVariable %190 %153 %64 %uint_136 %uint_10 %182 %uint_4
4811fd4e5da5Sopenharmony_ci        %194 = OpExtInst %void %2 DebugLocalVariable %193 %153 %64 %uint_133 %uint_10 %182 %uint_4
4812fd4e5da5Sopenharmony_ci        %197 = OpExtInst %void %2 DebugLocalVariable %196 %57 %64 %uint_132 %uint_9 %182 %uint_4
4813fd4e5da5Sopenharmony_ci        %200 = OpExtInst %void %2 DebugLocalVariable %199 %57 %64 %uint_129 %uint_9 %182 %uint_4
4814fd4e5da5Sopenharmony_ci        %203 = OpExtInst %void %2 DebugLocalVariable %202 %57 %64 %uint_128 %uint_9 %182 %uint_4
4815fd4e5da5Sopenharmony_ci        %206 = OpExtInst %void %2 DebugLocalVariable %205 %57 %64 %uint_127 %uint_9 %182 %uint_4
4816fd4e5da5Sopenharmony_ci        %209 = OpExtInst %void %2 DebugLocalVariable %208 %153 %64 %uint_124 %uint_10 %182 %uint_4
4817fd4e5da5Sopenharmony_ci        %212 = OpExtInst %void %2 DebugLocalVariable %211 %57 %64 %uint_121 %uint_9 %182 %uint_4
4818fd4e5da5Sopenharmony_ci        %215 = OpExtInst %void %2 DebugLocalVariable %214 %57 %64 %uint_120 %uint_9 %182 %uint_4
4819fd4e5da5Sopenharmony_ci        %218 = OpExtInst %void %2 DebugLocalVariable %217 %57 %64 %uint_119 %uint_9 %182 %uint_4
4820fd4e5da5Sopenharmony_ci        %221 = OpExtInst %void %2 DebugLocalVariable %220 %153 %64 %uint_116 %uint_10 %182 %uint_4
4821fd4e5da5Sopenharmony_ci        %223 = OpExtInst %void %2 DebugLocalVariable %78 %57 %64 %uint_112 %uint_9 %182 %uint_4
4822fd4e5da5Sopenharmony_ci        %226 = OpExtInst %void %2 DebugLocalVariable %225 %153 %64 %uint_110 %uint_10 %182 %uint_4
4823fd4e5da5Sopenharmony_ci        %228 = OpExtInst %void %2 DebugLocalVariable %166 %109 %64 %uint_107 %uint_10 %179 %uint_4
4824fd4e5da5Sopenharmony_ci        %231 = OpExtInst %void %2 DebugLocalVariable %230 %153 %64 %uint_105 %uint_9 %179 %uint_4
4825fd4e5da5Sopenharmony_ci        %233 = OpExtInst %void %2 DebugLocalVariable %171 %153 %64 %uint_103 %uint_9 %179 %uint_4
4826fd4e5da5Sopenharmony_ci        %236 = OpExtInst %void %2 DebugLocalVariable %235 %58 %64 %uint_100 %uint_9 %179 %uint_4
4827fd4e5da5Sopenharmony_ci        %239 = OpExtInst %void %2 DebugLocalVariable %238 %153 %64 %uint_99 %uint_9 %179 %uint_4
4828fd4e5da5Sopenharmony_ci        %241 = OpExtInst %void %2 DebugLocalVariable %169 %153 %64 %uint_98 %uint_9 %179 %uint_4
4829fd4e5da5Sopenharmony_ci        %245 = OpExtInst %void %2 DebugLocalVariable %244 %60 %64 %uint_95 %uint_40 %176 %uint_4 %uint_1
4830fd4e5da5Sopenharmony_ci)"
4831fd4e5da5Sopenharmony_ci      R"(     %247 = OpExtInst %void %2 DebugTypeMember %246 %58 %64 %uint_29 %uint_9 %uint_0 %uint_128 %uint_3
4832fd4e5da5Sopenharmony_ci        %250 = OpExtInst %void %2 DebugTypeMember %249 %58 %64 %uint_21 %uint_9 %uint_0 %uint_128 %uint_3
4833fd4e5da5Sopenharmony_ci        %253 = OpExtInst %void %2 DebugTypeMember %252 %58 %64 %uint_22 %uint_9 %uint_128 %uint_128 %uint_3
4834fd4e5da5Sopenharmony_ci        %256 = OpExtInst %void %2 DebugTypeMember %254 %58 %64 %uint_23 %uint_9 %uint_256 %uint_128 %uint_3
4835fd4e5da5Sopenharmony_ci        %258 = OpExtInst %void %2 DebugTypeArray %57 %uint_4 %uint_4
4836fd4e5da5Sopenharmony_ci        %262 = OpExtInst %void %2 DebugTypeMember %259 %258 %64 %uint_24 %uint_11 %uint_384 %uint_512 %uint_3
4837fd4e5da5Sopenharmony_ci        %265 = OpExtInst %void %2 DebugTypeComposite %263 %uint_1 %64 %uint_19 %uint_8 %65 %263 %uint_896 %uint_3 %250 %253 %256 %262
4838fd4e5da5Sopenharmony_ci        %266 = OpExtInst %void %2 DebugTypeArray %265 %uint_3
4839fd4e5da5Sopenharmony_ci        %269 = OpExtInst %void %2 DebugTypeMember %267 %266 %64 %uint_30 %uint_8 %uint_128 %uint_2688 %uint_3
4840fd4e5da5Sopenharmony_ci        %273 = OpExtInst %void %2 DebugTypeMember %271 %109 %64 %uint_31 %uint_6 %uint_2816 %uint_32 %uint_3
4841fd4e5da5Sopenharmony_ci        %277 = OpExtInst %void %2 DebugTypeMember %275 %109 %64 %uint_32 %uint_6 %uint_2848 %uint_32 %uint_3
4842fd4e5da5Sopenharmony_ci        %280 = OpExtInst %void %2 DebugTypeComposite %278 %uint_1 %64 %uint_27 %uint_8 %65 %278 %uint_2880 %uint_3 %247 %269 %273 %277
4843fd4e5da5Sopenharmony_ci        %284 = OpExtInst %void %2 DebugTypeMember %282 %280 %64 %uint_35 %uint_34 %uint_0 %uint_2944 %uint_3
4844fd4e5da5Sopenharmony_ci        %286 = OpExtInst %void %2 DebugTypeComposite %285 %uint_1 %64 %uint_35 %uint_9 %65 %285 %uint_2944 %uint_3 %284
4845fd4e5da5Sopenharmony_ci        %287 = OpExtInst %void %2 DebugGlobalVariable %282 %286 %64 %uint_35 %uint_9 %65 %282 %ubo %uint_8
4846fd4e5da5Sopenharmony_ci        %291 = OpExtInst %void %2 DebugTypeComposite %289 %uint_1 %64 %uint_0 %uint_0 %65 %290 %288 %uint_3
4847fd4e5da5Sopenharmony_ci        %293 = OpExtInst %void %2 DebugGlobalVariable %292 %291 %64 %uint_12 %uint_14 %65 %292 %samplerShadowMap %uint_8
4848fd4e5da5Sopenharmony_ci        %297 = OpExtInst %void %2 DebugTypeComposite %295 %uint_0 %64 %uint_0 %uint_0 %65 %296 %288 %uint_3
4849fd4e5da5Sopenharmony_ci        %299 = OpExtInst %void %2 DebugTypeTemplateParameter %298 %58 %288 %64 %uint_0 %uint_0
4850fd4e5da5Sopenharmony_ci        %300 = OpExtInst %void %2 DebugTypeTemplate %297 %299
4851fd4e5da5Sopenharmony_ci        %302 = OpExtInst %void %2 DebugGlobalVariable %301 %300 %64 %uint_11 %uint_16 %65 %301 %textureShadowMap %uint_8
4852fd4e5da5Sopenharmony_ci        %305 = OpExtInst %void %2 DebugGlobalVariable %304 %291 %64 %uint_8 %uint_14 %65 %304 %samplerAlbedo %uint_8
4853fd4e5da5Sopenharmony_ci        %308 = OpExtInst %void %2 DebugTypeComposite %306 %uint_0 %64 %uint_0 %uint_0 %65 %307 %288 %uint_3
4854fd4e5da5Sopenharmony_ci        %309 = OpExtInst %void %2 DebugTypeTemplateParameter %298 %58 %288 %64 %uint_0 %uint_0
4855fd4e5da5Sopenharmony_ci        %310 = OpExtInst %void %2 DebugTypeTemplate %308 %309
4856fd4e5da5Sopenharmony_ci        %312 = OpExtInst %void %2 DebugGlobalVariable %311 %310 %64 %uint_7 %uint_11 %65 %311 %textureAlbedo %uint_8
4857fd4e5da5Sopenharmony_ci        %314 = OpExtInst %void %2 DebugGlobalVariable %313 %291 %64 %uint_6 %uint_14 %65 %313 %samplerNormal %uint_8
4858fd4e5da5Sopenharmony_ci        %316 = OpExtInst %void %2 DebugGlobalVariable %315 %310 %64 %uint_5 %uint_11 %65 %315 %textureNormal %uint_8
4859fd4e5da5Sopenharmony_ci        %318 = OpExtInst %void %2 DebugGlobalVariable %317 %291 %64 %uint_4 %uint_14 %65 %317 %samplerposition %uint_8
4860fd4e5da5Sopenharmony_ci        %320 = OpExtInst %void %2 DebugGlobalVariable %319 %310 %64 %uint_3 %uint_11 %65 %319 %textureposition %uint_8
4861fd4e5da5Sopenharmony_ci       %1803 = OpExtInst %void %2 DebugInlinedAt %uint_1792 %180
4862fd4e5da5Sopenharmony_ci       %1885 = OpExtInst %void %2 DebugInlinedAt %uint_1869 %158 %1803
4863fd4e5da5Sopenharmony_ci       %2085 = OpExtInst %void %2 DebugInlinedAt %uint_2060 %106 %1885
4864fd4e5da5Sopenharmony_ci)"
4865fd4e5da5Sopenharmony_ci      R"(    %main = OpFunction %void None %321
4866fd4e5da5Sopenharmony_ci        %322 = OpLabel
4867fd4e5da5Sopenharmony_ci       %2083 = OpVariable %_ptr_Function_float Function
4868fd4e5da5Sopenharmony_ci       %2086 = OpVariable %_ptr_Function_v4float Function
4869fd4e5da5Sopenharmony_ci       %1883 = OpVariable %_ptr_Function_v2int Function
4870fd4e5da5Sopenharmony_ci       %1891 = OpVariable %_ptr_Function_float Function
4871fd4e5da5Sopenharmony_ci       %1892 = OpVariable %_ptr_Function_int Function
4872fd4e5da5Sopenharmony_ci       %1894 = OpVariable %_ptr_Function_int Function
4873fd4e5da5Sopenharmony_ci       %1895 = OpVariable %_ptr_Function_int Function
4874fd4e5da5Sopenharmony_ci       %1896 = OpVariable %_ptr_Function_v4float Function
4875fd4e5da5Sopenharmony_ci       %1801 = OpVariable %_ptr_Function_int Function
4876fd4e5da5Sopenharmony_ci       %1447 = OpVariable %_ptr_Function_v4float Function
4877fd4e5da5Sopenharmony_ci       %1448 = OpVariable %_ptr_Function_v3float Function
4878fd4e5da5Sopenharmony_ci       %1450 = OpVariable %_ptr_Function_int Function
4879fd4e5da5Sopenharmony_ci       %1451 = OpVariable %_ptr_Function_v3float Function
4880fd4e5da5Sopenharmony_ci       %1453 = OpVariable %_ptr_Function_v3float Function
4881fd4e5da5Sopenharmony_ci       %1466 = OpVariable %_ptr_Function_v3float Function
4882fd4e5da5Sopenharmony_ci%param_var_inUV = OpVariable %_ptr_Function_v2float Function
4883fd4e5da5Sopenharmony_ci        %325 = OpExtInst %void %2 DebugFunctionDefinition %176 %main
4884fd4e5da5Sopenharmony_ci        %326 = OpLoad %v2float %in_var_TEXCOORD0
4885fd4e5da5Sopenharmony_ci               OpStore %param_var_inUV %326
4886fd4e5da5Sopenharmony_ci       %2290 = OpExtInst %void %2 DebugScope %176
4887fd4e5da5Sopenharmony_ci       %1620 = OpExtInst %void %2 DebugLine %64 %uint_95 %uint_95 %uint_33 %uint_40
4888fd4e5da5Sopenharmony_ci       %1470 = OpExtInst %void %2 DebugDeclare %245 %param_var_inUV %243
4889fd4e5da5Sopenharmony_ci       %2291 = OpExtInst %void %2 DebugScope %179
4890fd4e5da5Sopenharmony_ci       %1621 = OpExtInst %void %2 DebugLine %64 %uint_98 %uint_98 %uint_19 %uint_19
4891fd4e5da5Sopenharmony_ci       %1471 = OpLoad %type_2d_image %textureposition
4892fd4e5da5Sopenharmony_ci       %1622 = OpExtInst %void %2 DebugLine %64 %uint_98 %uint_98 %uint_42 %uint_42
4893fd4e5da5Sopenharmony_ci       %1472 = OpLoad %type_sampler %samplerposition
4894fd4e5da5Sopenharmony_ci       %1624 = OpExtInst %void %2 DebugLine %64 %uint_98 %uint_98 %uint_19 %uint_63
4895fd4e5da5Sopenharmony_ci       %1474 = OpSampledImage %type_sampled_image %1471 %1472
4896fd4e5da5Sopenharmony_ci       %1475 = OpImageSampleImplicitLod %v4float %1474 %326 None
4897fd4e5da5Sopenharmony_ci       %1626 = OpExtInst %void %2 DebugLine %64 %uint_98 %uint_98 %uint_19 %uint_65
4898fd4e5da5Sopenharmony_ci       %1476 = OpVectorShuffle %v3float %1475 %1475 0 1 2
4899fd4e5da5Sopenharmony_ci       %2241 = OpExtInst %void %2 DebugLine %64 %uint_98 %uint_98 %uint_2 %uint_65
4900fd4e5da5Sopenharmony_ci       %2240 = OpExtInst %void %2 DebugValue %241 %1476 %243
4901fd4e5da5Sopenharmony_ci       %1629 = OpExtInst %void %2 DebugLine %64 %uint_99 %uint_99 %uint_18 %uint_18
4902fd4e5da5Sopenharmony_ci       %1478 = OpLoad %type_2d_image %textureNormal
4903fd4e5da5Sopenharmony_ci       %1630 = OpExtInst %void %2 DebugLine %64 %uint_99 %uint_99 %uint_39 %uint_39
4904fd4e5da5Sopenharmony_ci       %1479 = OpLoad %type_sampler %samplerNormal
4905fd4e5da5Sopenharmony_ci       %1632 = OpExtInst %void %2 DebugLine %64 %uint_99 %uint_99 %uint_18 %uint_58
4906fd4e5da5Sopenharmony_ci       %1481 = OpSampledImage %type_sampled_image %1478 %1479
4907fd4e5da5Sopenharmony_ci       %1482 = OpImageSampleImplicitLod %v4float %1481 %326 None
4908fd4e5da5Sopenharmony_ci       %1634 = OpExtInst %void %2 DebugLine %64 %uint_99 %uint_99 %uint_18 %uint_60
4909fd4e5da5Sopenharmony_ci       %1483 = OpVectorShuffle %v3float %1482 %1482 0 1 2
4910fd4e5da5Sopenharmony_ci       %2244 = OpExtInst %void %2 DebugLine %64 %uint_99 %uint_99 %uint_2 %uint_60
4911fd4e5da5Sopenharmony_ci       %2243 = OpExtInst %void %2 DebugValue %239 %1483 %243
4912fd4e5da5Sopenharmony_ci       %1637 = OpExtInst %void %2 DebugLine %64 %uint_100 %uint_100 %uint_18 %uint_18
4913fd4e5da5Sopenharmony_ci       %1485 = OpLoad %type_2d_image %textureAlbedo
4914fd4e5da5Sopenharmony_ci       %1638 = OpExtInst %void %2 DebugLine %64 %uint_100 %uint_100 %uint_39 %uint_39
4915fd4e5da5Sopenharmony_ci       %1486 = OpLoad %type_sampler %samplerAlbedo
4916fd4e5da5Sopenharmony_ci       %1640 = OpExtInst %void %2 DebugLine %64 %uint_100 %uint_100 %uint_18 %uint_58
4917fd4e5da5Sopenharmony_ci       %1488 = OpSampledImage %type_sampled_image %1485 %1486
4918fd4e5da5Sopenharmony_ci       %1489 = OpImageSampleImplicitLod %v4float %1488 %326 None
4919fd4e5da5Sopenharmony_ci       %1642 = OpExtInst %void %2 DebugLine %64 %uint_100 %uint_100 %uint_2 %uint_58
4920fd4e5da5Sopenharmony_ci               OpStore %1447 %1489
4921fd4e5da5Sopenharmony_ci       %1490 = OpExtInst %void %2 DebugDeclare %236 %1447 %243
4922fd4e5da5Sopenharmony_ci       %1645 = OpExtInst %void %2 DebugLine %64 %uint_103 %uint_103 %uint_22 %uint_29
4923fd4e5da5Sopenharmony_ci       %1492 = OpVectorShuffle %v3float %1489 %1489 0 1 2
4924fd4e5da5Sopenharmony_ci       %1646 = OpExtInst %void %2 DebugLine %64 %uint_103 %uint_103 %uint_22 %uint_35
4925fd4e5da5Sopenharmony_ci       %1493 = OpVectorTimesScalar %v3float %1492 %float_0_100000001
4926fd4e5da5Sopenharmony_ci       %1647 = OpExtInst %void %2 DebugLine %64 %uint_103 %uint_103 %uint_2 %uint_35
4927fd4e5da5Sopenharmony_ci               OpStore %1448 %1493
4928fd4e5da5Sopenharmony_ci       %1494 = OpExtInst %void %2 DebugDeclare %233 %1448 %243
4929fd4e5da5Sopenharmony_ci       %1650 = OpExtInst %void %2 DebugLine %64 %uint_105 %uint_105 %uint_13 %uint_29
4930fd4e5da5Sopenharmony_ci       %1496 = OpExtInst %v3float %1 Normalize %1483
4931fd4e5da5Sopenharmony_ci       %2247 = OpExtInst %void %2 DebugLine %64 %uint_105 %uint_105 %uint_2 %uint_29
4932fd4e5da5Sopenharmony_ci       %2246 = OpExtInst %void %2 DebugValue %231 %1496 %243
4933fd4e5da5Sopenharmony_ci       %1653 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_6 %uint_14
4934fd4e5da5Sopenharmony_ci               OpStore %1450 %int_0
4935fd4e5da5Sopenharmony_ci       %1498 = OpExtInst %void %2 DebugDeclare %228 %1450 %243
4936fd4e5da5Sopenharmony_ci       %1655 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_6 %uint_15
4937fd4e5da5Sopenharmony_ci               OpBranch %1499
4938fd4e5da5Sopenharmony_ci       %1499 = OpLabel
4939fd4e5da5Sopenharmony_ci       %2292 = OpExtInst %void %2 DebugScope %179
4940fd4e5da5Sopenharmony_ci       %1656 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_17 %uint_17
4941fd4e5da5Sopenharmony_ci       %1500 = OpLoad %int %1450
4942fd4e5da5Sopenharmony_ci       %1657 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_17 %uint_21
4943fd4e5da5Sopenharmony_ci       %1501 = OpSLessThan %bool %1500 %int_3
4944fd4e5da5Sopenharmony_ci       %2293 = OpExtInst %void %2 DebugNoScope
4945fd4e5da5Sopenharmony_ci               OpLoopMerge %1605 %1602 None
4946fd4e5da5Sopenharmony_ci               OpBranchConditional %1501 %1502 %1605
4947fd4e5da5Sopenharmony_ci       %1502 = OpLabel
4948fd4e5da5Sopenharmony_ci       %2294 = OpExtInst %void %2 DebugScope %182
4949fd4e5da5Sopenharmony_ci       %1660 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_25 %uint_25
4950fd4e5da5Sopenharmony_ci       %1503 = OpLoad %int %1450
4951fd4e5da5Sopenharmony_ci       %1661 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_14 %uint_37
4952fd4e5da5Sopenharmony_ci       %1504 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
4953fd4e5da5Sopenharmony_ci       %1505 = OpAccessChain %_ptr_Uniform_v4float %1504 %int_1 %1503 %int_0
4954fd4e5da5Sopenharmony_ci       %1663 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_14 %uint_28
4955fd4e5da5Sopenharmony_ci       %1506 = OpLoad %v4float %1505
4956fd4e5da5Sopenharmony_ci       %1664 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_14 %uint_37
4957fd4e5da5Sopenharmony_ci       %1507 = OpVectorShuffle %v3float %1506 %1506 0 1 2
4958fd4e5da5Sopenharmony_ci       %1666 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_14 %uint_43
4959fd4e5da5Sopenharmony_ci       %1509 = OpFSub %v3float %1507 %1476
4960fd4e5da5Sopenharmony_ci       %1667 = OpExtInst %void %2 DebugLine %64 %uint_110 %uint_110 %uint_3 %uint_43
4961fd4e5da5Sopenharmony_ci               OpStore %1451 %1509
4962fd4e5da5Sopenharmony_ci       %1510 = OpExtInst %void %2 DebugDeclare %226 %1451 %243
4963fd4e5da5Sopenharmony_ci       %1670 = OpExtInst %void %2 DebugLine %64 %uint_112 %uint_112 %uint_16 %uint_24
4964fd4e5da5Sopenharmony_ci       %1512 = OpExtInst %float %1 Length %1509
4965fd4e5da5Sopenharmony_ci       %2250 = OpExtInst %void %2 DebugLine %64 %uint_112 %uint_112 %uint_3 %uint_24
4966fd4e5da5Sopenharmony_ci       %2249 = OpExtInst %void %2 DebugValue %223 %1512 %243
4967fd4e5da5Sopenharmony_ci       %1674 = OpExtInst %void %2 DebugLine %64 %uint_113 %uint_113 %uint_7 %uint_18
4968fd4e5da5Sopenharmony_ci       %1515 = OpExtInst %v3float %1 Normalize %1509
4969fd4e5da5Sopenharmony_ci       %1675 = OpExtInst %void %2 DebugLine %64 %uint_113 %uint_113 %uint_3 %uint_18
4970fd4e5da5Sopenharmony_ci               OpStore %1451 %1515
4971fd4e5da5Sopenharmony_ci       %1676 = OpExtInst %void %2 DebugLine %64 %uint_116 %uint_116 %uint_14 %uint_26
4972fd4e5da5Sopenharmony_ci       %1516 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
4973fd4e5da5Sopenharmony_ci       %1517 = OpAccessChain %_ptr_Uniform_v4float %1516 %int_0
4974fd4e5da5Sopenharmony_ci       %1678 = OpExtInst %void %2 DebugLine %64 %uint_116 %uint_116 %uint_14 %uint_18
4975fd4e5da5Sopenharmony_ci       %1518 = OpLoad %v4float %1517
4976fd4e5da5Sopenharmony_ci       %1679 = OpExtInst %void %2 DebugLine %64 %uint_116 %uint_116 %uint_14 %uint_26
4977fd4e5da5Sopenharmony_ci       %1519 = OpVectorShuffle %v3float %1518 %1518 0 1 2
4978fd4e5da5Sopenharmony_ci       %1681 = OpExtInst %void %2 DebugLine %64 %uint_116 %uint_116 %uint_14 %uint_32
4979fd4e5da5Sopenharmony_ci       %1521 = OpFSub %v3float %1519 %1476
4980fd4e5da5Sopenharmony_ci       %1682 = OpExtInst %void %2 DebugLine %64 %uint_116 %uint_116 %uint_3 %uint_32
4981fd4e5da5Sopenharmony_ci               OpStore %1453 %1521
4982fd4e5da5Sopenharmony_ci       %1522 = OpExtInst %void %2 DebugDeclare %221 %1453 %243
4983fd4e5da5Sopenharmony_ci       %1685 = OpExtInst %void %2 DebugLine %64 %uint_117 %uint_117 %uint_7 %uint_18
4984fd4e5da5Sopenharmony_ci       %1524 = OpExtInst %v3float %1 Normalize %1521
4985fd4e5da5Sopenharmony_ci       %1686 = OpExtInst %void %2 DebugLine %64 %uint_117 %uint_117 %uint_3 %uint_18
4986fd4e5da5Sopenharmony_ci               OpStore %1453 %1524
4987fd4e5da5Sopenharmony_ci       %1687 = OpExtInst %void %2 DebugLine %64 %uint_119 %uint_119 %uint_34 %uint_46
4988fd4e5da5Sopenharmony_ci       %1525 = OpExtInst %float %1 Radians %float_15
4989fd4e5da5Sopenharmony_ci       %1688 = OpExtInst %void %2 DebugLine %64 %uint_119 %uint_119 %uint_30 %uint_47
4990fd4e5da5Sopenharmony_ci       %1526 = OpExtInst %float %1 Cos %1525
4991fd4e5da5Sopenharmony_ci       %2253 = OpExtInst %void %2 DebugLine %64 %uint_119 %uint_119 %uint_3 %uint_47
4992fd4e5da5Sopenharmony_ci       %2252 = OpExtInst %void %2 DebugValue %218 %1526 %243
4993fd4e5da5Sopenharmony_ci       %1691 = OpExtInst %void %2 DebugLine %64 %uint_120 %uint_120 %uint_34 %uint_46
4994fd4e5da5Sopenharmony_ci       %1528 = OpExtInst %float %1 Radians %float_25
4995fd4e5da5Sopenharmony_ci       %1692 = OpExtInst %void %2 DebugLine %64 %uint_120 %uint_120 %uint_30 %uint_47
4996fd4e5da5Sopenharmony_ci       %1529 = OpExtInst %float %1 Cos %1528
4997fd4e5da5Sopenharmony_ci       %2256 = OpExtInst %void %2 DebugLine %64 %uint_120 %uint_120 %uint_3 %uint_47
4998fd4e5da5Sopenharmony_ci       %2255 = OpExtInst %void %2 DebugValue %215 %1529 %243
4999fd4e5da5Sopenharmony_ci       %2259 = OpExtInst %void %2 DebugLine %64 %uint_121 %uint_121 %uint_3 %uint_22
5000fd4e5da5Sopenharmony_ci       %2258 = OpExtInst %void %2 DebugValue %212 %float_100 %243
5001fd4e5da5Sopenharmony_ci       %1698 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_26 %uint_49
5002fd4e5da5Sopenharmony_ci       %1533 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
5003fd4e5da5Sopenharmony_ci       %1534 = OpAccessChain %_ptr_Uniform_v4float %1533 %int_1 %1503 %int_0
5004fd4e5da5Sopenharmony_ci       %1700 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_26 %uint_40
5005fd4e5da5Sopenharmony_ci       %1535 = OpLoad %v4float %1534
5006fd4e5da5Sopenharmony_ci       %1701 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_26 %uint_49
5007fd4e5da5Sopenharmony_ci       %1536 = OpVectorShuffle %v3float %1535 %1535 0 1 2
5008fd4e5da5Sopenharmony_ci       %1703 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_55 %uint_76
5009fd4e5da5Sopenharmony_ci       %1538 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
5010fd4e5da5Sopenharmony_ci       %1539 = OpAccessChain %_ptr_Uniform_v4float %1538 %int_1 %1503 %int_1
5011fd4e5da5Sopenharmony_ci       %1705 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_55 %uint_69
5012fd4e5da5Sopenharmony_ci       %1540 = OpLoad %v4float %1539
5013fd4e5da5Sopenharmony_ci       %1706 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_55 %uint_76
5014fd4e5da5Sopenharmony_ci       %1541 = OpVectorShuffle %v3float %1540 %1540 0 1 2
5015fd4e5da5Sopenharmony_ci       %1707 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_26 %uint_76
5016fd4e5da5Sopenharmony_ci       %1542 = OpFSub %v3float %1536 %1541
5017fd4e5da5Sopenharmony_ci       %1708 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_16 %uint_79
5018fd4e5da5Sopenharmony_ci       %1543 = OpExtInst %v3float %1 Normalize %1542
5019fd4e5da5Sopenharmony_ci       %2262 = OpExtInst %void %2 DebugLine %64 %uint_124 %uint_124 %uint_3 %uint_79
5020fd4e5da5Sopenharmony_ci       %2261 = OpExtInst %void %2 DebugValue %209 %1543 %243
5021fd4e5da5Sopenharmony_ci       %1713 = OpExtInst %void %2 DebugLine %64 %uint_127 %uint_127 %uint_18 %uint_28
5022fd4e5da5Sopenharmony_ci       %1547 = OpDot %float %1515 %1543
5023fd4e5da5Sopenharmony_ci       %2265 = OpExtInst %void %2 DebugLine %64 %uint_127 %uint_127 %uint_3 %uint_28
5024fd4e5da5Sopenharmony_ci       %2264 = OpExtInst %void %2 DebugValue %206 %1547 %243
5025fd4e5da5Sopenharmony_ci       %1719 = OpExtInst %void %2 DebugLine %64 %uint_128 %uint_128 %uint_22 %uint_79
5026fd4e5da5Sopenharmony_ci       %1552 = OpExtInst %float %1 SmoothStep %1529 %1526 %1547
5027fd4e5da5Sopenharmony_ci       %2268 = OpExtInst %void %2 DebugLine %64 %uint_128 %uint_128 %uint_3 %uint_79
5028fd4e5da5Sopenharmony_ci       %2267 = OpExtInst %void %2 DebugValue %203 %1552 %243
5029fd4e5da5Sopenharmony_ci       %1724 = OpExtInst %void %2 DebugLine %64 %uint_129 %uint_129 %uint_29 %uint_62
5030fd4e5da5Sopenharmony_ci       %1556 = OpExtInst %float %1 SmoothStep %float_100 %float_0 %1512
5031fd4e5da5Sopenharmony_ci       %2271 = OpExtInst %void %2 DebugLine %64 %uint_129 %uint_129 %uint_3 %uint_62
5032fd4e5da5Sopenharmony_ci       %2270 = OpExtInst %void %2 DebugValue %200 %1556 %243
5033fd4e5da5Sopenharmony_ci       %1729 = OpExtInst %void %2 DebugLine %64 %uint_132 %uint_132 %uint_26 %uint_34
5034fd4e5da5Sopenharmony_ci       %1560 = OpDot %float %1496 %1515
5035fd4e5da5Sopenharmony_ci       %1730 = OpExtInst %void %2 DebugLine %64 %uint_132 %uint_132 %uint_17 %uint_35
5036fd4e5da5Sopenharmony_ci       %1561 = OpExtInst %float %1 FMax %float_0 %1560
5037fd4e5da5Sopenharmony_ci       %2274 = OpExtInst %void %2 DebugLine %64 %uint_132 %uint_132 %uint_3 %uint_35
5038fd4e5da5Sopenharmony_ci       %2273 = OpExtInst %void %2 DebugValue %197 %1561 %243
5039fd4e5da5Sopenharmony_ci       %1734 = OpExtInst %void %2 DebugLine %64 %uint_133 %uint_133 %uint_17 %uint_23
5040fd4e5da5Sopenharmony_ci       %1564 = OpCompositeConstruct %v3float %1561 %1561 %1561
5041fd4e5da5Sopenharmony_ci       %2277 = OpExtInst %void %2 DebugLine %64 %uint_133 %uint_133 %uint_3 %uint_23
5042fd4e5da5Sopenharmony_ci       %2276 = OpExtInst %void %2 DebugValue %194 %1564 %243
5043fd4e5da5Sopenharmony_ci       %1738 = OpExtInst %void %2 DebugLine %64 %uint_136 %uint_136 %uint_22 %uint_23
5044fd4e5da5Sopenharmony_ci       %1567 = OpFNegate %v3float %1515
5045fd4e5da5Sopenharmony_ci       %1740 = OpExtInst %void %2 DebugLine %64 %uint_136 %uint_136 %uint_14 %uint_27
5046fd4e5da5Sopenharmony_ci       %1569 = OpExtInst %v3float %1 Reflect %1567 %1496
5047fd4e5da5Sopenharmony_ci       %2280 = OpExtInst %void %2 DebugLine %64 %uint_136 %uint_136 %uint_3 %uint_27
5048fd4e5da5Sopenharmony_ci       %2279 = OpExtInst %void %2 DebugValue %191 %1569 %243
5049fd4e5da5Sopenharmony_ci       %1745 = OpExtInst %void %2 DebugLine %64 %uint_137 %uint_137 %uint_26 %uint_34
5050fd4e5da5Sopenharmony_ci       %1573 = OpDot %float %1569 %1524
5051fd4e5da5Sopenharmony_ci       %1746 = OpExtInst %void %2 DebugLine %64 %uint_137 %uint_137 %uint_17 %uint_35
5052fd4e5da5Sopenharmony_ci       %1574 = OpExtInst %float %1 FMax %float_0 %1573
5053fd4e5da5Sopenharmony_ci       %2283 = OpExtInst %void %2 DebugLine %64 %uint_137 %uint_137 %uint_3 %uint_35
5054fd4e5da5Sopenharmony_ci       %2282 = OpExtInst %void %2 DebugValue %188 %1574 %243
5055fd4e5da5Sopenharmony_ci       %1750 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_18 %uint_33
5056fd4e5da5Sopenharmony_ci       %1577 = OpExtInst %float %1 Pow %1574 %float_16
5057fd4e5da5Sopenharmony_ci       %1751 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_37 %uint_44
5058fd4e5da5Sopenharmony_ci       %1578 = OpAccessChain %_ptr_Function_float %1447 %int_3
5059fd4e5da5Sopenharmony_ci       %1579 = OpLoad %float %1578
5060fd4e5da5Sopenharmony_ci       %1753 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_18 %uint_44
5061fd4e5da5Sopenharmony_ci       %1580 = OpFMul %float %1577 %1579
5062fd4e5da5Sopenharmony_ci       %1754 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_18 %uint_48
5063fd4e5da5Sopenharmony_ci       %1581 = OpFMul %float %1580 %float_2_5
5064fd4e5da5Sopenharmony_ci       %1755 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_17 %uint_53
5065fd4e5da5Sopenharmony_ci       %1582 = OpCompositeConstruct %v3float %1581 %1581 %1581
5066fd4e5da5Sopenharmony_ci       %2286 = OpExtInst %void %2 DebugLine %64 %uint_138 %uint_138 %uint_3 %uint_53
5067fd4e5da5Sopenharmony_ci       %2285 = OpExtInst %void %2 DebugValue %185 %1582 %243
5068fd4e5da5Sopenharmony_ci       %1760 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_24 %uint_31
5069fd4e5da5Sopenharmony_ci       %1586 = OpFAdd %v3float %1564 %1582
5070fd4e5da5Sopenharmony_ci       %1762 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_23 %uint_39
5071fd4e5da5Sopenharmony_ci       %1588 = OpVectorTimesScalar %v3float %1586 %1552
5072fd4e5da5Sopenharmony_ci       %1764 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_23 %uint_52
5073fd4e5da5Sopenharmony_ci       %1590 = OpVectorTimesScalar %v3float %1588 %1556
5074fd4e5da5Sopenharmony_ci       %1766 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_73 %uint_93
5075fd4e5da5Sopenharmony_ci       %1592 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
5076fd4e5da5Sopenharmony_ci       %1593 = OpAccessChain %_ptr_Uniform_v4float %1592 %int_1 %1503 %int_2
5077fd4e5da5Sopenharmony_ci       %1768 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_73 %uint_87
5078fd4e5da5Sopenharmony_ci       %1594 = OpLoad %v4float %1593
5079fd4e5da5Sopenharmony_ci       %1769 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_73 %uint_93
5080fd4e5da5Sopenharmony_ci       %1595 = OpVectorShuffle %v3float %1594 %1594 0 1 2
5081fd4e5da5Sopenharmony_ci       %1770 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_16 %uint_93
5082fd4e5da5Sopenharmony_ci       %1596 = OpFMul %v3float %1590 %1595
5083fd4e5da5Sopenharmony_ci       %1772 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_99 %uint_106
5084fd4e5da5Sopenharmony_ci       %1598 = OpVectorShuffle %v3float %1489 %1489 0 1 2
5085fd4e5da5Sopenharmony_ci       %1773 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_16 %uint_106
5086fd4e5da5Sopenharmony_ci       %1599 = OpFMul %v3float %1596 %1598
5087fd4e5da5Sopenharmony_ci       %1774 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_3 %uint_3
5088fd4e5da5Sopenharmony_ci       %1600 = OpLoad %v3float %1448
5089fd4e5da5Sopenharmony_ci       %1775 = OpExtInst %void %2 DebugLine %64 %uint_140 %uint_140 %uint_3 %uint_106
5090fd4e5da5Sopenharmony_ci       %1601 = OpFAdd %v3float %1600 %1599
5091fd4e5da5Sopenharmony_ci               OpStore %1448 %1601
5092fd4e5da5Sopenharmony_ci       %2295 = OpExtInst %void %2 DebugScope %179
5093fd4e5da5Sopenharmony_ci       %1777 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_34 %uint_36
5094fd4e5da5Sopenharmony_ci               OpBranch %1602
5095fd4e5da5Sopenharmony_ci       %1602 = OpLabel
5096fd4e5da5Sopenharmony_ci       %2296 = OpExtInst %void %2 DebugScope %179
5097fd4e5da5Sopenharmony_ci       %1778 = OpExtInst %void %2 DebugLine %64 %uint_107 %uint_107 %uint_34 %uint_36
5098fd4e5da5Sopenharmony_ci       %1603 = OpLoad %int %1450
5099fd4e5da5Sopenharmony_ci       %1604 = OpIAdd %int %1603 %int_1
5100fd4e5da5Sopenharmony_ci               OpStore %1450 %1604
5101fd4e5da5Sopenharmony_ci               OpBranch %1499
5102fd4e5da5Sopenharmony_ci       %1605 = OpLabel
5103fd4e5da5Sopenharmony_ci       %2297 = OpExtInst %void %2 DebugScope %179
5104fd4e5da5Sopenharmony_ci       %1782 = OpExtInst %void %2 DebugLine %64 %uint_144 %uint_144 %uint_6 %uint_10
5105fd4e5da5Sopenharmony_ci       %1606 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
5106fd4e5da5Sopenharmony_ci       %1607 = OpAccessChain %_ptr_Uniform_int %1606 %int_2
5107fd4e5da5Sopenharmony_ci       %1608 = OpLoad %int %1607
5108fd4e5da5Sopenharmony_ci       %1785 = OpExtInst %void %2 DebugLine %64 %uint_144 %uint_144 %uint_6 %uint_23
5109fd4e5da5Sopenharmony_ci       %1609 = OpSGreaterThan %bool %1608 %int_0
5110fd4e5da5Sopenharmony_ci       %2298 = OpExtInst %void %2 DebugNoScope
5111fd4e5da5Sopenharmony_ci               OpSelectionMerge %1614 None
5112fd4e5da5Sopenharmony_ci               OpBranchConditional %1609 %1610 %1614
5113fd4e5da5Sopenharmony_ci)"
5114fd4e5da5Sopenharmony_ci      R"(    %1610 = OpLabel
5115fd4e5da5Sopenharmony_ci       %2299 = OpExtInst %void %2 DebugScope %180
5116fd4e5da5Sopenharmony_ci       %1788 = OpExtInst %void %2 DebugLine %64 %uint_146 %uint_146 %uint_22 %uint_22
5117fd4e5da5Sopenharmony_ci       %1611 = OpLoad %v3float %1448
5118fd4e5da5Sopenharmony_ci               OpStore %1466 %1611
5119fd4e5da5Sopenharmony_ci       %2300 = OpExtInst %void %2 DebugScope %155 %1803
5120fd4e5da5Sopenharmony_ci       %1842 = OpExtInst %void %2 DebugLine %64 %uint_78 %uint_78 %uint_15 %uint_22
5121fd4e5da5Sopenharmony_ci       %1810 = OpExtInst %void %2 DebugDeclare %172 %1466 %243
5122fd4e5da5Sopenharmony_ci       %2301 = OpExtInst %void %2 DebugScope %180
5123fd4e5da5Sopenharmony_ci       %2289 = OpExtInst %void %2 DebugLine %64 %uint_146 %uint_146 %uint_33 %uint_33
5124fd4e5da5Sopenharmony_ci       %2288 = OpExtInst %void %2 DebugValue %170 %1476 %243
5125fd4e5da5Sopenharmony_ci       %2302 = OpExtInst %void %2 DebugScope %157 %1803
5126fd4e5da5Sopenharmony_ci       %1844 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_7 %uint_15
5127fd4e5da5Sopenharmony_ci               OpStore %1801 %int_0
5128fd4e5da5Sopenharmony_ci       %1813 = OpExtInst %void %2 DebugDeclare %167 %1801 %243
5129fd4e5da5Sopenharmony_ci       %1846 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_7 %uint_16
5130fd4e5da5Sopenharmony_ci               OpBranch %1814
5131fd4e5da5Sopenharmony_ci       %1814 = OpLabel
5132fd4e5da5Sopenharmony_ci       %2303 = OpExtInst %void %2 DebugScope %157 %1803
5133fd4e5da5Sopenharmony_ci       %1847 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_18 %uint_18
5134fd4e5da5Sopenharmony_ci       %1815 = OpLoad %int %1801
5135fd4e5da5Sopenharmony_ci       %1848 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_18 %uint_22
5136fd4e5da5Sopenharmony_ci       %1816 = OpSLessThan %bool %1815 %int_3
5137fd4e5da5Sopenharmony_ci       %2304 = OpExtInst %void %2 DebugNoScope
5138fd4e5da5Sopenharmony_ci               OpLoopMerge %1840 %1837 None
5139fd4e5da5Sopenharmony_ci               OpBranchConditional %1816 %1817 %1840
5140fd4e5da5Sopenharmony_ci       %1817 = OpLabel
5141fd4e5da5Sopenharmony_ci       %2305 = OpExtInst %void %2 DebugScope %158 %1803
5142fd4e5da5Sopenharmony_ci       %1851 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_38 %uint_38
5143fd4e5da5Sopenharmony_ci       %1818 = OpLoad %int %1801
5144fd4e5da5Sopenharmony_ci       %1852 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_27 %uint_41
5145fd4e5da5Sopenharmony_ci       %1819 = OpAccessChain %_ptr_Uniform_UBO %ubo %int_0
5146fd4e5da5Sopenharmony_ci       %1820 = OpAccessChain %_ptr_Uniform_mat4v4float %1819 %int_1 %1818 %int_3
5147fd4e5da5Sopenharmony_ci       %1821 = OpLoad %mat4v4float %1820
5148fd4e5da5Sopenharmony_ci       %1856 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_60 %uint_68
5149fd4e5da5Sopenharmony_ci       %1823 = OpCompositeExtract %float %1476 0
5150fd4e5da5Sopenharmony_ci       %1824 = OpCompositeExtract %float %1476 1
5151fd4e5da5Sopenharmony_ci       %1825 = OpCompositeExtract %float %1476 2
5152fd4e5da5Sopenharmony_ci       %1859 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_53 %uint_76
5153fd4e5da5Sopenharmony_ci       %1826 = OpCompositeConstruct %v4float %1823 %1824 %1825 %float_1
5154fd4e5da5Sopenharmony_ci       %1860 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_23 %uint_77
5155fd4e5da5Sopenharmony_ci       %1827 = OpVectorTimesMatrix %v4float %1826 %1821
5156fd4e5da5Sopenharmony_ci       %2229 = OpExtInst %void %2 DebugLine %64 %uint_81 %uint_81 %uint_3 %uint_77
5157fd4e5da5Sopenharmony_ci       %2228 = OpExtInst %void %2 DebugValue %163 %1827 %243
5158fd4e5da5Sopenharmony_ci       %1867 = OpExtInst %void %2 DebugLine %64 %uint_85 %uint_85 %uint_40 %uint_40
5159fd4e5da5Sopenharmony_ci       %1832 = OpConvertSToF %float %1818
5160fd4e5da5Sopenharmony_ci       %2235 = OpExtInst %void %2 DebugLine %64 %uint_85 %uint_85 %uint_28 %uint_28
5161fd4e5da5Sopenharmony_ci       %2234 = OpExtInst %void %2 DebugValue %151 %1827 %243
5162fd4e5da5Sopenharmony_ci       %2238 = OpExtInst %void %2 DebugLine %64 %uint_85 %uint_85 %uint_40 %uint_40
5163fd4e5da5Sopenharmony_ci       %2237 = OpExtInst %void %2 DebugValue %148 %1832 %243
5164fd4e5da5Sopenharmony_ci       %2306 = OpExtInst %void %2 DebugScope %103 %1885
5165fd4e5da5Sopenharmony_ci       %1983 = OpExtInst %void %2 DebugLine %64 %uint_56 %uint_56 %uint_2 %uint_7
5166fd4e5da5Sopenharmony_ci       %1904 = OpExtInst %void %2 DebugDeclare %146 %1883 %243
5167fd4e5da5Sopenharmony_ci       %1986 = OpExtInst %void %2 DebugLine %64 %uint_57 %uint_57 %uint_2 %uint_2
5168fd4e5da5Sopenharmony_ci       %1907 = OpLoad %type_2d_image_array %textureShadowMap
5169fd4e5da5Sopenharmony_ci)"
5170fd4e5da5Sopenharmony_ci      R"(    %1987 = OpExtInst %void %2 DebugLine %64 %uint_57 %uint_57 %uint_2 %uint_72
5171fd4e5da5Sopenharmony_ci       %1908 = OpImageQuerySizeLod %v3uint %1907 %uint_0
5172fd4e5da5Sopenharmony_ci       %1909 = OpCompositeExtract %uint %1908 0
5173fd4e5da5Sopenharmony_ci       %1910 = OpBitcast %int %1909
5174fd4e5da5Sopenharmony_ci       %1911 = OpAccessChain %_ptr_Function_int %1883 %int_0
5175fd4e5da5Sopenharmony_ci               OpStore %1911 %1910
5176fd4e5da5Sopenharmony_ci       %1912 = OpCompositeExtract %uint %1908 1
5177fd4e5da5Sopenharmony_ci       %1913 = OpBitcast %int %1912
5178fd4e5da5Sopenharmony_ci       %1914 = OpAccessChain %_ptr_Function_int %1883 %int_1
5179fd4e5da5Sopenharmony_ci               OpStore %1914 %1913
5180fd4e5da5Sopenharmony_ci       %1915 = OpCompositeExtract %uint %1908 2
5181fd4e5da5Sopenharmony_ci       %1916 = OpBitcast %int %1915
5182fd4e5da5Sopenharmony_ci       %2204 = OpExtInst %void %2 DebugValue %142 %1916 %243
5183fd4e5da5Sopenharmony_ci       %1999 = OpExtInst %void %2 DebugLine %64 %uint_57 %uint_57 %uint_19 %uint_19
5184fd4e5da5Sopenharmony_ci       %1917 = OpImageQueryLevels %uint %1907
5185fd4e5da5Sopenharmony_ci       %2000 = OpExtInst %void %2 DebugLine %64 %uint_57 %uint_57 %uint_2 %uint_72
5186fd4e5da5Sopenharmony_ci       %1918 = OpBitcast %int %1917
5187fd4e5da5Sopenharmony_ci       %2207 = OpExtInst %void %2 DebugValue %138 %1918 %243
5188fd4e5da5Sopenharmony_ci       %2211 = OpExtInst %void %2 DebugLine %64 %uint_58 %uint_58 %uint_2 %uint_16
5189fd4e5da5Sopenharmony_ci       %2210 = OpExtInst %void %2 DebugValue %135 %float_1_5 %243
5190fd4e5da5Sopenharmony_ci       %2005 = OpExtInst %void %2 DebugLine %64 %uint_59 %uint_59 %uint_13 %uint_21
5191fd4e5da5Sopenharmony_ci       %1921 = OpFMul %float %float_1_5 %float_1
5192fd4e5da5Sopenharmony_ci       %2006 = OpExtInst %void %2 DebugLine %64 %uint_59 %uint_59 %uint_33 %uint_40
5193fd4e5da5Sopenharmony_ci       %1922 = OpAccessChain %_ptr_Function_int %1883 %int_0
5194fd4e5da5Sopenharmony_ci       %1923 = OpLoad %int %1922
5195fd4e5da5Sopenharmony_ci       %1924 = OpConvertSToF %float %1923
5196fd4e5da5Sopenharmony_ci       %2009 = OpExtInst %void %2 DebugLine %64 %uint_59 %uint_59 %uint_13 %uint_41
5197fd4e5da5Sopenharmony_ci       %1925 = OpFDiv %float %1921 %1924
5198fd4e5da5Sopenharmony_ci       %2214 = OpExtInst %void %2 DebugLine %64 %uint_59 %uint_59 %uint_2 %uint_41
5199fd4e5da5Sopenharmony_ci       %2213 = OpExtInst %void %2 DebugValue %132 %1925 %243
5200fd4e5da5Sopenharmony_ci       %2013 = OpExtInst %void %2 DebugLine %64 %uint_60 %uint_60 %uint_13 %uint_21
5201fd4e5da5Sopenharmony_ci       %1928 = OpFMul %float %float_1_5 %float_1
5202fd4e5da5Sopenharmony_ci       %2014 = OpExtInst %void %2 DebugLine %64 %uint_60 %uint_60 %uint_33 %uint_40
5203fd4e5da5Sopenharmony_ci       %1929 = OpAccessChain %_ptr_Function_int %1883 %int_1
5204fd4e5da5Sopenharmony_ci       %1930 = OpLoad %int %1929
5205fd4e5da5Sopenharmony_ci       %1931 = OpConvertSToF %float %1930
5206fd4e5da5Sopenharmony_ci       %2017 = OpExtInst %void %2 DebugLine %64 %uint_60 %uint_60 %uint_13 %uint_41
5207fd4e5da5Sopenharmony_ci       %1932 = OpFDiv %float %1928 %1931
5208fd4e5da5Sopenharmony_ci       %2217 = OpExtInst %void %2 DebugLine %64 %uint_60 %uint_60 %uint_2 %uint_41
5209fd4e5da5Sopenharmony_ci       %2216 = OpExtInst %void %2 DebugValue %129 %1932 %243
5210fd4e5da5Sopenharmony_ci       %2020 = OpExtInst %void %2 DebugLine %64 %uint_62 %uint_62 %uint_2 %uint_23
5211fd4e5da5Sopenharmony_ci               OpStore %1891 %float_0
5212fd4e5da5Sopenharmony_ci       %1934 = OpExtInst %void %2 DebugDeclare %126 %1891 %243
5213fd4e5da5Sopenharmony_ci       %2022 = OpExtInst %void %2 DebugLine %64 %uint_63 %uint_63 %uint_2 %uint_14
5214fd4e5da5Sopenharmony_ci               OpStore %1892 %int_0
5215fd4e5da5Sopenharmony_ci       %1935 = OpExtInst %void %2 DebugDeclare %123 %1892 %243
5216fd4e5da5Sopenharmony_ci       %2220 = OpExtInst %void %2 DebugLine %64 %uint_64 %uint_64 %uint_2 %uint_14
5217fd4e5da5Sopenharmony_ci       %2219 = OpExtInst %void %2 DebugValue %119 %int_1 %243
5218fd4e5da5Sopenharmony_ci       %2027 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_15 %uint_16
5219fd4e5da5Sopenharmony_ci       %1938 = OpSNegate %int %int_1
5220fd4e5da5Sopenharmony_ci       %2028 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_7 %uint_16
5221fd4e5da5Sopenharmony_ci               OpStore %1894 %1938
5222fd4e5da5Sopenharmony_ci       %1939 = OpExtInst %void %2 DebugDeclare %115 %1894 %243
5223fd4e5da5Sopenharmony_ci       %2030 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_7 %uint_21
5224fd4e5da5Sopenharmony_ci               OpBranch %1940
5225fd4e5da5Sopenharmony_ci       %1940 = OpLabel
5226fd4e5da5Sopenharmony_ci       %2307 = OpExtInst %void %2 DebugScope %103 %1885
5227fd4e5da5Sopenharmony_ci       %2031 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_23 %uint_23
5228fd4e5da5Sopenharmony_ci       %1941 = OpLoad %int %1894
5229fd4e5da5Sopenharmony_ci       %2033 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_23 %uint_28
5230fd4e5da5Sopenharmony_ci       %1943 = OpSLessThanEqual %bool %1941 %int_1
5231fd4e5da5Sopenharmony_ci       %2308 = OpExtInst %void %2 DebugNoScope
5232fd4e5da5Sopenharmony_ci               OpLoopMerge %1976 %1973 None
5233fd4e5da5Sopenharmony_ci               OpBranchConditional %1943 %1944 %1976
5234fd4e5da5Sopenharmony_ci       %1944 = OpLabel
5235fd4e5da5Sopenharmony_ci       %2309 = OpExtInst %void %2 DebugScope %104 %1885
5236fd4e5da5Sopenharmony_ci       %2037 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_16 %uint_17
5237fd4e5da5Sopenharmony_ci       %1946 = OpSNegate %int %int_1
5238fd4e5da5Sopenharmony_ci       %2038 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_8 %uint_17
5239fd4e5da5Sopenharmony_ci               OpStore %1895 %1946
5240fd4e5da5Sopenharmony_ci       %1947 = OpExtInst %void %2 DebugDeclare %111 %1895 %243
5241fd4e5da5Sopenharmony_ci       %2040 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_8 %uint_22
5242fd4e5da5Sopenharmony_ci               OpBranch %1948
5243fd4e5da5Sopenharmony_ci       %1948 = OpLabel
5244fd4e5da5Sopenharmony_ci       %2310 = OpExtInst %void %2 DebugScope %104 %1885
5245fd4e5da5Sopenharmony_ci       %2041 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_24 %uint_24
5246fd4e5da5Sopenharmony_ci       %1949 = OpLoad %int %1895
5247fd4e5da5Sopenharmony_ci       %2043 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_24 %uint_29
5248fd4e5da5Sopenharmony_ci       %1951 = OpSLessThanEqual %bool %1949 %int_1
5249fd4e5da5Sopenharmony_ci       %2311 = OpExtInst %void %2 DebugNoScope
5250fd4e5da5Sopenharmony_ci               OpLoopMerge %1972 %1969 None
5251fd4e5da5Sopenharmony_ci               OpBranchConditional %1951 %1952 %1972
5252fd4e5da5Sopenharmony_ci       %1952 = OpLabel
5253fd4e5da5Sopenharmony_ci       %2312 = OpExtInst %void %2 DebugScope %106 %1885
5254fd4e5da5Sopenharmony_ci       %2047 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_32 %uint_32
5255fd4e5da5Sopenharmony_ci               OpStore %1896 %1827
5256fd4e5da5Sopenharmony_ci       %2051 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_53 %uint_53
5257fd4e5da5Sopenharmony_ci       %1956 = OpLoad %int %1894
5258fd4e5da5Sopenharmony_ci       %1957 = OpConvertSToF %float %1956
5259fd4e5da5Sopenharmony_ci       %2053 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_50 %uint_53
5260fd4e5da5Sopenharmony_ci       %1958 = OpFMul %float %1925 %1957
5261fd4e5da5Sopenharmony_ci       %2055 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_59 %uint_59
5262fd4e5da5Sopenharmony_ci       %1960 = OpLoad %int %1895
5263fd4e5da5Sopenharmony_ci       %1961 = OpConvertSToF %float %1960
5264fd4e5da5Sopenharmony_ci       %2057 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_56 %uint_59
5265fd4e5da5Sopenharmony_ci       %1962 = OpFMul %float %1932 %1961
5266fd4e5da5Sopenharmony_ci       %2058 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_43 %uint_60
5267fd4e5da5Sopenharmony_ci       %1963 = OpCompositeConstruct %v2float %1958 %1962
5268fd4e5da5Sopenharmony_ci       %2313 = OpExtInst %void %2 DebugScope %70 %2085
5269fd4e5da5Sopenharmony_ci       %2141 = OpExtInst %void %2 DebugLine %64 %uint_37 %uint_37 %uint_19 %uint_26
5270fd4e5da5Sopenharmony_ci       %2090 = OpExtInst %void %2 DebugDeclare %96 %1896 %243
5271fd4e5da5Sopenharmony_ci       %2314 = OpExtInst %void %2 DebugScope %106 %1885
5272fd4e5da5Sopenharmony_ci       %2223 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_36 %uint_36
5273fd4e5da5Sopenharmony_ci       %2222 = OpExtInst %void %2 DebugValue %93 %1832 %243
5274fd4e5da5Sopenharmony_ci       %2226 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_43 %uint_60
5275fd4e5da5Sopenharmony_ci       %2225 = OpExtInst %void %2 DebugValue %90 %1963 %243
5276fd4e5da5Sopenharmony_ci       %2315 = OpExtInst %void %2 DebugScope %73 %2085
5277fd4e5da5Sopenharmony_ci       %2144 = OpExtInst %void %2 DebugLine %64 %uint_39 %uint_39 %uint_2 %uint_17
5278fd4e5da5Sopenharmony_ci               OpStore %2083 %float_1
5279fd4e5da5Sopenharmony_ci       %2094 = OpExtInst %void %2 DebugDeclare %86 %2083 %243
5280fd4e5da5Sopenharmony_ci       %2147 = OpExtInst %void %2 DebugLine %64 %uint_40 %uint_40 %uint_27 %uint_29
5281fd4e5da5Sopenharmony_ci       %2096 = OpAccessChain %_ptr_Function_float %1896 %int_3
5282fd4e5da5Sopenharmony_ci       %2097 = OpLoad %float %2096
5283fd4e5da5Sopenharmony_ci       %2098 = OpCompositeConstruct %v4float %2097 %2097 %2097 %2097
5284fd4e5da5Sopenharmony_ci       %2150 = OpExtInst %void %2 DebugLine %64 %uint_40 %uint_40 %uint_23 %uint_29
5285fd4e5da5Sopenharmony_ci       %2099 = OpFDiv %v4float %1827 %2098
5286fd4e5da5Sopenharmony_ci       %2151 = OpExtInst %void %2 DebugLine %64 %uint_40 %uint_40 %uint_2 %uint_29
5287fd4e5da5Sopenharmony_ci               OpStore %2086 %2099
5288fd4e5da5Sopenharmony_ci       %2100 = OpExtInst %void %2 DebugDeclare %83 %2086 %243
5289fd4e5da5Sopenharmony_ci       %2154 = OpExtInst %void %2 DebugLine %64 %uint_41 %uint_41 %uint_19 %uint_31
5290fd4e5da5Sopenharmony_ci       %2102 = OpVectorShuffle %v2float %2099 %2099 0 1
5291fd4e5da5Sopenharmony_ci       %2155 = OpExtInst %void %2 DebugLine %64 %uint_41 %uint_41 %uint_19 %uint_36
5292fd4e5da5Sopenharmony_ci       %2103 = OpVectorTimesScalar %v2float %2102 %float_0_5
5293fd4e5da5Sopenharmony_ci       %2156 = OpExtInst %void %2 DebugLine %64 %uint_41 %uint_41 %uint_19 %uint_42
5294fd4e5da5Sopenharmony_ci       %2104 = OpFAdd %v2float %2103 %35
5295fd4e5da5Sopenharmony_ci       %2158 = OpExtInst %void %2 DebugLine %64 %uint_41 %uint_41 %uint_2 %uint_42
5296fd4e5da5Sopenharmony_ci       %2106 = OpVectorShuffle %v4float %2099 %2104 4 5 2 3
5297fd4e5da5Sopenharmony_ci               OpStore %2086 %2106
5298fd4e5da5Sopenharmony_ci       %2160 = OpExtInst %void %2 DebugLine %64 %uint_43 %uint_43 %uint_6 %uint_18
5299fd4e5da5Sopenharmony_ci       %2107 = OpAccessChain %_ptr_Function_float %2086 %int_2
5300fd4e5da5Sopenharmony_ci       %2108 = OpLoad %float %2107
5301fd4e5da5Sopenharmony_ci       %2162 = OpExtInst %void %2 DebugLine %64 %uint_43 %uint_43 %uint_6 %uint_23
5302fd4e5da5Sopenharmony_ci       %2109 = OpFOrdGreaterThan %bool %2108 %float_n1
5303fd4e5da5Sopenharmony_ci       %2163 = OpExtInst %void %2 DebugLine %64 %uint_43 %uint_43 %uint_30 %uint_42
5304fd4e5da5Sopenharmony_ci       %2110 = OpAccessChain %_ptr_Function_float %2086 %int_2
5305fd4e5da5Sopenharmony_ci       %2111 = OpLoad %float %2110
5306fd4e5da5Sopenharmony_ci       %2165 = OpExtInst %void %2 DebugLine %64 %uint_43 %uint_43 %uint_30 %uint_46
5307fd4e5da5Sopenharmony_ci       %2112 = OpFOrdLessThan %bool %2111 %float_1
5308fd4e5da5Sopenharmony_ci       %2166 = OpExtInst %void %2 DebugLine %64 %uint_43 %uint_43 %uint_6 %uint_46
5309fd4e5da5Sopenharmony_ci       %2113 = OpLogicalAnd %bool %2109 %2112
5310fd4e5da5Sopenharmony_ci       %2316 = OpExtInst %void %2 DebugNoScope
5311fd4e5da5Sopenharmony_ci               OpSelectionMerge %2139 None
5312fd4e5da5Sopenharmony_ci               OpBranchConditional %2113 %2114 %2139
5313fd4e5da5Sopenharmony_ci       %2114 = OpLabel
5314fd4e5da5Sopenharmony_ci       %2317 = OpExtInst %void %2 DebugScope %74 %2085
5315fd4e5da5Sopenharmony_ci       %2169 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_16 %uint_16
5316fd4e5da5Sopenharmony_ci       %2115 = OpLoad %type_2d_image_array %textureShadowMap
5317fd4e5da5Sopenharmony_ci       %2170 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_40 %uint_40
5318fd4e5da5Sopenharmony_ci       %2116 = OpLoad %type_sampler %samplerShadowMap
5319fd4e5da5Sopenharmony_ci       %2171 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_65 %uint_65
5320fd4e5da5Sopenharmony_ci       %2117 = OpLoad %v4float %2086
5321fd4e5da5Sopenharmony_ci       %2172 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_65 %uint_77
5322fd4e5da5Sopenharmony_ci       %2118 = OpVectorShuffle %v2float %2117 %2117 0 1
5323fd4e5da5Sopenharmony_ci       %2174 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_65 %uint_82
5324fd4e5da5Sopenharmony_ci       %2120 = OpFAdd %v2float %2118 %1963
5325fd4e5da5Sopenharmony_ci       %2122 = OpCompositeExtract %float %2120 0
5326fd4e5da5Sopenharmony_ci       %2123 = OpCompositeExtract %float %2120 1
5327fd4e5da5Sopenharmony_ci       %2178 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_58 %uint_95
5328fd4e5da5Sopenharmony_ci       %2124 = OpCompositeConstruct %v3float %2122 %2123 %1832
5329fd4e5da5Sopenharmony_ci       %2179 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_16 %uint_96
5330fd4e5da5Sopenharmony_ci       %2125 = OpSampledImage %type_sampled_image_0 %2115 %2116
5331fd4e5da5Sopenharmony_ci       %2126 = OpImageSampleImplicitLod %v4float %2125 %2124 None
5332fd4e5da5Sopenharmony_ci       %2181 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_16 %uint_98
5333fd4e5da5Sopenharmony_ci       %2127 = OpCompositeExtract %float %2126 0
5334fd4e5da5Sopenharmony_ci       %2202 = OpExtInst %void %2 DebugLine %64 %uint_45 %uint_45 %uint_3 %uint_98
5335fd4e5da5Sopenharmony_ci       %2201 = OpExtInst %void %2 DebugValue %79 %2127 %243
5336fd4e5da5Sopenharmony_ci       %2184 = OpExtInst %void %2 DebugLine %64 %uint_46 %uint_46 %uint_7 %uint_19
5337fd4e5da5Sopenharmony_ci       %2129 = OpAccessChain %_ptr_Function_float %2086 %int_3
5338fd4e5da5Sopenharmony_ci       %2130 = OpLoad %float %2129
5339fd4e5da5Sopenharmony_ci       %2186 = OpExtInst %void %2 DebugLine %64 %uint_46 %uint_46 %uint_7 %uint_23
5340fd4e5da5Sopenharmony_ci       %2131 = OpFOrdGreaterThan %bool %2130 %float_0
5341fd4e5da5Sopenharmony_ci       %2188 = OpExtInst %void %2 DebugLine %64 %uint_46 %uint_46 %uint_37 %uint_49
5342fd4e5da5Sopenharmony_ci       %2133 = OpAccessChain %_ptr_Function_float %2086 %int_2
5343fd4e5da5Sopenharmony_ci       %2134 = OpLoad %float %2133
5344fd4e5da5Sopenharmony_ci       %2190 = OpExtInst %void %2 DebugLine %64 %uint_46 %uint_46 %uint_30 %uint_49
5345fd4e5da5Sopenharmony_ci       %2135 = OpFOrdLessThan %bool %2127 %2134
5346fd4e5da5Sopenharmony_ci       %2191 = OpExtInst %void %2 DebugLine %64 %uint_46 %uint_46 %uint_7 %uint_49
5347fd4e5da5Sopenharmony_ci       %2136 = OpLogicalAnd %bool %2131 %2135
5348fd4e5da5Sopenharmony_ci       %2318 = OpExtInst %void %2 DebugNoScope
5349fd4e5da5Sopenharmony_ci               OpSelectionMerge %2138 None
5350fd4e5da5Sopenharmony_ci               OpBranchConditional %2136 %2137 %2138
5351fd4e5da5Sopenharmony_ci       %2137 = OpLabel
5352fd4e5da5Sopenharmony_ci       %2319 = OpExtInst %void %2 DebugScope %76 %2085
5353fd4e5da5Sopenharmony_ci       %2194 = OpExtInst %void %2 DebugLine %64 %uint_48 %uint_48 %uint_4 %uint_13
5354fd4e5da5Sopenharmony_ci               OpStore %2083 %float_0_25
5355fd4e5da5Sopenharmony_ci       %2320 = OpExtInst %void %2 DebugScope %74 %2085
5356fd4e5da5Sopenharmony_ci       %2195 = OpExtInst %void %2 DebugLine %64 %uint_49 %uint_49 %uint_3 %uint_3
5357fd4e5da5Sopenharmony_ci               OpBranch %2138
5358fd4e5da5Sopenharmony_ci       %2138 = OpLabel
5359fd4e5da5Sopenharmony_ci       %2321 = OpExtInst %void %2 DebugScope %73 %2085
5360fd4e5da5Sopenharmony_ci       %2196 = OpExtInst %void %2 DebugLine %64 %uint_50 %uint_50 %uint_2 %uint_2
5361fd4e5da5Sopenharmony_ci               OpBranch %2139
5362fd4e5da5Sopenharmony_ci       %2139 = OpLabel
5363fd4e5da5Sopenharmony_ci       %2322 = OpExtInst %void %2 DebugScope %73 %2085
5364fd4e5da5Sopenharmony_ci       %2197 = OpExtInst %void %2 DebugLine %64 %uint_51 %uint_51 %uint_9 %uint_9
5365fd4e5da5Sopenharmony_ci       %2140 = OpLoad %float %2083
5366fd4e5da5Sopenharmony_ci       %2323 = OpExtInst %void %2 DebugScope %106 %1885
5367fd4e5da5Sopenharmony_ci       %2061 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_4 %uint_4
5368fd4e5da5Sopenharmony_ci       %1965 = OpLoad %float %1891
5369fd4e5da5Sopenharmony_ci       %2062 = OpExtInst %void %2 DebugLine %64 %uint_70 %uint_70 %uint_4 %uint_61
5370fd4e5da5Sopenharmony_ci       %1966 = OpFAdd %float %1965 %2140
5371fd4e5da5Sopenharmony_ci               OpStore %1891 %1966
5372fd4e5da5Sopenharmony_ci       %2064 = OpExtInst %void %2 DebugLine %64 %uint_71 %uint_71 %uint_4 %uint_9
5373fd4e5da5Sopenharmony_ci       %1967 = OpLoad %int %1892
5374fd4e5da5Sopenharmony_ci       %1968 = OpIAdd %int %1967 %int_1
5375fd4e5da5Sopenharmony_ci               OpStore %1892 %1968
5376fd4e5da5Sopenharmony_ci       %2324 = OpExtInst %void %2 DebugScope %104 %1885
5377fd4e5da5Sopenharmony_ci       %2067 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_36 %uint_37
5378fd4e5da5Sopenharmony_ci               OpBranch %1969
5379fd4e5da5Sopenharmony_ci       %1969 = OpLabel
5380fd4e5da5Sopenharmony_ci       %2325 = OpExtInst %void %2 DebugScope %104 %1885
5381fd4e5da5Sopenharmony_ci       %2068 = OpExtInst %void %2 DebugLine %64 %uint_68 %uint_68 %uint_36 %uint_37
5382fd4e5da5Sopenharmony_ci       %1970 = OpLoad %int %1895
5383fd4e5da5Sopenharmony_ci       %1971 = OpIAdd %int %1970 %int_1
5384fd4e5da5Sopenharmony_ci               OpStore %1895 %1971
5385fd4e5da5Sopenharmony_ci               OpBranch %1948
5386fd4e5da5Sopenharmony_ci       %1972 = OpLabel
5387fd4e5da5Sopenharmony_ci       %2326 = OpExtInst %void %2 DebugScope %103 %1885
5388fd4e5da5Sopenharmony_ci       %2072 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_35 %uint_36
5389fd4e5da5Sopenharmony_ci               OpBranch %1973
5390fd4e5da5Sopenharmony_ci       %1973 = OpLabel
5391fd4e5da5Sopenharmony_ci       %2327 = OpExtInst %void %2 DebugScope %103 %1885
5392fd4e5da5Sopenharmony_ci       %2073 = OpExtInst %void %2 DebugLine %64 %uint_66 %uint_66 %uint_35 %uint_36
5393fd4e5da5Sopenharmony_ci       %1974 = OpLoad %int %1894
5394fd4e5da5Sopenharmony_ci       %1975 = OpIAdd %int %1974 %int_1
5395fd4e5da5Sopenharmony_ci               OpStore %1894 %1975
5396fd4e5da5Sopenharmony_ci               OpBranch %1940
5397fd4e5da5Sopenharmony_ci       %1976 = OpLabel
5398fd4e5da5Sopenharmony_ci       %2328 = OpExtInst %void %2 DebugScope %103 %1885
5399fd4e5da5Sopenharmony_ci       %2077 = OpExtInst %void %2 DebugLine %64 %uint_75 %uint_75 %uint_9 %uint_9
5400fd4e5da5Sopenharmony_ci       %1977 = OpLoad %float %1891
5401fd4e5da5Sopenharmony_ci       %2078 = OpExtInst %void %2 DebugLine %64 %uint_75 %uint_75 %uint_24 %uint_24
5402fd4e5da5Sopenharmony_ci       %1978 = OpLoad %int %1892
5403fd4e5da5Sopenharmony_ci       %1979 = OpConvertSToF %float %1978
5404fd4e5da5Sopenharmony_ci       %2080 = OpExtInst %void %2 DebugLine %64 %uint_75 %uint_75 %uint_9 %uint_24
5405fd4e5da5Sopenharmony_ci       %1980 = OpFDiv %float %1977 %1979
5406fd4e5da5Sopenharmony_ci       %2329 = OpExtInst %void %2 DebugScope %158 %1803
5407fd4e5da5Sopenharmony_ci       %2232 = OpExtInst %void %2 DebugLine %64 %uint_85 %uint_85 %uint_4 %uint_41
5408fd4e5da5Sopenharmony_ci       %2231 = OpExtInst %void %2 DebugValue %160 %1980 %243
5409fd4e5da5Sopenharmony_ci       %1872 = OpExtInst %void %2 DebugLine %64 %uint_90 %uint_90 %uint_3 %uint_3
5410fd4e5da5Sopenharmony_ci       %1835 = OpLoad %v3float %1466
5411fd4e5da5Sopenharmony_ci       %1873 = OpExtInst %void %2 DebugLine %64 %uint_90 %uint_90 %uint_3 %uint_16
5412fd4e5da5Sopenharmony_ci       %1836 = OpVectorTimesScalar %v3float %1835 %1980
5413fd4e5da5Sopenharmony_ci               OpStore %1466 %1836
5414fd4e5da5Sopenharmony_ci       %2330 = OpExtInst %void %2 DebugScope %157 %1803
5415fd4e5da5Sopenharmony_ci       %1875 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_35 %uint_37
5416fd4e5da5Sopenharmony_ci               OpBranch %1837
5417fd4e5da5Sopenharmony_ci       %1837 = OpLabel
5418fd4e5da5Sopenharmony_ci       %2331 = OpExtInst %void %2 DebugScope %157 %1803
5419fd4e5da5Sopenharmony_ci       %1876 = OpExtInst %void %2 DebugLine %64 %uint_79 %uint_79 %uint_35 %uint_37
5420fd4e5da5Sopenharmony_ci       %1838 = OpLoad %int %1801
5421fd4e5da5Sopenharmony_ci       %1839 = OpIAdd %int %1838 %int_1
5422fd4e5da5Sopenharmony_ci               OpStore %1801 %1839
5423fd4e5da5Sopenharmony_ci               OpBranch %1814
5424fd4e5da5Sopenharmony_ci       %1840 = OpLabel
5425fd4e5da5Sopenharmony_ci       %2332 = OpExtInst %void %2 DebugScope %157 %1803
5426fd4e5da5Sopenharmony_ci       %1880 = OpExtInst %void %2 DebugLine %64 %uint_92 %uint_92 %uint_9 %uint_9
5427fd4e5da5Sopenharmony_ci       %1841 = OpLoad %v3float %1466
5428fd4e5da5Sopenharmony_ci       %2333 = OpExtInst %void %2 DebugScope %180
5429fd4e5da5Sopenharmony_ci       %1793 = OpExtInst %void %2 DebugLine %64 %uint_146 %uint_146 %uint_3 %uint_40
5430fd4e5da5Sopenharmony_ci               OpStore %1448 %1841
5431fd4e5da5Sopenharmony_ci       %2334 = OpExtInst %void %2 DebugScope %179
5432fd4e5da5Sopenharmony_ci       %1794 = OpExtInst %void %2 DebugLine %64 %uint_147 %uint_147 %uint_2 %uint_2
5433fd4e5da5Sopenharmony_ci               OpBranch %1614
5434fd4e5da5Sopenharmony_ci       %1614 = OpLabel
5435fd4e5da5Sopenharmony_ci;CHECK:      %1614 = OpLabel
5436fd4e5da5Sopenharmony_ci;CHECK-NEXT: [[phi:%\w+]] = OpPhi
5437fd4e5da5Sopenharmony_ci;CHECK-NEXT: {{%\w+}} = OpExtInst %void {{%\w+}} DebugValue %233
5438fd4e5da5Sopenharmony_ci       %2335 = OpExtInst %void %2 DebugScope %179
5439fd4e5da5Sopenharmony_ci       %1795 = OpExtInst %void %2 DebugLine %64 %uint_149 %uint_149 %uint_16 %uint_16
5440fd4e5da5Sopenharmony_ci       %1615 = OpLoad %v3float %1448
5441fd4e5da5Sopenharmony_ci       %1616 = OpCompositeExtract %float %1615 0
5442fd4e5da5Sopenharmony_ci       %1617 = OpCompositeExtract %float %1615 1
5443fd4e5da5Sopenharmony_ci       %1618 = OpCompositeExtract %float %1615 2
5444fd4e5da5Sopenharmony_ci       %1799 = OpExtInst %void %2 DebugLine %64 %uint_149 %uint_149 %uint_9 %uint_28
5445fd4e5da5Sopenharmony_ci       %1619 = OpCompositeConstruct %v4float %1616 %1617 %1618 %float_1
5446fd4e5da5Sopenharmony_ci       %2336 = OpExtInst %void %2 DebugNoLine
5447fd4e5da5Sopenharmony_ci       %2337 = OpExtInst %void %2 DebugNoScope
5448fd4e5da5Sopenharmony_ci               OpStore %out_var_SV_TARGET %1619
5449fd4e5da5Sopenharmony_ci        %329 = OpExtInst %void %2 DebugLine %64 %uint_150 %uint_150 %uint_1 %uint_1
5450fd4e5da5Sopenharmony_ci               OpReturn
5451fd4e5da5Sopenharmony_ci               OpFunctionEnd
5452fd4e5da5Sopenharmony_ci)";
5453fd4e5da5Sopenharmony_ci
5454fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
5455fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5456fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<SSARewritePass>(text, true);
5457fd4e5da5Sopenharmony_ci}
5458fd4e5da5Sopenharmony_ci
5459fd4e5da5Sopenharmony_ci// TODO(greg-lunarg): Add tests to verify handling of these cases:
5460fd4e5da5Sopenharmony_ci//
5461fd4e5da5Sopenharmony_ci//    No optimization in the presence of
5462fd4e5da5Sopenharmony_ci//      access chains
5463fd4e5da5Sopenharmony_ci//      function calls
5464fd4e5da5Sopenharmony_ci//      OpCopyMemory?
5465fd4e5da5Sopenharmony_ci//      unsupported extensions
5466fd4e5da5Sopenharmony_ci//    Others?
5467fd4e5da5Sopenharmony_ci
5468fd4e5da5Sopenharmony_ci}  // namespace
5469fd4e5da5Sopenharmony_ci}  // namespace opt
5470fd4e5da5Sopenharmony_ci}  // namespace spvtools
5471