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 <string>
17fd4e5da5Sopenharmony_ci#include <vector>
18fd4e5da5Sopenharmony_ci
19fd4e5da5Sopenharmony_ci#include "test/opt/assembly_builder.h"
20fd4e5da5Sopenharmony_ci#include "test/opt/pass_fixture.h"
21fd4e5da5Sopenharmony_ci#include "test/opt/pass_utils.h"
22fd4e5da5Sopenharmony_ci
23fd4e5da5Sopenharmony_cinamespace spvtools {
24fd4e5da5Sopenharmony_cinamespace opt {
25fd4e5da5Sopenharmony_cinamespace {
26fd4e5da5Sopenharmony_ci
27fd4e5da5Sopenharmony_ciusing AggressiveDCETest = PassTest<::testing::Test>;
28fd4e5da5Sopenharmony_ci
29fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateExtendedInst) {
30fd4e5da5Sopenharmony_ci  //  #version 140
31fd4e5da5Sopenharmony_ci  //
32fd4e5da5Sopenharmony_ci  //  in vec4 BaseColor;
33fd4e5da5Sopenharmony_ci  //  in vec4 Dead;
34fd4e5da5Sopenharmony_ci  //
35fd4e5da5Sopenharmony_ci  //  void main()
36fd4e5da5Sopenharmony_ci  //  {
37fd4e5da5Sopenharmony_ci  //      vec4 v = BaseColor;
38fd4e5da5Sopenharmony_ci  //      vec4 dv = sqrt(Dead);
39fd4e5da5Sopenharmony_ci  //      gl_FragColor = v;
40fd4e5da5Sopenharmony_ci  //  }
41fd4e5da5Sopenharmony_ci  const std::string spirv = R"(
42fd4e5da5Sopenharmony_ciOpCapability Shader
43fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
44fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
45fd4e5da5Sopenharmony_ci; CHECK: OpEntryPoint Fragment %main "main" %BaseColor %gl_FragColor
46fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %Dead %gl_FragColor
47fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
48fd4e5da5Sopenharmony_ciOpSource GLSL 140
49fd4e5da5Sopenharmony_ciOpName %main "main"
50fd4e5da5Sopenharmony_ciOpName %v "v"
51fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
52fd4e5da5Sopenharmony_ci; CHECK-NOT: OpName %dv "dv"
53fd4e5da5Sopenharmony_ciOpName %dv "dv"
54fd4e5da5Sopenharmony_ci; CHECK-NOT: OpName %Dead "Dead"
55fd4e5da5Sopenharmony_ciOpName %Dead "Dead"
56fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
57fd4e5da5Sopenharmony_ci%void = OpTypeVoid
58fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
59fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
60fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
61fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
62fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
63fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
64fd4e5da5Sopenharmony_ci; CHECK-NOT: %Dead = OpVariable
65fd4e5da5Sopenharmony_ci%Dead = OpVariable %_ptr_Input_v4float Input
66fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
67fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
68fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
69fd4e5da5Sopenharmony_ci%15 = OpLabel
70fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
71fd4e5da5Sopenharmony_ci; CHECK-NOT: %dv = OpVariable
72fd4e5da5Sopenharmony_ci%dv = OpVariable %_ptr_Function_v4float Function
73fd4e5da5Sopenharmony_ci%16 = OpLoad %v4float %BaseColor
74fd4e5da5Sopenharmony_ciOpStore %v %16
75fd4e5da5Sopenharmony_ci; CHECK-NOT: OpLoad %v4float %Dead
76fd4e5da5Sopenharmony_ci%17 = OpLoad %v4float %Dead
77fd4e5da5Sopenharmony_ci; CHECK-NOT: OpExtInst %v4float %1 Sqrt
78fd4e5da5Sopenharmony_ci%18 = OpExtInst %v4float %1 Sqrt %17
79fd4e5da5Sopenharmony_ci; CHECK-NOT: OpStore %dv
80fd4e5da5Sopenharmony_ciOpStore %dv %18
81fd4e5da5Sopenharmony_ci%19 = OpLoad %v4float %v
82fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %19
83fd4e5da5Sopenharmony_ciOpReturn
84fd4e5da5Sopenharmony_ciOpFunctionEnd
85fd4e5da5Sopenharmony_ci)";
86fd4e5da5Sopenharmony_ci
87fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
88fd4e5da5Sopenharmony_ci}
89fd4e5da5Sopenharmony_ci
90fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateFrexp) {
91fd4e5da5Sopenharmony_ci  // Note: SPIR-V hand-edited to utilize Frexp
92fd4e5da5Sopenharmony_ci  //
93fd4e5da5Sopenharmony_ci  // #version 450
94fd4e5da5Sopenharmony_ci  //
95fd4e5da5Sopenharmony_ci  // in vec4 BaseColor;
96fd4e5da5Sopenharmony_ci  // in vec4 Dead;
97fd4e5da5Sopenharmony_ci  // out vec4 Color;
98fd4e5da5Sopenharmony_ci  // out ivec4 iv2;
99fd4e5da5Sopenharmony_ci  //
100fd4e5da5Sopenharmony_ci  // void main()
101fd4e5da5Sopenharmony_ci  // {
102fd4e5da5Sopenharmony_ci  //     vec4 v = BaseColor;
103fd4e5da5Sopenharmony_ci  //     vec4 dv = frexp(Dead, iv2);
104fd4e5da5Sopenharmony_ci  //     Color = v;
105fd4e5da5Sopenharmony_ci  // }
106fd4e5da5Sopenharmony_ci
107fd4e5da5Sopenharmony_ci  const std::string predefs1 =
108fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
109fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
110fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
111fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %Dead %iv2 %Color
112fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
113fd4e5da5Sopenharmony_ciOpSource GLSL 450
114fd4e5da5Sopenharmony_ci)";
115fd4e5da5Sopenharmony_ci
116fd4e5da5Sopenharmony_ci  const std::string names_before =
117fd4e5da5Sopenharmony_ci      R"(OpName %main "main"
118fd4e5da5Sopenharmony_ciOpName %v "v"
119fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
120fd4e5da5Sopenharmony_ciOpName %dv "dv"
121fd4e5da5Sopenharmony_ciOpName %Dead "Dead"
122fd4e5da5Sopenharmony_ciOpName %iv2 "iv2"
123fd4e5da5Sopenharmony_ciOpName %ResType "ResType"
124fd4e5da5Sopenharmony_ciOpName %Color "Color"
125fd4e5da5Sopenharmony_ci)";
126fd4e5da5Sopenharmony_ci
127fd4e5da5Sopenharmony_ci  const std::string names_after =
128fd4e5da5Sopenharmony_ci      R"(OpName %main "main"
129fd4e5da5Sopenharmony_ciOpName %v "v"
130fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
131fd4e5da5Sopenharmony_ciOpName %Dead "Dead"
132fd4e5da5Sopenharmony_ciOpName %iv2 "iv2"
133fd4e5da5Sopenharmony_ciOpName %Color "Color"
134fd4e5da5Sopenharmony_ci)";
135fd4e5da5Sopenharmony_ci
136fd4e5da5Sopenharmony_ci  const std::string predefs2_before =
137fd4e5da5Sopenharmony_ci      R"(%void = OpTypeVoid
138fd4e5da5Sopenharmony_ci%11 = OpTypeFunction %void
139fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
140fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
141fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
142fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
143fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
144fd4e5da5Sopenharmony_ci%Dead = OpVariable %_ptr_Input_v4float Input
145fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
146fd4e5da5Sopenharmony_ci%v4int = OpTypeVector %int 4
147fd4e5da5Sopenharmony_ci%_ptr_Output_v4int = OpTypePointer Output %v4int
148fd4e5da5Sopenharmony_ci%iv2 = OpVariable %_ptr_Output_v4int Output
149fd4e5da5Sopenharmony_ci%ResType = OpTypeStruct %v4float %v4int
150fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
151fd4e5da5Sopenharmony_ci%Color = OpVariable %_ptr_Output_v4float Output
152fd4e5da5Sopenharmony_ci)";
153fd4e5da5Sopenharmony_ci
154fd4e5da5Sopenharmony_ci  const std::string predefs2_after =
155fd4e5da5Sopenharmony_ci      R"(%void = OpTypeVoid
156fd4e5da5Sopenharmony_ci%11 = OpTypeFunction %void
157fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
158fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
159fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
160fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
161fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
162fd4e5da5Sopenharmony_ci%Dead = OpVariable %_ptr_Input_v4float Input
163fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
164fd4e5da5Sopenharmony_ci%v4int = OpTypeVector %int 4
165fd4e5da5Sopenharmony_ci%_ptr_Output_v4int = OpTypePointer Output %v4int
166fd4e5da5Sopenharmony_ci%iv2 = OpVariable %_ptr_Output_v4int Output
167fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
168fd4e5da5Sopenharmony_ci%Color = OpVariable %_ptr_Output_v4float Output
169fd4e5da5Sopenharmony_ci)";
170fd4e5da5Sopenharmony_ci
171fd4e5da5Sopenharmony_ci  const std::string func_before =
172fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %11
173fd4e5da5Sopenharmony_ci%20 = OpLabel
174fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
175fd4e5da5Sopenharmony_ci%dv = OpVariable %_ptr_Function_v4float Function
176fd4e5da5Sopenharmony_ci%21 = OpLoad %v4float %BaseColor
177fd4e5da5Sopenharmony_ciOpStore %v %21
178fd4e5da5Sopenharmony_ci%22 = OpLoad %v4float %Dead
179fd4e5da5Sopenharmony_ci%23 = OpExtInst %v4float %1 Frexp %22 %iv2
180fd4e5da5Sopenharmony_ciOpStore %dv %23
181fd4e5da5Sopenharmony_ci%24 = OpLoad %v4float %v
182fd4e5da5Sopenharmony_ciOpStore %Color %24
183fd4e5da5Sopenharmony_ciOpReturn
184fd4e5da5Sopenharmony_ciOpFunctionEnd
185fd4e5da5Sopenharmony_ci)";
186fd4e5da5Sopenharmony_ci
187fd4e5da5Sopenharmony_ci  const std::string func_after =
188fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %11
189fd4e5da5Sopenharmony_ci%20 = OpLabel
190fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
191fd4e5da5Sopenharmony_ci%21 = OpLoad %v4float %BaseColor
192fd4e5da5Sopenharmony_ciOpStore %v %21
193fd4e5da5Sopenharmony_ci%22 = OpLoad %v4float %Dead
194fd4e5da5Sopenharmony_ci%23 = OpExtInst %v4float %1 Frexp %22 %iv2
195fd4e5da5Sopenharmony_ci%24 = OpLoad %v4float %v
196fd4e5da5Sopenharmony_ciOpStore %Color %24
197fd4e5da5Sopenharmony_ciOpReturn
198fd4e5da5Sopenharmony_ciOpFunctionEnd
199fd4e5da5Sopenharmony_ci)";
200fd4e5da5Sopenharmony_ci
201fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(
202fd4e5da5Sopenharmony_ci      predefs1 + names_before + predefs2_before + func_before,
203fd4e5da5Sopenharmony_ci      predefs1 + names_after + predefs2_after + func_after, true, true);
204fd4e5da5Sopenharmony_ci}
205fd4e5da5Sopenharmony_ci
206fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateDecorate) {
207fd4e5da5Sopenharmony_ci  // Note: The SPIR-V was hand-edited to add the OpDecorate
208fd4e5da5Sopenharmony_ci  //
209fd4e5da5Sopenharmony_ci  // #version 140
210fd4e5da5Sopenharmony_ci  //
211fd4e5da5Sopenharmony_ci  // in vec4 BaseColor;
212fd4e5da5Sopenharmony_ci  // in vec4 Dead;
213fd4e5da5Sopenharmony_ci  //
214fd4e5da5Sopenharmony_ci  // void main()
215fd4e5da5Sopenharmony_ci  // {
216fd4e5da5Sopenharmony_ci  //     vec4 v = BaseColor;
217fd4e5da5Sopenharmony_ci  //     vec4 dv = Dead * 0.5;
218fd4e5da5Sopenharmony_ci  //     gl_FragColor = v;
219fd4e5da5Sopenharmony_ci  // }
220fd4e5da5Sopenharmony_ci
221fd4e5da5Sopenharmony_ci  const std::string spirv =
222fd4e5da5Sopenharmony_ci      R"(
223fd4e5da5Sopenharmony_ciOpCapability Shader
224fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
225fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
226fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %Dead %gl_FragColor
227fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
228fd4e5da5Sopenharmony_ciOpSource GLSL 140
229fd4e5da5Sopenharmony_ciOpName %main "main"
230fd4e5da5Sopenharmony_ciOpName %v "v"
231fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
232fd4e5da5Sopenharmony_ciOpName %dv "dv"
233fd4e5da5Sopenharmony_ciOpName %Dead "Dead"
234fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
235fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorate
236fd4e5da5Sopenharmony_ciOpDecorate %8 RelaxedPrecision
237fd4e5da5Sopenharmony_ci%void = OpTypeVoid
238fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
239fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
240fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
241fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
242fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
243fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
244fd4e5da5Sopenharmony_ci%Dead = OpVariable %_ptr_Input_v4float Input
245fd4e5da5Sopenharmony_ci%float_0_5 = OpConstant %float 0.5
246fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
247fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
248fd4e5da5Sopenharmony_ci%main = OpFunction %void None %10
249fd4e5da5Sopenharmony_ci%17 = OpLabel
250fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
251fd4e5da5Sopenharmony_ci%dv = OpVariable %_ptr_Function_v4float Function
252fd4e5da5Sopenharmony_ci%18 = OpLoad %v4float %BaseColor
253fd4e5da5Sopenharmony_ciOpStore %v %18
254fd4e5da5Sopenharmony_ci%19 = OpLoad %v4float %Dead
255fd4e5da5Sopenharmony_ci; CHECK-NOT: OpVectorTimesScalar
256fd4e5da5Sopenharmony_ci%8 = OpVectorTimesScalar %v4float %19 %float_0_5
257fd4e5da5Sopenharmony_ciOpStore %dv %8
258fd4e5da5Sopenharmony_ci%20 = OpLoad %v4float %v
259fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %20
260fd4e5da5Sopenharmony_ciOpReturn
261fd4e5da5Sopenharmony_ciOpFunctionEnd
262fd4e5da5Sopenharmony_ci)";
263fd4e5da5Sopenharmony_ci
264fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
265fd4e5da5Sopenharmony_ci}
266fd4e5da5Sopenharmony_ci
267fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, Simple) {
268fd4e5da5Sopenharmony_ci  //  #version 140
269fd4e5da5Sopenharmony_ci  //
270fd4e5da5Sopenharmony_ci  //  in vec4 BaseColor;
271fd4e5da5Sopenharmony_ci  //  in vec4 Dead;
272fd4e5da5Sopenharmony_ci  //
273fd4e5da5Sopenharmony_ci  //  void main()
274fd4e5da5Sopenharmony_ci  //  {
275fd4e5da5Sopenharmony_ci  //      vec4 v = BaseColor;
276fd4e5da5Sopenharmony_ci  //      vec4 dv = Dead;
277fd4e5da5Sopenharmony_ci  //      gl_FragColor = v;
278fd4e5da5Sopenharmony_ci  //  }
279fd4e5da5Sopenharmony_ci
280fd4e5da5Sopenharmony_ci  const std::string spirv =
281fd4e5da5Sopenharmony_ci      R"(
282fd4e5da5Sopenharmony_ciOpCapability Shader
283fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
284fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
285fd4e5da5Sopenharmony_ci; CHECK: OpEntryPoint Fragment %main "main" %BaseColor %gl_FragColor
286fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %Dead %gl_FragColor
287fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
288fd4e5da5Sopenharmony_ciOpSource GLSL 140
289fd4e5da5Sopenharmony_ciOpName %main "main"
290fd4e5da5Sopenharmony_ciOpName %v "v"
291fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
292fd4e5da5Sopenharmony_ci; CHECK-NOT: OpName %dv "dv"
293fd4e5da5Sopenharmony_ciOpName %dv "dv"
294fd4e5da5Sopenharmony_ci; CHECK-NOT: OpName %Dead "Dead"
295fd4e5da5Sopenharmony_ciOpName %Dead "Dead"
296fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
297fd4e5da5Sopenharmony_ci%void = OpTypeVoid
298fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
299fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
300fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
301fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
302fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
303fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
304fd4e5da5Sopenharmony_ci; CHECK-NOT: %Dead = OpVariable
305fd4e5da5Sopenharmony_ci%Dead = OpVariable %_ptr_Input_v4float Input
306fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
307fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
308fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
309fd4e5da5Sopenharmony_ci%15 = OpLabel
310fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
311fd4e5da5Sopenharmony_ci; CHECK-NOT: %dv = OpVariable
312fd4e5da5Sopenharmony_ci%dv = OpVariable %_ptr_Function_v4float Function
313fd4e5da5Sopenharmony_ci%16 = OpLoad %v4float %BaseColor
314fd4e5da5Sopenharmony_ciOpStore %v %16
315fd4e5da5Sopenharmony_ci; CHECK-NOT: OpLoad %v4float %Dead
316fd4e5da5Sopenharmony_ci%17 = OpLoad %v4float %Dead
317fd4e5da5Sopenharmony_ci; CHECK-NOT: OpStore %dv
318fd4e5da5Sopenharmony_ciOpStore %dv %17
319fd4e5da5Sopenharmony_ci%18 = OpLoad %v4float %v
320fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %18
321fd4e5da5Sopenharmony_ciOpReturn
322fd4e5da5Sopenharmony_ciOpFunctionEnd
323fd4e5da5Sopenharmony_ci)";
324fd4e5da5Sopenharmony_ci
325fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
326fd4e5da5Sopenharmony_ci}
327fd4e5da5Sopenharmony_ci
328fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, OptAllowListExtension) {
329fd4e5da5Sopenharmony_ci  //  #version 140
330fd4e5da5Sopenharmony_ci  //
331fd4e5da5Sopenharmony_ci  //  in vec4 BaseColor;
332fd4e5da5Sopenharmony_ci  //  in vec4 Dead;
333fd4e5da5Sopenharmony_ci  //
334fd4e5da5Sopenharmony_ci  //  void main()
335fd4e5da5Sopenharmony_ci  //  {
336fd4e5da5Sopenharmony_ci  //      vec4 v = BaseColor;
337fd4e5da5Sopenharmony_ci  //      vec4 dv = Dead;
338fd4e5da5Sopenharmony_ci  //      gl_FragColor = v;
339fd4e5da5Sopenharmony_ci  //  }
340fd4e5da5Sopenharmony_ci
341fd4e5da5Sopenharmony_ci  const std::string spirv =
342fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
343fd4e5da5Sopenharmony_ciOpExtension "SPV_AMD_gpu_shader_int16"
344fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
345fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
346fd4e5da5Sopenharmony_ci; CHECK: OpEntryPoint Fragment %main "main" %BaseColor %gl_FragColor
347fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %Dead %gl_FragColor
348fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
349fd4e5da5Sopenharmony_ciOpSource GLSL 140
350fd4e5da5Sopenharmony_ciOpName %main "main"
351fd4e5da5Sopenharmony_ciOpName %v "v"
352fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
353fd4e5da5Sopenharmony_ciOpName %dv "dv"
354fd4e5da5Sopenharmony_ciOpName %Dead "Dead"
355fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
356fd4e5da5Sopenharmony_ci%void = OpTypeVoid
357fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
358fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
359fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
360fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
361fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
362fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
363fd4e5da5Sopenharmony_ci%Dead = OpVariable %_ptr_Input_v4float Input
364fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
365fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
366fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
367fd4e5da5Sopenharmony_ci%15 = OpLabel
368fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
369fd4e5da5Sopenharmony_ci%dv = OpVariable %_ptr_Function_v4float Function
370fd4e5da5Sopenharmony_ci%16 = OpLoad %v4float %BaseColor
371fd4e5da5Sopenharmony_ciOpStore %v %16
372fd4e5da5Sopenharmony_ci%17 = OpLoad %v4float %Dead
373fd4e5da5Sopenharmony_ciOpStore %dv %17
374fd4e5da5Sopenharmony_ci%18 = OpLoad %v4float %v
375fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %18
376fd4e5da5Sopenharmony_ciOpReturn
377fd4e5da5Sopenharmony_ciOpFunctionEnd
378fd4e5da5Sopenharmony_ci)";
379fd4e5da5Sopenharmony_ci
380fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
381fd4e5da5Sopenharmony_ci}
382fd4e5da5Sopenharmony_ci
383fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoOptDenyListExtension) {
384fd4e5da5Sopenharmony_ci  //  #version 140
385fd4e5da5Sopenharmony_ci  //
386fd4e5da5Sopenharmony_ci  //  in vec4 BaseColor;
387fd4e5da5Sopenharmony_ci  //  in vec4 Dead;
388fd4e5da5Sopenharmony_ci  //
389fd4e5da5Sopenharmony_ci  //  void main()
390fd4e5da5Sopenharmony_ci  //  {
391fd4e5da5Sopenharmony_ci  //      vec4 v = BaseColor;
392fd4e5da5Sopenharmony_ci  //      vec4 dv = Dead;
393fd4e5da5Sopenharmony_ci  //      gl_FragColor = v;
394fd4e5da5Sopenharmony_ci  //  }
395fd4e5da5Sopenharmony_ci
396fd4e5da5Sopenharmony_ci  const std::string assembly =
397fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
398fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_variable_pointers"
399fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
400fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
401fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %Dead %gl_FragColor
402fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
403fd4e5da5Sopenharmony_ciOpSource GLSL 140
404fd4e5da5Sopenharmony_ciOpName %main "main"
405fd4e5da5Sopenharmony_ciOpName %v "v"
406fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
407fd4e5da5Sopenharmony_ciOpName %dv "dv"
408fd4e5da5Sopenharmony_ciOpName %Dead "Dead"
409fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
410fd4e5da5Sopenharmony_ci%void = OpTypeVoid
411fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
412fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
413fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
414fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
415fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
416fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
417fd4e5da5Sopenharmony_ci%Dead = OpVariable %_ptr_Input_v4float Input
418fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
419fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
420fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
421fd4e5da5Sopenharmony_ci%15 = OpLabel
422fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
423fd4e5da5Sopenharmony_ci%dv = OpVariable %_ptr_Function_v4float Function
424fd4e5da5Sopenharmony_ci%16 = OpLoad %v4float %BaseColor
425fd4e5da5Sopenharmony_ciOpStore %v %16
426fd4e5da5Sopenharmony_ci%17 = OpLoad %v4float %Dead
427fd4e5da5Sopenharmony_ciOpStore %dv %17
428fd4e5da5Sopenharmony_ci%18 = OpLoad %v4float %v
429fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %18
430fd4e5da5Sopenharmony_ciOpReturn
431fd4e5da5Sopenharmony_ciOpFunctionEnd
432fd4e5da5Sopenharmony_ci)";
433fd4e5da5Sopenharmony_ci
434fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
435fd4e5da5Sopenharmony_ci}
436fd4e5da5Sopenharmony_ci
437fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, ElimWithCall) {
438fd4e5da5Sopenharmony_ci  // This demonstrates that "dead" function calls are not eliminated.
439fd4e5da5Sopenharmony_ci  // Also demonstrates that DCE will happen in presence of function call.
440fd4e5da5Sopenharmony_ci  // #version 140
441fd4e5da5Sopenharmony_ci  // in vec4 i1;
442fd4e5da5Sopenharmony_ci  // in vec4 i2;
443fd4e5da5Sopenharmony_ci  //
444fd4e5da5Sopenharmony_ci  // void nothing(vec4 v)
445fd4e5da5Sopenharmony_ci  // {
446fd4e5da5Sopenharmony_ci  // }
447fd4e5da5Sopenharmony_ci  //
448fd4e5da5Sopenharmony_ci  // void main()
449fd4e5da5Sopenharmony_ci  // {
450fd4e5da5Sopenharmony_ci  //     vec4 v1 = i1;
451fd4e5da5Sopenharmony_ci  //     vec4 v2 = i2;
452fd4e5da5Sopenharmony_ci  //     nothing(v1);
453fd4e5da5Sopenharmony_ci  //     gl_FragColor = vec4(0.0);
454fd4e5da5Sopenharmony_ci  // }
455fd4e5da5Sopenharmony_ci
456fd4e5da5Sopenharmony_ci  const std::string text =
457fd4e5da5Sopenharmony_ci      R"( OpCapability Shader
458fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
459fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
460fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %i1 %i2 %gl_FragColor
461fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
462fd4e5da5Sopenharmony_ciOpSource GLSL 140
463fd4e5da5Sopenharmony_ciOpName %main "main"
464fd4e5da5Sopenharmony_ciOpName %nothing_vf4_ "nothing(vf4;"
465fd4e5da5Sopenharmony_ciOpName %v "v"
466fd4e5da5Sopenharmony_ciOpName %v1 "v1"
467fd4e5da5Sopenharmony_ciOpName %i1 "i1"
468fd4e5da5Sopenharmony_ciOpName %v2 "v2"
469fd4e5da5Sopenharmony_ciOpName %i2 "i2"
470fd4e5da5Sopenharmony_ciOpName %param "param"
471fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
472fd4e5da5Sopenharmony_ci%void = OpTypeVoid
473fd4e5da5Sopenharmony_ci%12 = OpTypeFunction %void
474fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
475fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
476fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
477fd4e5da5Sopenharmony_ci%16 = OpTypeFunction %void %_ptr_Function_v4float
478fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
479fd4e5da5Sopenharmony_ci%i1 = OpVariable %_ptr_Input_v4float Input
480fd4e5da5Sopenharmony_ci%i2 = OpVariable %_ptr_Input_v4float Input
481fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
482fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
483fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
484fd4e5da5Sopenharmony_ci%20 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
485fd4e5da5Sopenharmony_ci%main = OpFunction %void None %12
486fd4e5da5Sopenharmony_ci%21 = OpLabel
487fd4e5da5Sopenharmony_ci%v1 = OpVariable %_ptr_Function_v4float Function
488fd4e5da5Sopenharmony_ci%v2 = OpVariable %_ptr_Function_v4float Function
489fd4e5da5Sopenharmony_ci%param = OpVariable %_ptr_Function_v4float Function
490fd4e5da5Sopenharmony_ci%22 = OpLoad %v4float %i1
491fd4e5da5Sopenharmony_ciOpStore %v1 %22
492fd4e5da5Sopenharmony_ci; CHECK-NOT: OpLoad %v4float %i2
493fd4e5da5Sopenharmony_ci%23 = OpLoad %v4float %i2
494fd4e5da5Sopenharmony_ci; CHECK-NOT: OpStore %v2
495fd4e5da5Sopenharmony_ciOpStore %v2 %23
496fd4e5da5Sopenharmony_ci%24 = OpLoad %v4float %v1
497fd4e5da5Sopenharmony_ciOpStore %param %24
498fd4e5da5Sopenharmony_ci; CHECK: OpFunctionCall %void %nothing_vf4_
499fd4e5da5Sopenharmony_ci%25 = OpFunctionCall %void %nothing_vf4_ %param
500fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %20
501fd4e5da5Sopenharmony_ciOpReturn
502fd4e5da5Sopenharmony_ciOpFunctionEnd
503fd4e5da5Sopenharmony_ci; CHECK: %nothing_vf4_ = OpFunction
504fd4e5da5Sopenharmony_ci%nothing_vf4_ = OpFunction %void None %16
505fd4e5da5Sopenharmony_ci%v = OpFunctionParameter %_ptr_Function_v4float
506fd4e5da5Sopenharmony_ci%26 = OpLabel
507fd4e5da5Sopenharmony_ciOpReturn
508fd4e5da5Sopenharmony_ciOpFunctionEnd
509fd4e5da5Sopenharmony_ci)";
510fd4e5da5Sopenharmony_ci
511fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
512fd4e5da5Sopenharmony_ci}
513fd4e5da5Sopenharmony_ci
514fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoParamElim) {
515fd4e5da5Sopenharmony_ci  // This demonstrates that unused parameters are not eliminated, but
516fd4e5da5Sopenharmony_ci  // dead uses of them are.
517fd4e5da5Sopenharmony_ci  // #version 140
518fd4e5da5Sopenharmony_ci  //
519fd4e5da5Sopenharmony_ci  // in vec4 BaseColor;
520fd4e5da5Sopenharmony_ci  //
521fd4e5da5Sopenharmony_ci  // vec4 foo(vec4 v1, vec4 v2)
522fd4e5da5Sopenharmony_ci  // {
523fd4e5da5Sopenharmony_ci  //     vec4 t = -v1;
524fd4e5da5Sopenharmony_ci  //     return v2;
525fd4e5da5Sopenharmony_ci  // }
526fd4e5da5Sopenharmony_ci  //
527fd4e5da5Sopenharmony_ci  // void main()
528fd4e5da5Sopenharmony_ci  // {
529fd4e5da5Sopenharmony_ci  //     vec4 dead;
530fd4e5da5Sopenharmony_ci  //     gl_FragColor = foo(dead, BaseColor);
531fd4e5da5Sopenharmony_ci  // }
532fd4e5da5Sopenharmony_ci
533fd4e5da5Sopenharmony_ci  const std::string defs_before =
534fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
535fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
536fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
537fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %gl_FragColor %BaseColor
538fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
539fd4e5da5Sopenharmony_ciOpSource GLSL 140
540fd4e5da5Sopenharmony_ciOpName %main "main"
541fd4e5da5Sopenharmony_ciOpName %foo_vf4_vf4_ "foo(vf4;vf4;"
542fd4e5da5Sopenharmony_ciOpName %v1 "v1"
543fd4e5da5Sopenharmony_ciOpName %v2 "v2"
544fd4e5da5Sopenharmony_ciOpName %t "t"
545fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
546fd4e5da5Sopenharmony_ciOpName %dead "dead"
547fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
548fd4e5da5Sopenharmony_ciOpName %param "param"
549fd4e5da5Sopenharmony_ciOpName %param_0 "param"
550fd4e5da5Sopenharmony_ci%void = OpTypeVoid
551fd4e5da5Sopenharmony_ci%13 = OpTypeFunction %void
552fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
553fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
554fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
555fd4e5da5Sopenharmony_ci%17 = OpTypeFunction %v4float %_ptr_Function_v4float %_ptr_Function_v4float
556fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
557fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
558fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
559fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
560fd4e5da5Sopenharmony_ci%main = OpFunction %void None %13
561fd4e5da5Sopenharmony_ci%20 = OpLabel
562fd4e5da5Sopenharmony_ci%dead = OpVariable %_ptr_Function_v4float Function
563fd4e5da5Sopenharmony_ci%param = OpVariable %_ptr_Function_v4float Function
564fd4e5da5Sopenharmony_ci%param_0 = OpVariable %_ptr_Function_v4float Function
565fd4e5da5Sopenharmony_ci%21 = OpLoad %v4float %dead
566fd4e5da5Sopenharmony_ciOpStore %param %21
567fd4e5da5Sopenharmony_ci%22 = OpLoad %v4float %BaseColor
568fd4e5da5Sopenharmony_ciOpStore %param_0 %22
569fd4e5da5Sopenharmony_ci%23 = OpFunctionCall %v4float %foo_vf4_vf4_ %param %param_0
570fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %23
571fd4e5da5Sopenharmony_ciOpReturn
572fd4e5da5Sopenharmony_ciOpFunctionEnd
573fd4e5da5Sopenharmony_ci)";
574fd4e5da5Sopenharmony_ci
575fd4e5da5Sopenharmony_ci  const std::string defs_after =
576fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
577fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
578fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
579fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %gl_FragColor %BaseColor
580fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
581fd4e5da5Sopenharmony_ciOpSource GLSL 140
582fd4e5da5Sopenharmony_ciOpName %main "main"
583fd4e5da5Sopenharmony_ciOpName %foo_vf4_vf4_ "foo(vf4;vf4;"
584fd4e5da5Sopenharmony_ciOpName %v1 "v1"
585fd4e5da5Sopenharmony_ciOpName %v2 "v2"
586fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
587fd4e5da5Sopenharmony_ciOpName %dead "dead"
588fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
589fd4e5da5Sopenharmony_ciOpName %param "param"
590fd4e5da5Sopenharmony_ciOpName %param_0 "param"
591fd4e5da5Sopenharmony_ci%void = OpTypeVoid
592fd4e5da5Sopenharmony_ci%13 = OpTypeFunction %void
593fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
594fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
595fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
596fd4e5da5Sopenharmony_ci%17 = OpTypeFunction %v4float %_ptr_Function_v4float %_ptr_Function_v4float
597fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
598fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
599fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
600fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
601fd4e5da5Sopenharmony_ci%main = OpFunction %void None %13
602fd4e5da5Sopenharmony_ci%20 = OpLabel
603fd4e5da5Sopenharmony_ci%dead = OpVariable %_ptr_Function_v4float Function
604fd4e5da5Sopenharmony_ci%param = OpVariable %_ptr_Function_v4float Function
605fd4e5da5Sopenharmony_ci%param_0 = OpVariable %_ptr_Function_v4float Function
606fd4e5da5Sopenharmony_ci%21 = OpLoad %v4float %dead
607fd4e5da5Sopenharmony_ciOpStore %param %21
608fd4e5da5Sopenharmony_ci%22 = OpLoad %v4float %BaseColor
609fd4e5da5Sopenharmony_ciOpStore %param_0 %22
610fd4e5da5Sopenharmony_ci%23 = OpFunctionCall %v4float %foo_vf4_vf4_ %param %param_0
611fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %23
612fd4e5da5Sopenharmony_ciOpReturn
613fd4e5da5Sopenharmony_ciOpFunctionEnd
614fd4e5da5Sopenharmony_ci)";
615fd4e5da5Sopenharmony_ci
616fd4e5da5Sopenharmony_ci  const std::string func_before =
617fd4e5da5Sopenharmony_ci      R"(%foo_vf4_vf4_ = OpFunction %v4float None %17
618fd4e5da5Sopenharmony_ci%v1 = OpFunctionParameter %_ptr_Function_v4float
619fd4e5da5Sopenharmony_ci%v2 = OpFunctionParameter %_ptr_Function_v4float
620fd4e5da5Sopenharmony_ci%24 = OpLabel
621fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_v4float Function
622fd4e5da5Sopenharmony_ci%25 = OpLoad %v4float %v1
623fd4e5da5Sopenharmony_ci%26 = OpFNegate %v4float %25
624fd4e5da5Sopenharmony_ciOpStore %t %26
625fd4e5da5Sopenharmony_ci%27 = OpLoad %v4float %v2
626fd4e5da5Sopenharmony_ciOpReturnValue %27
627fd4e5da5Sopenharmony_ciOpFunctionEnd
628fd4e5da5Sopenharmony_ci)";
629fd4e5da5Sopenharmony_ci
630fd4e5da5Sopenharmony_ci  const std::string func_after =
631fd4e5da5Sopenharmony_ci      R"(%foo_vf4_vf4_ = OpFunction %v4float None %17
632fd4e5da5Sopenharmony_ci%v1 = OpFunctionParameter %_ptr_Function_v4float
633fd4e5da5Sopenharmony_ci%v2 = OpFunctionParameter %_ptr_Function_v4float
634fd4e5da5Sopenharmony_ci%24 = OpLabel
635fd4e5da5Sopenharmony_ci%27 = OpLoad %v4float %v2
636fd4e5da5Sopenharmony_ciOpReturnValue %27
637fd4e5da5Sopenharmony_ciOpFunctionEnd
638fd4e5da5Sopenharmony_ci)";
639fd4e5da5Sopenharmony_ci
640fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(defs_before + func_before,
641fd4e5da5Sopenharmony_ci                                           defs_after + func_after, true, true);
642fd4e5da5Sopenharmony_ci}
643fd4e5da5Sopenharmony_ci
644fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, ElimOpaque) {
645fd4e5da5Sopenharmony_ci  // SPIR-V not representable from GLSL; not generatable from HLSL
646fd4e5da5Sopenharmony_ci  // for the moment.
647fd4e5da5Sopenharmony_ci
648fd4e5da5Sopenharmony_ci  const std::string defs_before =
649fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
650fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
651fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
652fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %outColor %texCoords
653fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
654fd4e5da5Sopenharmony_ciOpSource GLSL 140
655fd4e5da5Sopenharmony_ciOpName %main "main"
656fd4e5da5Sopenharmony_ciOpName %S_t "S_t"
657fd4e5da5Sopenharmony_ciOpMemberName %S_t 0 "v0"
658fd4e5da5Sopenharmony_ciOpMemberName %S_t 1 "v1"
659fd4e5da5Sopenharmony_ciOpMemberName %S_t 2 "smp"
660fd4e5da5Sopenharmony_ciOpName %outColor "outColor"
661fd4e5da5Sopenharmony_ciOpName %sampler15 "sampler15"
662fd4e5da5Sopenharmony_ciOpName %s0 "s0"
663fd4e5da5Sopenharmony_ciOpName %texCoords "texCoords"
664fd4e5da5Sopenharmony_ciOpDecorate %sampler15 DescriptorSet 0
665fd4e5da5Sopenharmony_ci%void = OpTypeVoid
666fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
667fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
668fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
669fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
670fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
671fd4e5da5Sopenharmony_ci%outColor = OpVariable %_ptr_Output_v4float Output
672fd4e5da5Sopenharmony_ci%14 = OpTypeImage %float 2D 0 0 0 1 Unknown
673fd4e5da5Sopenharmony_ci%15 = OpTypeSampledImage %14
674fd4e5da5Sopenharmony_ci%S_t = OpTypeStruct %v2float %v2float %15
675fd4e5da5Sopenharmony_ci%_ptr_Function_S_t = OpTypePointer Function %S_t
676fd4e5da5Sopenharmony_ci%17 = OpTypeFunction %void %_ptr_Function_S_t
677fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15
678fd4e5da5Sopenharmony_ci%_ptr_Function_15 = OpTypePointer Function %15
679fd4e5da5Sopenharmony_ci%sampler15 = OpVariable %_ptr_UniformConstant_15 UniformConstant
680fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
681fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
682fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
683fd4e5da5Sopenharmony_ci%_ptr_Function_v2float = OpTypePointer Function %v2float
684fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
685fd4e5da5Sopenharmony_ci%texCoords = OpVariable %_ptr_Input_v2float Input
686fd4e5da5Sopenharmony_ci)";
687fd4e5da5Sopenharmony_ci
688fd4e5da5Sopenharmony_ci  const std::string defs_after =
689fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
690fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
691fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
692fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %outColor %texCoords
693fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
694fd4e5da5Sopenharmony_ciOpSource GLSL 140
695fd4e5da5Sopenharmony_ciOpName %main "main"
696fd4e5da5Sopenharmony_ciOpName %outColor "outColor"
697fd4e5da5Sopenharmony_ciOpName %sampler15 "sampler15"
698fd4e5da5Sopenharmony_ciOpName %texCoords "texCoords"
699fd4e5da5Sopenharmony_ciOpDecorate %sampler15 DescriptorSet 0
700fd4e5da5Sopenharmony_ci%void = OpTypeVoid
701fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
702fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
703fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
704fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
705fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
706fd4e5da5Sopenharmony_ci%outColor = OpVariable %_ptr_Output_v4float Output
707fd4e5da5Sopenharmony_ci%14 = OpTypeImage %float 2D 0 0 0 1 Unknown
708fd4e5da5Sopenharmony_ci%15 = OpTypeSampledImage %14
709fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_15 = OpTypePointer UniformConstant %15
710fd4e5da5Sopenharmony_ci%sampler15 = OpVariable %_ptr_UniformConstant_15 UniformConstant
711fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
712fd4e5da5Sopenharmony_ci%texCoords = OpVariable %_ptr_Input_v2float Input
713fd4e5da5Sopenharmony_ci)";
714fd4e5da5Sopenharmony_ci
715fd4e5da5Sopenharmony_ci  const std::string func_before =
716fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %9
717fd4e5da5Sopenharmony_ci%25 = OpLabel
718fd4e5da5Sopenharmony_ci%s0 = OpVariable %_ptr_Function_S_t Function
719fd4e5da5Sopenharmony_ci%26 = OpLoad %v2float %texCoords
720fd4e5da5Sopenharmony_ci%27 = OpLoad %S_t %s0
721fd4e5da5Sopenharmony_ci%28 = OpCompositeInsert %S_t %26 %27 0
722fd4e5da5Sopenharmony_ci%29 = OpLoad %15 %sampler15
723fd4e5da5Sopenharmony_ci%30 = OpCompositeInsert %S_t %29 %28 2
724fd4e5da5Sopenharmony_ciOpStore %s0 %30
725fd4e5da5Sopenharmony_ci%31 = OpImageSampleImplicitLod %v4float %29 %26
726fd4e5da5Sopenharmony_ciOpStore %outColor %31
727fd4e5da5Sopenharmony_ciOpReturn
728fd4e5da5Sopenharmony_ciOpFunctionEnd
729fd4e5da5Sopenharmony_ci)";
730fd4e5da5Sopenharmony_ci
731fd4e5da5Sopenharmony_ci  const std::string func_after =
732fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %9
733fd4e5da5Sopenharmony_ci%25 = OpLabel
734fd4e5da5Sopenharmony_ci%26 = OpLoad %v2float %texCoords
735fd4e5da5Sopenharmony_ci%29 = OpLoad %15 %sampler15
736fd4e5da5Sopenharmony_ci%31 = OpImageSampleImplicitLod %v4float %29 %26
737fd4e5da5Sopenharmony_ciOpStore %outColor %31
738fd4e5da5Sopenharmony_ciOpReturn
739fd4e5da5Sopenharmony_ciOpFunctionEnd
740fd4e5da5Sopenharmony_ci)";
741fd4e5da5Sopenharmony_ci
742fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(defs_before + func_before,
743fd4e5da5Sopenharmony_ci                                           defs_after + func_after, true, true);
744fd4e5da5Sopenharmony_ci}
745fd4e5da5Sopenharmony_ci
746fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoParamStoreElim) {
747fd4e5da5Sopenharmony_ci  // Should not eliminate stores to params
748fd4e5da5Sopenharmony_ci  //
749fd4e5da5Sopenharmony_ci  // #version 450
750fd4e5da5Sopenharmony_ci  //
751fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
752fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
753fd4e5da5Sopenharmony_ci  //
754fd4e5da5Sopenharmony_ci  // void foo(in vec4 v1, out vec4 v2)
755fd4e5da5Sopenharmony_ci  // {
756fd4e5da5Sopenharmony_ci  //     v2 = -v1;
757fd4e5da5Sopenharmony_ci  // }
758fd4e5da5Sopenharmony_ci  //
759fd4e5da5Sopenharmony_ci  // void main()
760fd4e5da5Sopenharmony_ci  // {
761fd4e5da5Sopenharmony_ci  //     foo(BaseColor, OutColor);
762fd4e5da5Sopenharmony_ci  // }
763fd4e5da5Sopenharmony_ci
764fd4e5da5Sopenharmony_ci  const std::string assembly =
765fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
766fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
767fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
768fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %OutColor
769fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
770fd4e5da5Sopenharmony_ciOpSource GLSL 450
771fd4e5da5Sopenharmony_ciOpName %main "main"
772fd4e5da5Sopenharmony_ciOpName %foo_vf4_vf4_ "foo(vf4;vf4;"
773fd4e5da5Sopenharmony_ciOpName %v1 "v1"
774fd4e5da5Sopenharmony_ciOpName %v2 "v2"
775fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
776fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
777fd4e5da5Sopenharmony_ciOpName %param "param"
778fd4e5da5Sopenharmony_ciOpName %param_0 "param"
779fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
780fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
781fd4e5da5Sopenharmony_ci%void = OpTypeVoid
782fd4e5da5Sopenharmony_ci%11 = OpTypeFunction %void
783fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
784fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
785fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
786fd4e5da5Sopenharmony_ci%15 = OpTypeFunction %void %_ptr_Function_v4float %_ptr_Function_v4float
787fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
788fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
789fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
790fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
791fd4e5da5Sopenharmony_ci%main = OpFunction %void None %11
792fd4e5da5Sopenharmony_ci%18 = OpLabel
793fd4e5da5Sopenharmony_ci%param = OpVariable %_ptr_Function_v4float Function
794fd4e5da5Sopenharmony_ci%param_0 = OpVariable %_ptr_Function_v4float Function
795fd4e5da5Sopenharmony_ci%19 = OpLoad %v4float %BaseColor
796fd4e5da5Sopenharmony_ciOpStore %param %19
797fd4e5da5Sopenharmony_ci%20 = OpFunctionCall %void %foo_vf4_vf4_ %param %param_0
798fd4e5da5Sopenharmony_ci%21 = OpLoad %v4float %param_0
799fd4e5da5Sopenharmony_ciOpStore %OutColor %21
800fd4e5da5Sopenharmony_ciOpReturn
801fd4e5da5Sopenharmony_ciOpFunctionEnd
802fd4e5da5Sopenharmony_ci%foo_vf4_vf4_ = OpFunction %void None %15
803fd4e5da5Sopenharmony_ci%v1 = OpFunctionParameter %_ptr_Function_v4float
804fd4e5da5Sopenharmony_ci%v2 = OpFunctionParameter %_ptr_Function_v4float
805fd4e5da5Sopenharmony_ci%22 = OpLabel
806fd4e5da5Sopenharmony_ci%23 = OpLoad %v4float %v1
807fd4e5da5Sopenharmony_ci%24 = OpFNegate %v4float %23
808fd4e5da5Sopenharmony_ciOpStore %v2 %24
809fd4e5da5Sopenharmony_ciOpReturn
810fd4e5da5Sopenharmony_ciOpFunctionEnd
811fd4e5da5Sopenharmony_ci)";
812fd4e5da5Sopenharmony_ci
813fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
814fd4e5da5Sopenharmony_ci}
815fd4e5da5Sopenharmony_ci
816fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, PrivateStoreElimInEntryNoCalls) {
817fd4e5da5Sopenharmony_ci  // Eliminate stores to private in entry point with no calls
818fd4e5da5Sopenharmony_ci  // Note: Not legal GLSL
819fd4e5da5Sopenharmony_ci  //
820fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
821fd4e5da5Sopenharmony_ci  // layout(location = 1) in vec4 Dead;
822fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
823fd4e5da5Sopenharmony_ci  //
824fd4e5da5Sopenharmony_ci  // private vec4 dv;
825fd4e5da5Sopenharmony_ci  //
826fd4e5da5Sopenharmony_ci  // void main()
827fd4e5da5Sopenharmony_ci  // {
828fd4e5da5Sopenharmony_ci  //     vec4 v = BaseColor;
829fd4e5da5Sopenharmony_ci  //     dv = Dead;
830fd4e5da5Sopenharmony_ci  //     OutColor = v;
831fd4e5da5Sopenharmony_ci  // }
832fd4e5da5Sopenharmony_ci
833fd4e5da5Sopenharmony_ci  const std::string spirv =
834fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
835fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
836fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
837fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %Dead %OutColor
838fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
839fd4e5da5Sopenharmony_ciOpSource GLSL 450
840fd4e5da5Sopenharmony_ciOpName %main "main"
841fd4e5da5Sopenharmony_ciOpName %v "v"
842fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
843fd4e5da5Sopenharmony_ci; CHECK-NOT: OpName %dv "dv"
844fd4e5da5Sopenharmony_ciOpName %dv "dv"
845fd4e5da5Sopenharmony_ciOpName %Dead "Dead"
846fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
847fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
848fd4e5da5Sopenharmony_ciOpDecorate %Dead Location 1
849fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
850fd4e5da5Sopenharmony_ci%void = OpTypeVoid
851fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
852fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
853fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
854fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
855fd4e5da5Sopenharmony_ci; CHECK-NOT: OpTypePointer Private
856fd4e5da5Sopenharmony_ci%_ptr_Private_v4float = OpTypePointer Private %v4float
857fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
858fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
859fd4e5da5Sopenharmony_ci%Dead = OpVariable %_ptr_Input_v4float Input
860fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
861fd4e5da5Sopenharmony_ci; CHECK-NOT: %dv = OpVariable
862fd4e5da5Sopenharmony_ci%dv = OpVariable %_ptr_Private_v4float Private
863fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
864fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
865fd4e5da5Sopenharmony_ci%16 = OpLabel
866fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
867fd4e5da5Sopenharmony_ci%17 = OpLoad %v4float %BaseColor
868fd4e5da5Sopenharmony_ciOpStore %v %17
869fd4e5da5Sopenharmony_ci%18 = OpLoad %v4float %Dead
870fd4e5da5Sopenharmony_ci; CHECK-NOT: OpStore %dv
871fd4e5da5Sopenharmony_ciOpStore %dv %18
872fd4e5da5Sopenharmony_ci%19 = OpLoad %v4float %v
873fd4e5da5Sopenharmony_ci%20 = OpFNegate %v4float %19
874fd4e5da5Sopenharmony_ciOpStore %OutColor %20
875fd4e5da5Sopenharmony_ciOpReturn
876fd4e5da5Sopenharmony_ciOpFunctionEnd
877fd4e5da5Sopenharmony_ci)";
878fd4e5da5Sopenharmony_ci
879fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
880fd4e5da5Sopenharmony_ci}
881fd4e5da5Sopenharmony_ci
882fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoPrivateStoreElimIfLoad) {
883fd4e5da5Sopenharmony_ci  // Should not eliminate stores to private when there is a load
884fd4e5da5Sopenharmony_ci  // Note: Not legal GLSL
885fd4e5da5Sopenharmony_ci  //
886fd4e5da5Sopenharmony_ci  // #version 450
887fd4e5da5Sopenharmony_ci  //
888fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
889fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
890fd4e5da5Sopenharmony_ci  //
891fd4e5da5Sopenharmony_ci  // private vec4 pv;
892fd4e5da5Sopenharmony_ci  //
893fd4e5da5Sopenharmony_ci  // void main()
894fd4e5da5Sopenharmony_ci  // {
895fd4e5da5Sopenharmony_ci  //     pv = BaseColor;
896fd4e5da5Sopenharmony_ci  //     OutColor = pv;
897fd4e5da5Sopenharmony_ci  // }
898fd4e5da5Sopenharmony_ci
899fd4e5da5Sopenharmony_ci  const std::string assembly =
900fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
901fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
902fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
903fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %OutColor
904fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
905fd4e5da5Sopenharmony_ciOpSource GLSL 450
906fd4e5da5Sopenharmony_ciOpName %main "main"
907fd4e5da5Sopenharmony_ciOpName %pv "pv"
908fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
909fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
910fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
911fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
912fd4e5da5Sopenharmony_ci%void = OpTypeVoid
913fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
914fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
915fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
916fd4e5da5Sopenharmony_ci%_ptr_Private_v4float = OpTypePointer Private %v4float
917fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
918fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
919fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
920fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
921fd4e5da5Sopenharmony_ci%pv = OpVariable %_ptr_Private_v4float Private
922fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
923fd4e5da5Sopenharmony_ci%13 = OpLabel
924fd4e5da5Sopenharmony_ci%14 = OpLoad %v4float %BaseColor
925fd4e5da5Sopenharmony_ciOpStore %pv %14
926fd4e5da5Sopenharmony_ci%15 = OpLoad %v4float %pv
927fd4e5da5Sopenharmony_ci%16 = OpFNegate %v4float %15
928fd4e5da5Sopenharmony_ciOpStore %OutColor %16
929fd4e5da5Sopenharmony_ciOpReturn
930fd4e5da5Sopenharmony_ciOpFunctionEnd
931fd4e5da5Sopenharmony_ci)";
932fd4e5da5Sopenharmony_ci
933fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
934fd4e5da5Sopenharmony_ci}
935fd4e5da5Sopenharmony_ci
936fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoPrivateStoreElimWithCall) {
937fd4e5da5Sopenharmony_ci  // Should not eliminate stores to private when function contains call
938fd4e5da5Sopenharmony_ci  // Note: Not legal GLSL
939fd4e5da5Sopenharmony_ci  //
940fd4e5da5Sopenharmony_ci  // #version 450
941fd4e5da5Sopenharmony_ci  //
942fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
943fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
944fd4e5da5Sopenharmony_ci  //
945fd4e5da5Sopenharmony_ci  // private vec4 v1;
946fd4e5da5Sopenharmony_ci  //
947fd4e5da5Sopenharmony_ci  // void foo()
948fd4e5da5Sopenharmony_ci  // {
949fd4e5da5Sopenharmony_ci  //     OutColor = -v1;
950fd4e5da5Sopenharmony_ci  // }
951fd4e5da5Sopenharmony_ci  //
952fd4e5da5Sopenharmony_ci  // void main()
953fd4e5da5Sopenharmony_ci  // {
954fd4e5da5Sopenharmony_ci  //     v1 = BaseColor;
955fd4e5da5Sopenharmony_ci  //     foo();
956fd4e5da5Sopenharmony_ci  // }
957fd4e5da5Sopenharmony_ci
958fd4e5da5Sopenharmony_ci  const std::string assembly =
959fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
960fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
961fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
962fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %OutColor %BaseColor
963fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
964fd4e5da5Sopenharmony_ciOpSource GLSL 450
965fd4e5da5Sopenharmony_ciOpName %main "main"
966fd4e5da5Sopenharmony_ciOpName %foo_ "foo("
967fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
968fd4e5da5Sopenharmony_ciOpName %v1 "v1"
969fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
970fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
971fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
972fd4e5da5Sopenharmony_ci%void = OpTypeVoid
973fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
974fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
975fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
976fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
977fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
978fd4e5da5Sopenharmony_ci%_ptr_Private_v4float = OpTypePointer Private %v4float
979fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
980fd4e5da5Sopenharmony_ci%v1 = OpVariable %_ptr_Private_v4float Private
981fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
982fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
983fd4e5da5Sopenharmony_ci%14 = OpLabel
984fd4e5da5Sopenharmony_ci%15 = OpLoad %v4float %BaseColor
985fd4e5da5Sopenharmony_ciOpStore %v1 %15
986fd4e5da5Sopenharmony_ci%16 = OpFunctionCall %void %foo_
987fd4e5da5Sopenharmony_ciOpReturn
988fd4e5da5Sopenharmony_ciOpFunctionEnd
989fd4e5da5Sopenharmony_ci%foo_ = OpFunction %void None %8
990fd4e5da5Sopenharmony_ci%17 = OpLabel
991fd4e5da5Sopenharmony_ci%18 = OpLoad %v4float %v1
992fd4e5da5Sopenharmony_ci%19 = OpFNegate %v4float %18
993fd4e5da5Sopenharmony_ciOpStore %OutColor %19
994fd4e5da5Sopenharmony_ciOpReturn
995fd4e5da5Sopenharmony_ciOpFunctionEnd
996fd4e5da5Sopenharmony_ci)";
997fd4e5da5Sopenharmony_ci
998fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
999fd4e5da5Sopenharmony_ci}
1000fd4e5da5Sopenharmony_ci
1001fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoPrivateStoreElimInNonEntry) {
1002fd4e5da5Sopenharmony_ci  // Should not eliminate stores to private when function is not entry point
1003fd4e5da5Sopenharmony_ci  // Note: Not legal GLSL
1004fd4e5da5Sopenharmony_ci  //
1005fd4e5da5Sopenharmony_ci  // #version 450
1006fd4e5da5Sopenharmony_ci  //
1007fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
1008fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
1009fd4e5da5Sopenharmony_ci  //
1010fd4e5da5Sopenharmony_ci  // private vec4 v1;
1011fd4e5da5Sopenharmony_ci  //
1012fd4e5da5Sopenharmony_ci  // void foo()
1013fd4e5da5Sopenharmony_ci  // {
1014fd4e5da5Sopenharmony_ci  //     v1 = BaseColor;
1015fd4e5da5Sopenharmony_ci  // }
1016fd4e5da5Sopenharmony_ci  //
1017fd4e5da5Sopenharmony_ci  // void main()
1018fd4e5da5Sopenharmony_ci  // {
1019fd4e5da5Sopenharmony_ci  //     foo();
1020fd4e5da5Sopenharmony_ci  //     OutColor = -v1;
1021fd4e5da5Sopenharmony_ci  // }
1022fd4e5da5Sopenharmony_ci
1023fd4e5da5Sopenharmony_ci  const std::string assembly =
1024fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1025fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1026fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1027fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %OutColor
1028fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1029fd4e5da5Sopenharmony_ciOpSource GLSL 450
1030fd4e5da5Sopenharmony_ciOpName %main "main"
1031fd4e5da5Sopenharmony_ciOpName %foo_ "foo("
1032fd4e5da5Sopenharmony_ciOpName %v1 "v1"
1033fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1034fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
1035fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
1036fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
1037fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1038fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
1039fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1040fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1041fd4e5da5Sopenharmony_ci%_ptr_Private_v4float = OpTypePointer Private %v4float
1042fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1043fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1044fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1045fd4e5da5Sopenharmony_ci%v1 = OpVariable %_ptr_Private_v4float Private
1046fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
1047fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
1048fd4e5da5Sopenharmony_ci%14 = OpLabel
1049fd4e5da5Sopenharmony_ci%15 = OpFunctionCall %void %foo_
1050fd4e5da5Sopenharmony_ci%16 = OpLoad %v4float %v1
1051fd4e5da5Sopenharmony_ci%17 = OpFNegate %v4float %16
1052fd4e5da5Sopenharmony_ciOpStore %OutColor %17
1053fd4e5da5Sopenharmony_ciOpReturn
1054fd4e5da5Sopenharmony_ciOpFunctionEnd
1055fd4e5da5Sopenharmony_ci%foo_ = OpFunction %void None %8
1056fd4e5da5Sopenharmony_ci%18 = OpLabel
1057fd4e5da5Sopenharmony_ci%19 = OpLoad %v4float %BaseColor
1058fd4e5da5Sopenharmony_ciOpStore %v1 %19
1059fd4e5da5Sopenharmony_ciOpReturn
1060fd4e5da5Sopenharmony_ciOpFunctionEnd
1061fd4e5da5Sopenharmony_ci)";
1062fd4e5da5Sopenharmony_ci
1063fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
1064fd4e5da5Sopenharmony_ci}
1065fd4e5da5Sopenharmony_ci
1066fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, WorkgroupStoreElimInEntryNoCalls) {
1067fd4e5da5Sopenharmony_ci  // Eliminate stores to private in entry point with no calls
1068fd4e5da5Sopenharmony_ci  // Note: Not legal GLSL
1069fd4e5da5Sopenharmony_ci  //
1070fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
1071fd4e5da5Sopenharmony_ci  // layout(location = 1) in vec4 Dead;
1072fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
1073fd4e5da5Sopenharmony_ci  //
1074fd4e5da5Sopenharmony_ci  // workgroup vec4 dv;
1075fd4e5da5Sopenharmony_ci  //
1076fd4e5da5Sopenharmony_ci  // void main()
1077fd4e5da5Sopenharmony_ci  // {
1078fd4e5da5Sopenharmony_ci  //     vec4 v = BaseColor;
1079fd4e5da5Sopenharmony_ci  //     dv = Dead;
1080fd4e5da5Sopenharmony_ci  //     OutColor = v;
1081fd4e5da5Sopenharmony_ci  // }
1082fd4e5da5Sopenharmony_ci
1083fd4e5da5Sopenharmony_ci  const std::string spirv =
1084fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1085fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1086fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1087fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %Dead %OutColor
1088fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1089fd4e5da5Sopenharmony_ciOpSource GLSL 450
1090fd4e5da5Sopenharmony_ciOpName %main "main"
1091fd4e5da5Sopenharmony_ciOpName %v "v"
1092fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1093fd4e5da5Sopenharmony_ci; CHECK-NOT: OpName %dv "dv"
1094fd4e5da5Sopenharmony_ciOpName %dv "dv"
1095fd4e5da5Sopenharmony_ciOpName %Dead "Dead"
1096fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
1097fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
1098fd4e5da5Sopenharmony_ciOpDecorate %Dead Location 1
1099fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
1100fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1101fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
1102fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1103fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1104fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
1105fd4e5da5Sopenharmony_ci; CHECK-NOT: OpTypePointer Workgroup
1106fd4e5da5Sopenharmony_ci%_ptr_Workgroup_v4float = OpTypePointer Workgroup %v4float
1107fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1108fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1109fd4e5da5Sopenharmony_ci%Dead = OpVariable %_ptr_Input_v4float Input
1110fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1111fd4e5da5Sopenharmony_ci; CHECK-NOT: %dv = OpVariable
1112fd4e5da5Sopenharmony_ci%dv = OpVariable %_ptr_Workgroup_v4float Workgroup
1113fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
1114fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
1115fd4e5da5Sopenharmony_ci%16 = OpLabel
1116fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
1117fd4e5da5Sopenharmony_ci%17 = OpLoad %v4float %BaseColor
1118fd4e5da5Sopenharmony_ciOpStore %v %17
1119fd4e5da5Sopenharmony_ci%18 = OpLoad %v4float %Dead
1120fd4e5da5Sopenharmony_ci; CHECK-NOT: OpStore %dv
1121fd4e5da5Sopenharmony_ciOpStore %dv %18
1122fd4e5da5Sopenharmony_ci%19 = OpLoad %v4float %v
1123fd4e5da5Sopenharmony_ci%20 = OpFNegate %v4float %19
1124fd4e5da5Sopenharmony_ciOpStore %OutColor %20
1125fd4e5da5Sopenharmony_ciOpReturn
1126fd4e5da5Sopenharmony_ciOpFunctionEnd
1127fd4e5da5Sopenharmony_ci)";
1128fd4e5da5Sopenharmony_ci
1129fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
1130fd4e5da5Sopenharmony_ci}
1131fd4e5da5Sopenharmony_ci
1132fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateDeadIfThenElse) {
1133fd4e5da5Sopenharmony_ci  // #version 450
1134fd4e5da5Sopenharmony_ci  //
1135fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
1136fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
1137fd4e5da5Sopenharmony_ci  //
1138fd4e5da5Sopenharmony_ci  // void main()
1139fd4e5da5Sopenharmony_ci  // {
1140fd4e5da5Sopenharmony_ci  //     float d;
1141fd4e5da5Sopenharmony_ci  //     if (BaseColor.x == 0)
1142fd4e5da5Sopenharmony_ci  //       d = BaseColor.y;
1143fd4e5da5Sopenharmony_ci  //     else
1144fd4e5da5Sopenharmony_ci  //       d = BaseColor.z;
1145fd4e5da5Sopenharmony_ci  //     OutColor = vec4(1.0,1.0,1.0,1.0);
1146fd4e5da5Sopenharmony_ci  // }
1147fd4e5da5Sopenharmony_ci
1148fd4e5da5Sopenharmony_ci  const std::string spirv =
1149fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1150fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1151fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1152fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %OutColor
1153fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1154fd4e5da5Sopenharmony_ciOpSource GLSL 450
1155fd4e5da5Sopenharmony_ciOpName %main "main"
1156fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1157fd4e5da5Sopenharmony_ciOpName %d "d"
1158fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
1159fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
1160fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
1161fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1162fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
1163fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1164fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1165fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1166fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1167fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1168fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
1169fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
1170fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1171fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1172fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1173fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
1174fd4e5da5Sopenharmony_ci%uint_2 = OpConstant %uint 2
1175fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1176fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
1177fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
1178fd4e5da5Sopenharmony_ci%21 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
1179fd4e5da5Sopenharmony_ci; CHECK: = OpFunction %void
1180fd4e5da5Sopenharmony_ci; CHECK-NEXT: %22 = OpLabel
1181fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch %26
1182fd4e5da5Sopenharmony_ci; CHECK-NEXT: %26 = OpLabel
1183fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
1184fd4e5da5Sopenharmony_ci%22 = OpLabel
1185fd4e5da5Sopenharmony_ci%d = OpVariable %_ptr_Function_float Function
1186fd4e5da5Sopenharmony_ci%23 = OpAccessChain %_ptr_Input_float %BaseColor %uint_0
1187fd4e5da5Sopenharmony_ci%24 = OpLoad %float %23
1188fd4e5da5Sopenharmony_ci%25 = OpFOrdEqual %bool %24 %float_0
1189fd4e5da5Sopenharmony_ciOpSelectionMerge %26 None
1190fd4e5da5Sopenharmony_ciOpBranchConditional %25 %27 %28
1191fd4e5da5Sopenharmony_ci%27 = OpLabel
1192fd4e5da5Sopenharmony_ci%29 = OpAccessChain %_ptr_Input_float %BaseColor %uint_1
1193fd4e5da5Sopenharmony_ci%30 = OpLoad %float %29
1194fd4e5da5Sopenharmony_ciOpStore %d %30
1195fd4e5da5Sopenharmony_ciOpBranch %26
1196fd4e5da5Sopenharmony_ci%28 = OpLabel
1197fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Input_float %BaseColor %uint_2
1198fd4e5da5Sopenharmony_ci%32 = OpLoad %float %31
1199fd4e5da5Sopenharmony_ciOpStore %d %32
1200fd4e5da5Sopenharmony_ciOpBranch %26
1201fd4e5da5Sopenharmony_ci%26 = OpLabel
1202fd4e5da5Sopenharmony_ciOpStore %OutColor %21
1203fd4e5da5Sopenharmony_ciOpReturn
1204fd4e5da5Sopenharmony_ciOpFunctionEnd
1205fd4e5da5Sopenharmony_ci)";
1206fd4e5da5Sopenharmony_ci
1207fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
1208fd4e5da5Sopenharmony_ci}
1209fd4e5da5Sopenharmony_ci
1210fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateDeadIfThen) {
1211fd4e5da5Sopenharmony_ci  // #version 450
1212fd4e5da5Sopenharmony_ci  //
1213fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
1214fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
1215fd4e5da5Sopenharmony_ci  //
1216fd4e5da5Sopenharmony_ci  // void main()
1217fd4e5da5Sopenharmony_ci  // {
1218fd4e5da5Sopenharmony_ci  //     float d;
1219fd4e5da5Sopenharmony_ci  //     if (BaseColor.x == 0)
1220fd4e5da5Sopenharmony_ci  //       d = BaseColor.y;
1221fd4e5da5Sopenharmony_ci  //     OutColor = vec4(1.0,1.0,1.0,1.0);
1222fd4e5da5Sopenharmony_ci  // }
1223fd4e5da5Sopenharmony_ci
1224fd4e5da5Sopenharmony_ci  const std::string spirv =
1225fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1226fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1227fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1228fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %OutColor
1229fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1230fd4e5da5Sopenharmony_ciOpSource GLSL 450
1231fd4e5da5Sopenharmony_ciOpName %main "main"
1232fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1233fd4e5da5Sopenharmony_ciOpName %d "d"
1234fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
1235fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
1236fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
1237fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1238fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
1239fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1240fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1241fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1242fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1243fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1244fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
1245fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
1246fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1247fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1248fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1249fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
1250fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1251fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
1252fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
1253fd4e5da5Sopenharmony_ci%20 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
1254fd4e5da5Sopenharmony_ci; CHECK: = OpFunction
1255fd4e5da5Sopenharmony_ci; CHECK-NEXT: %21 = OpLabel
1256fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[target:%\w+]]
1257fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[target]] = OpLabel
1258fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
1259fd4e5da5Sopenharmony_ci%21 = OpLabel
1260fd4e5da5Sopenharmony_ci%d = OpVariable %_ptr_Function_float Function
1261fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_Input_float %BaseColor %uint_0
1262fd4e5da5Sopenharmony_ci%23 = OpLoad %float %22
1263fd4e5da5Sopenharmony_ci%24 = OpFOrdEqual %bool %23 %float_0
1264fd4e5da5Sopenharmony_ciOpSelectionMerge %25 None
1265fd4e5da5Sopenharmony_ciOpBranchConditional %24 %26 %25
1266fd4e5da5Sopenharmony_ci%26 = OpLabel
1267fd4e5da5Sopenharmony_ci%27 = OpAccessChain %_ptr_Input_float %BaseColor %uint_1
1268fd4e5da5Sopenharmony_ci%28 = OpLoad %float %27
1269fd4e5da5Sopenharmony_ciOpStore %d %28
1270fd4e5da5Sopenharmony_ciOpBranch %25
1271fd4e5da5Sopenharmony_ci%25 = OpLabel
1272fd4e5da5Sopenharmony_ciOpStore %OutColor %20
1273fd4e5da5Sopenharmony_ciOpReturn
1274fd4e5da5Sopenharmony_ciOpFunctionEnd
1275fd4e5da5Sopenharmony_ci)";
1276fd4e5da5Sopenharmony_ci
1277fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
1278fd4e5da5Sopenharmony_ci}
1279fd4e5da5Sopenharmony_ci
1280fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateDeadSwitch) {
1281fd4e5da5Sopenharmony_ci  // #version 450
1282fd4e5da5Sopenharmony_ci  //
1283fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
1284fd4e5da5Sopenharmony_ci  // layout(location = 1) in flat int x;
1285fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
1286fd4e5da5Sopenharmony_ci  //
1287fd4e5da5Sopenharmony_ci  // void main()
1288fd4e5da5Sopenharmony_ci  // {
1289fd4e5da5Sopenharmony_ci  //     float d;
1290fd4e5da5Sopenharmony_ci  //     switch (x) {
1291fd4e5da5Sopenharmony_ci  //       case 0:
1292fd4e5da5Sopenharmony_ci  //         d = BaseColor.y;
1293fd4e5da5Sopenharmony_ci  //     }
1294fd4e5da5Sopenharmony_ci  //     OutColor = vec4(1.0,1.0,1.0,1.0);
1295fd4e5da5Sopenharmony_ci  // }
1296fd4e5da5Sopenharmony_ci  const std::string spirv =
1297fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1298fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
1299fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
1300fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %main "main" %x %BaseColor %OutColor
1301fd4e5da5Sopenharmony_ci               OpExecutionMode %main OriginUpperLeft
1302fd4e5da5Sopenharmony_ci               OpSource GLSL 450
1303fd4e5da5Sopenharmony_ci               OpName %main "main"
1304fd4e5da5Sopenharmony_ci               OpName %x "x"
1305fd4e5da5Sopenharmony_ci               OpName %d "d"
1306fd4e5da5Sopenharmony_ci               OpName %BaseColor "BaseColor"
1307fd4e5da5Sopenharmony_ci               OpName %OutColor "OutColor"
1308fd4e5da5Sopenharmony_ci               OpDecorate %x Flat
1309fd4e5da5Sopenharmony_ci               OpDecorate %x Location 1
1310fd4e5da5Sopenharmony_ci               OpDecorate %BaseColor Location 0
1311fd4e5da5Sopenharmony_ci               OpDecorate %OutColor Location 0
1312fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
1313fd4e5da5Sopenharmony_ci          %3 = OpTypeFunction %void
1314fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
1315fd4e5da5Sopenharmony_ci%_ptr_Input_int = OpTypePointer Input %int
1316fd4e5da5Sopenharmony_ci          %x = OpVariable %_ptr_Input_int Input
1317fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
1318fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1319fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
1320fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1321fd4e5da5Sopenharmony_ci  %BaseColor = OpVariable %_ptr_Input_v4float Input
1322fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
1323fd4e5da5Sopenharmony_ci     %uint_1 = OpConstant %uint 1
1324fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
1325fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1326fd4e5da5Sopenharmony_ci   %OutColor = OpVariable %_ptr_Output_v4float Output
1327fd4e5da5Sopenharmony_ci    %float_1 = OpConstant %float 1
1328fd4e5da5Sopenharmony_ci         %27 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
1329fd4e5da5Sopenharmony_ci; CHECK: = OpFunction
1330fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpLabel
1331fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[target:%\w+]]
1332fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[target]] = OpLabel
1333fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %3
1334fd4e5da5Sopenharmony_ci          %5 = OpLabel
1335fd4e5da5Sopenharmony_ci          %d = OpVariable %_ptr_Function_float Function
1336fd4e5da5Sopenharmony_ci          %9 = OpLoad %int %x
1337fd4e5da5Sopenharmony_ci               OpSelectionMerge %11 None
1338fd4e5da5Sopenharmony_ci               OpSwitch %9 %11 0 %10
1339fd4e5da5Sopenharmony_ci         %10 = OpLabel
1340fd4e5da5Sopenharmony_ci         %21 = OpAccessChain %_ptr_Input_float %BaseColor %uint_1
1341fd4e5da5Sopenharmony_ci         %22 = OpLoad %float %21
1342fd4e5da5Sopenharmony_ci               OpStore %d %22
1343fd4e5da5Sopenharmony_ci               OpBranch %11
1344fd4e5da5Sopenharmony_ci         %11 = OpLabel
1345fd4e5da5Sopenharmony_ci               OpStore %OutColor %27
1346fd4e5da5Sopenharmony_ci               OpReturn
1347fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
1348fd4e5da5Sopenharmony_ci
1349fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
1350fd4e5da5Sopenharmony_ci}
1351fd4e5da5Sopenharmony_ci
1352fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateDeadIfThenElseNested) {
1353fd4e5da5Sopenharmony_ci  // #version 450
1354fd4e5da5Sopenharmony_ci  //
1355fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
1356fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
1357fd4e5da5Sopenharmony_ci  //
1358fd4e5da5Sopenharmony_ci  // void main()
1359fd4e5da5Sopenharmony_ci  // {
1360fd4e5da5Sopenharmony_ci  //     float d;
1361fd4e5da5Sopenharmony_ci  //     if (BaseColor.x == 0)
1362fd4e5da5Sopenharmony_ci  //       if (BaseColor.y == 0)
1363fd4e5da5Sopenharmony_ci  //         d = 0.0;
1364fd4e5da5Sopenharmony_ci  //       else
1365fd4e5da5Sopenharmony_ci  //         d = 0.25;
1366fd4e5da5Sopenharmony_ci  //     else
1367fd4e5da5Sopenharmony_ci  //       if (BaseColor.y == 0)
1368fd4e5da5Sopenharmony_ci  //         d = 0.5;
1369fd4e5da5Sopenharmony_ci  //       else
1370fd4e5da5Sopenharmony_ci  //         d = 0.75;
1371fd4e5da5Sopenharmony_ci  //     OutColor = vec4(1.0,1.0,1.0,1.0);
1372fd4e5da5Sopenharmony_ci  // }
1373fd4e5da5Sopenharmony_ci
1374fd4e5da5Sopenharmony_ci  const std::string spirv =
1375fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1376fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1377fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1378fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %OutColor
1379fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1380fd4e5da5Sopenharmony_ciOpSource GLSL 450
1381fd4e5da5Sopenharmony_ciOpName %main "main"
1382fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1383fd4e5da5Sopenharmony_ciOpName %d "d"
1384fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
1385fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
1386fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
1387fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1388fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
1389fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1390fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1391fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1392fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1393fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1394fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
1395fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
1396fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1397fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1398fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
1399fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1400fd4e5da5Sopenharmony_ci%float_0_25 = OpConstant %float 0.25
1401fd4e5da5Sopenharmony_ci%float_0_5 = OpConstant %float 0.5
1402fd4e5da5Sopenharmony_ci%float_0_75 = OpConstant %float 0.75
1403fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1404fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
1405fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
1406fd4e5da5Sopenharmony_ci%23 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
1407fd4e5da5Sopenharmony_ci
1408fd4e5da5Sopenharmony_ci; CHECK: = OpFunction
1409fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpLabel
1410fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[target:%\w+]]
1411fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[target]] = OpLabel
1412fd4e5da5Sopenharmony_ci; CHECK-NOT: OpLabel
1413fd4e5da5Sopenharmony_ci
1414fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
1415fd4e5da5Sopenharmony_ci%24 = OpLabel
1416fd4e5da5Sopenharmony_ci%d = OpVariable %_ptr_Function_float Function
1417fd4e5da5Sopenharmony_ci%25 = OpAccessChain %_ptr_Input_float %BaseColor %uint_0
1418fd4e5da5Sopenharmony_ci%26 = OpLoad %float %25
1419fd4e5da5Sopenharmony_ci%27 = OpFOrdEqual %bool %26 %float_0
1420fd4e5da5Sopenharmony_ciOpSelectionMerge %28 None
1421fd4e5da5Sopenharmony_ciOpBranchConditional %27 %29 %30
1422fd4e5da5Sopenharmony_ci%29 = OpLabel
1423fd4e5da5Sopenharmony_ci%31 = OpAccessChain %_ptr_Input_float %BaseColor %uint_1
1424fd4e5da5Sopenharmony_ci%32 = OpLoad %float %31
1425fd4e5da5Sopenharmony_ci%33 = OpFOrdEqual %bool %32 %float_0
1426fd4e5da5Sopenharmony_ciOpSelectionMerge %34 None
1427fd4e5da5Sopenharmony_ciOpBranchConditional %33 %35 %36
1428fd4e5da5Sopenharmony_ci%35 = OpLabel
1429fd4e5da5Sopenharmony_ciOpStore %d %float_0
1430fd4e5da5Sopenharmony_ciOpBranch %34
1431fd4e5da5Sopenharmony_ci%36 = OpLabel
1432fd4e5da5Sopenharmony_ciOpStore %d %float_0_25
1433fd4e5da5Sopenharmony_ciOpBranch %34
1434fd4e5da5Sopenharmony_ci%34 = OpLabel
1435fd4e5da5Sopenharmony_ciOpBranch %28
1436fd4e5da5Sopenharmony_ci%30 = OpLabel
1437fd4e5da5Sopenharmony_ci%37 = OpAccessChain %_ptr_Input_float %BaseColor %uint_1
1438fd4e5da5Sopenharmony_ci%38 = OpLoad %float %37
1439fd4e5da5Sopenharmony_ci%39 = OpFOrdEqual %bool %38 %float_0
1440fd4e5da5Sopenharmony_ciOpSelectionMerge %40 None
1441fd4e5da5Sopenharmony_ciOpBranchConditional %39 %41 %42
1442fd4e5da5Sopenharmony_ci%41 = OpLabel
1443fd4e5da5Sopenharmony_ciOpStore %d %float_0_5
1444fd4e5da5Sopenharmony_ciOpBranch %40
1445fd4e5da5Sopenharmony_ci%42 = OpLabel
1446fd4e5da5Sopenharmony_ciOpStore %d %float_0_75
1447fd4e5da5Sopenharmony_ciOpBranch %40
1448fd4e5da5Sopenharmony_ci%40 = OpLabel
1449fd4e5da5Sopenharmony_ciOpBranch %28
1450fd4e5da5Sopenharmony_ci%28 = OpLabel
1451fd4e5da5Sopenharmony_ciOpStore %OutColor %23
1452fd4e5da5Sopenharmony_ciOpReturn
1453fd4e5da5Sopenharmony_ciOpFunctionEnd
1454fd4e5da5Sopenharmony_ci)";
1455fd4e5da5Sopenharmony_ci
1456fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
1457fd4e5da5Sopenharmony_ci}
1458fd4e5da5Sopenharmony_ci
1459fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateLiveIfThenElse) {
1460fd4e5da5Sopenharmony_ci  // #version 450
1461fd4e5da5Sopenharmony_ci  //
1462fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
1463fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
1464fd4e5da5Sopenharmony_ci  //
1465fd4e5da5Sopenharmony_ci  // void main()
1466fd4e5da5Sopenharmony_ci  // {
1467fd4e5da5Sopenharmony_ci  //     float t;
1468fd4e5da5Sopenharmony_ci  //     if (BaseColor.x == 0)
1469fd4e5da5Sopenharmony_ci  //       t = BaseColor.y;
1470fd4e5da5Sopenharmony_ci  //     else
1471fd4e5da5Sopenharmony_ci  //       t = BaseColor.z;
1472fd4e5da5Sopenharmony_ci  //     OutColor = vec4(t);
1473fd4e5da5Sopenharmony_ci  // }
1474fd4e5da5Sopenharmony_ci
1475fd4e5da5Sopenharmony_ci  const std::string assembly =
1476fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1477fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1478fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1479fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %OutColor
1480fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1481fd4e5da5Sopenharmony_ciOpSource GLSL 450
1482fd4e5da5Sopenharmony_ciOpName %main "main"
1483fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1484fd4e5da5Sopenharmony_ciOpName %t "t"
1485fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
1486fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
1487fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
1488fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1489fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
1490fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1491fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1492fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1493fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1494fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1495fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
1496fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
1497fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1498fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1499fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1500fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
1501fd4e5da5Sopenharmony_ci%uint_2 = OpConstant %uint 2
1502fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1503fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
1504fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
1505fd4e5da5Sopenharmony_ci%20 = OpLabel
1506fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
1507fd4e5da5Sopenharmony_ci%21 = OpAccessChain %_ptr_Input_float %BaseColor %uint_0
1508fd4e5da5Sopenharmony_ci%22 = OpLoad %float %21
1509fd4e5da5Sopenharmony_ci%23 = OpFOrdEqual %bool %22 %float_0
1510fd4e5da5Sopenharmony_ciOpSelectionMerge %24 None
1511fd4e5da5Sopenharmony_ciOpBranchConditional %23 %25 %26
1512fd4e5da5Sopenharmony_ci%25 = OpLabel
1513fd4e5da5Sopenharmony_ci%27 = OpAccessChain %_ptr_Input_float %BaseColor %uint_1
1514fd4e5da5Sopenharmony_ci%28 = OpLoad %float %27
1515fd4e5da5Sopenharmony_ciOpStore %t %28
1516fd4e5da5Sopenharmony_ciOpBranch %24
1517fd4e5da5Sopenharmony_ci%26 = OpLabel
1518fd4e5da5Sopenharmony_ci%29 = OpAccessChain %_ptr_Input_float %BaseColor %uint_2
1519fd4e5da5Sopenharmony_ci%30 = OpLoad %float %29
1520fd4e5da5Sopenharmony_ciOpStore %t %30
1521fd4e5da5Sopenharmony_ciOpBranch %24
1522fd4e5da5Sopenharmony_ci%24 = OpLabel
1523fd4e5da5Sopenharmony_ci%31 = OpLoad %float %t
1524fd4e5da5Sopenharmony_ci%32 = OpCompositeConstruct %v4float %31 %31 %31 %31
1525fd4e5da5Sopenharmony_ciOpStore %OutColor %32
1526fd4e5da5Sopenharmony_ciOpReturn
1527fd4e5da5Sopenharmony_ciOpFunctionEnd
1528fd4e5da5Sopenharmony_ci)";
1529fd4e5da5Sopenharmony_ci
1530fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
1531fd4e5da5Sopenharmony_ci}
1532fd4e5da5Sopenharmony_ci
1533fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateLiveIfThenElseNested) {
1534fd4e5da5Sopenharmony_ci  // #version 450
1535fd4e5da5Sopenharmony_ci  //
1536fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
1537fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
1538fd4e5da5Sopenharmony_ci  //
1539fd4e5da5Sopenharmony_ci  // void main()
1540fd4e5da5Sopenharmony_ci  // {
1541fd4e5da5Sopenharmony_ci  //     float t;
1542fd4e5da5Sopenharmony_ci  //     if (BaseColor.x == 0)
1543fd4e5da5Sopenharmony_ci  //       if (BaseColor.y == 0)
1544fd4e5da5Sopenharmony_ci  //         t = 0.0;
1545fd4e5da5Sopenharmony_ci  //       else
1546fd4e5da5Sopenharmony_ci  //         t = 0.25;
1547fd4e5da5Sopenharmony_ci  //     else
1548fd4e5da5Sopenharmony_ci  //       if (BaseColor.y == 0)
1549fd4e5da5Sopenharmony_ci  //         t = 0.5;
1550fd4e5da5Sopenharmony_ci  //       else
1551fd4e5da5Sopenharmony_ci  //         t = 0.75;
1552fd4e5da5Sopenharmony_ci  //     OutColor = vec4(t);
1553fd4e5da5Sopenharmony_ci  // }
1554fd4e5da5Sopenharmony_ci
1555fd4e5da5Sopenharmony_ci  const std::string assembly =
1556fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1557fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1558fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1559fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %OutColor
1560fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1561fd4e5da5Sopenharmony_ciOpSource GLSL 450
1562fd4e5da5Sopenharmony_ciOpName %main "main"
1563fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1564fd4e5da5Sopenharmony_ciOpName %t "t"
1565fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
1566fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
1567fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
1568fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1569fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
1570fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1571fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1572fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1573fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1574fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1575fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
1576fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
1577fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1578fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1579fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
1580fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1581fd4e5da5Sopenharmony_ci%float_0_25 = OpConstant %float 0.25
1582fd4e5da5Sopenharmony_ci%float_0_5 = OpConstant %float 0.5
1583fd4e5da5Sopenharmony_ci%float_0_75 = OpConstant %float 0.75
1584fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1585fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
1586fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
1587fd4e5da5Sopenharmony_ci%22 = OpLabel
1588fd4e5da5Sopenharmony_ci%t = OpVariable %_ptr_Function_float Function
1589fd4e5da5Sopenharmony_ci%23 = OpAccessChain %_ptr_Input_float %BaseColor %uint_0
1590fd4e5da5Sopenharmony_ci%24 = OpLoad %float %23
1591fd4e5da5Sopenharmony_ci%25 = OpFOrdEqual %bool %24 %float_0
1592fd4e5da5Sopenharmony_ciOpSelectionMerge %26 None
1593fd4e5da5Sopenharmony_ciOpBranchConditional %25 %27 %28
1594fd4e5da5Sopenharmony_ci%27 = OpLabel
1595fd4e5da5Sopenharmony_ci%29 = OpAccessChain %_ptr_Input_float %BaseColor %uint_1
1596fd4e5da5Sopenharmony_ci%30 = OpLoad %float %29
1597fd4e5da5Sopenharmony_ci%31 = OpFOrdEqual %bool %30 %float_0
1598fd4e5da5Sopenharmony_ciOpSelectionMerge %32 None
1599fd4e5da5Sopenharmony_ciOpBranchConditional %31 %33 %34
1600fd4e5da5Sopenharmony_ci%33 = OpLabel
1601fd4e5da5Sopenharmony_ciOpStore %t %float_0
1602fd4e5da5Sopenharmony_ciOpBranch %32
1603fd4e5da5Sopenharmony_ci%34 = OpLabel
1604fd4e5da5Sopenharmony_ciOpStore %t %float_0_25
1605fd4e5da5Sopenharmony_ciOpBranch %32
1606fd4e5da5Sopenharmony_ci%32 = OpLabel
1607fd4e5da5Sopenharmony_ciOpBranch %26
1608fd4e5da5Sopenharmony_ci%28 = OpLabel
1609fd4e5da5Sopenharmony_ci%35 = OpAccessChain %_ptr_Input_float %BaseColor %uint_1
1610fd4e5da5Sopenharmony_ci%36 = OpLoad %float %35
1611fd4e5da5Sopenharmony_ci%37 = OpFOrdEqual %bool %36 %float_0
1612fd4e5da5Sopenharmony_ciOpSelectionMerge %38 None
1613fd4e5da5Sopenharmony_ciOpBranchConditional %37 %39 %40
1614fd4e5da5Sopenharmony_ci%39 = OpLabel
1615fd4e5da5Sopenharmony_ciOpStore %t %float_0_5
1616fd4e5da5Sopenharmony_ciOpBranch %38
1617fd4e5da5Sopenharmony_ci%40 = OpLabel
1618fd4e5da5Sopenharmony_ciOpStore %t %float_0_75
1619fd4e5da5Sopenharmony_ciOpBranch %38
1620fd4e5da5Sopenharmony_ci%38 = OpLabel
1621fd4e5da5Sopenharmony_ciOpBranch %26
1622fd4e5da5Sopenharmony_ci%26 = OpLabel
1623fd4e5da5Sopenharmony_ci%41 = OpLoad %float %t
1624fd4e5da5Sopenharmony_ci%42 = OpCompositeConstruct %v4float %41 %41 %41 %41
1625fd4e5da5Sopenharmony_ciOpStore %OutColor %42
1626fd4e5da5Sopenharmony_ciOpReturn
1627fd4e5da5Sopenharmony_ciOpFunctionEnd
1628fd4e5da5Sopenharmony_ci)";
1629fd4e5da5Sopenharmony_ci
1630fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
1631fd4e5da5Sopenharmony_ci}
1632fd4e5da5Sopenharmony_ci
1633fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateIfWithPhi) {
1634fd4e5da5Sopenharmony_ci  // Note: Assembly hand-optimized from GLSL
1635fd4e5da5Sopenharmony_ci  //
1636fd4e5da5Sopenharmony_ci  // #version 450
1637fd4e5da5Sopenharmony_ci  //
1638fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
1639fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
1640fd4e5da5Sopenharmony_ci  //
1641fd4e5da5Sopenharmony_ci  // void main()
1642fd4e5da5Sopenharmony_ci  // {
1643fd4e5da5Sopenharmony_ci  //     float t;
1644fd4e5da5Sopenharmony_ci  //     if (BaseColor.x == 0)
1645fd4e5da5Sopenharmony_ci  //       t = 0.0;
1646fd4e5da5Sopenharmony_ci  //     else
1647fd4e5da5Sopenharmony_ci  //       t = 1.0;
1648fd4e5da5Sopenharmony_ci  //     OutColor = vec4(t);
1649fd4e5da5Sopenharmony_ci  // }
1650fd4e5da5Sopenharmony_ci
1651fd4e5da5Sopenharmony_ci  const std::string assembly =
1652fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1653fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1654fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1655fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %OutColor
1656fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1657fd4e5da5Sopenharmony_ciOpSource GLSL 450
1658fd4e5da5Sopenharmony_ciOpName %main "main"
1659fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1660fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
1661fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
1662fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
1663fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1664fd4e5da5Sopenharmony_ci%6 = OpTypeFunction %void
1665fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1666fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1667fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1668fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1669fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1670fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
1671fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
1672fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1673fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1674fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
1675fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1676fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
1677fd4e5da5Sopenharmony_ci%main = OpFunction %void None %6
1678fd4e5da5Sopenharmony_ci%17 = OpLabel
1679fd4e5da5Sopenharmony_ci%18 = OpAccessChain %_ptr_Input_float %BaseColor %uint_0
1680fd4e5da5Sopenharmony_ci%19 = OpLoad %float %18
1681fd4e5da5Sopenharmony_ci%20 = OpFOrdEqual %bool %19 %float_0
1682fd4e5da5Sopenharmony_ciOpSelectionMerge %21 None
1683fd4e5da5Sopenharmony_ciOpBranchConditional %20 %22 %23
1684fd4e5da5Sopenharmony_ci%22 = OpLabel
1685fd4e5da5Sopenharmony_ciOpBranch %21
1686fd4e5da5Sopenharmony_ci%23 = OpLabel
1687fd4e5da5Sopenharmony_ciOpBranch %21
1688fd4e5da5Sopenharmony_ci%21 = OpLabel
1689fd4e5da5Sopenharmony_ci%24 = OpPhi %float %float_0 %22 %float_1 %23
1690fd4e5da5Sopenharmony_ci%25 = OpCompositeConstruct %v4float %24 %24 %24 %24
1691fd4e5da5Sopenharmony_ciOpStore %OutColor %25
1692fd4e5da5Sopenharmony_ciOpReturn
1693fd4e5da5Sopenharmony_ciOpFunctionEnd
1694fd4e5da5Sopenharmony_ci)";
1695fd4e5da5Sopenharmony_ci
1696fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
1697fd4e5da5Sopenharmony_ci}
1698fd4e5da5Sopenharmony_ci
1699fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateIfBreak) {
1700fd4e5da5Sopenharmony_ci  // Note: Assembly optimized from GLSL
1701fd4e5da5Sopenharmony_ci  //
1702fd4e5da5Sopenharmony_ci  // #version 450
1703fd4e5da5Sopenharmony_ci  //
1704fd4e5da5Sopenharmony_ci  // layout(location=0) in vec4 InColor;
1705fd4e5da5Sopenharmony_ci  // layout(location=0) out vec4 OutColor;
1706fd4e5da5Sopenharmony_ci  //
1707fd4e5da5Sopenharmony_ci  // void main()
1708fd4e5da5Sopenharmony_ci  // {
1709fd4e5da5Sopenharmony_ci  //     float f = 0.0;
1710fd4e5da5Sopenharmony_ci  //     for (;;) {
1711fd4e5da5Sopenharmony_ci  //         f += 2.0;
1712fd4e5da5Sopenharmony_ci  //         if (f > 20.0)
1713fd4e5da5Sopenharmony_ci  //             break;
1714fd4e5da5Sopenharmony_ci  //     }
1715fd4e5da5Sopenharmony_ci  //
1716fd4e5da5Sopenharmony_ci  //     OutColor = InColor / f;
1717fd4e5da5Sopenharmony_ci  // }
1718fd4e5da5Sopenharmony_ci
1719fd4e5da5Sopenharmony_ci  const std::string assembly =
1720fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1721fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1722fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1723fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %OutColor %InColor
1724fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1725fd4e5da5Sopenharmony_ciOpSource GLSL 450
1726fd4e5da5Sopenharmony_ciOpName %main "main"
1727fd4e5da5Sopenharmony_ciOpName %f "f"
1728fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
1729fd4e5da5Sopenharmony_ciOpName %InColor "InColor"
1730fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
1731fd4e5da5Sopenharmony_ciOpDecorate %InColor Location 0
1732fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1733fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
1734fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1735fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1736fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1737fd4e5da5Sopenharmony_ci%float_2 = OpConstant %float 2
1738fd4e5da5Sopenharmony_ci%float_20 = OpConstant %float 20
1739fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1740fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1741fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1742fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
1743fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1744fd4e5da5Sopenharmony_ci%InColor = OpVariable %_ptr_Input_v4float Input
1745fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
1746fd4e5da5Sopenharmony_ci%17 = OpLabel
1747fd4e5da5Sopenharmony_ci%f = OpVariable %_ptr_Function_float Function
1748fd4e5da5Sopenharmony_ciOpStore %f %float_0
1749fd4e5da5Sopenharmony_ciOpBranch %18
1750fd4e5da5Sopenharmony_ci%18 = OpLabel
1751fd4e5da5Sopenharmony_ciOpLoopMerge %19 %20 None
1752fd4e5da5Sopenharmony_ciOpBranch %21
1753fd4e5da5Sopenharmony_ci%21 = OpLabel
1754fd4e5da5Sopenharmony_ci%22 = OpLoad %float %f
1755fd4e5da5Sopenharmony_ci%23 = OpFAdd %float %22 %float_2
1756fd4e5da5Sopenharmony_ciOpStore %f %23
1757fd4e5da5Sopenharmony_ci%24 = OpLoad %float %f
1758fd4e5da5Sopenharmony_ci%25 = OpFOrdGreaterThan %bool %24 %float_20
1759fd4e5da5Sopenharmony_ciOpSelectionMerge %26 None
1760fd4e5da5Sopenharmony_ciOpBranchConditional %25 %27 %26
1761fd4e5da5Sopenharmony_ci%27 = OpLabel
1762fd4e5da5Sopenharmony_ciOpBranch %19
1763fd4e5da5Sopenharmony_ci%26 = OpLabel
1764fd4e5da5Sopenharmony_ciOpBranch %20
1765fd4e5da5Sopenharmony_ci%20 = OpLabel
1766fd4e5da5Sopenharmony_ciOpBranch %18
1767fd4e5da5Sopenharmony_ci%19 = OpLabel
1768fd4e5da5Sopenharmony_ci%28 = OpLoad %v4float %InColor
1769fd4e5da5Sopenharmony_ci%29 = OpLoad %float %f
1770fd4e5da5Sopenharmony_ci%30 = OpCompositeConstruct %v4float %29 %29 %29 %29
1771fd4e5da5Sopenharmony_ci%31 = OpFDiv %v4float %28 %30
1772fd4e5da5Sopenharmony_ciOpStore %OutColor %31
1773fd4e5da5Sopenharmony_ciOpReturn
1774fd4e5da5Sopenharmony_ciOpFunctionEnd
1775fd4e5da5Sopenharmony_ci)";
1776fd4e5da5Sopenharmony_ci
1777fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
1778fd4e5da5Sopenharmony_ci}
1779fd4e5da5Sopenharmony_ci
1780fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateIfBreak2) {
1781fd4e5da5Sopenharmony_ci  // Do not eliminate break as conditional branch with merge instruction
1782fd4e5da5Sopenharmony_ci  // Note: SPIR-V edited to add merge instruction before break.
1783fd4e5da5Sopenharmony_ci  //
1784fd4e5da5Sopenharmony_ci  // #version 430
1785fd4e5da5Sopenharmony_ci  //
1786fd4e5da5Sopenharmony_ci  // layout(std430) buffer U_t
1787fd4e5da5Sopenharmony_ci  // {
1788fd4e5da5Sopenharmony_ci  //     float g_F[10];
1789fd4e5da5Sopenharmony_ci  // };
1790fd4e5da5Sopenharmony_ci  //
1791fd4e5da5Sopenharmony_ci  // layout(location = 0)out float o;
1792fd4e5da5Sopenharmony_ci  //
1793fd4e5da5Sopenharmony_ci  // void main(void)
1794fd4e5da5Sopenharmony_ci  // {
1795fd4e5da5Sopenharmony_ci  //     float s = 0.0;
1796fd4e5da5Sopenharmony_ci  //     for (int i=0; i<10; i++)
1797fd4e5da5Sopenharmony_ci  //         s += g_F[i];
1798fd4e5da5Sopenharmony_ci  //     o = s;
1799fd4e5da5Sopenharmony_ci  // }
1800fd4e5da5Sopenharmony_ci
1801fd4e5da5Sopenharmony_ci  const std::string assembly =
1802fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1803fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1804fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1805fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
1806fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1807fd4e5da5Sopenharmony_ciOpSource GLSL 430
1808fd4e5da5Sopenharmony_ciOpName %main "main"
1809fd4e5da5Sopenharmony_ciOpName %s "s"
1810fd4e5da5Sopenharmony_ciOpName %i "i"
1811fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
1812fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_F"
1813fd4e5da5Sopenharmony_ciOpName %_ ""
1814fd4e5da5Sopenharmony_ciOpName %o "o"
1815fd4e5da5Sopenharmony_ciOpDecorate %_arr_float_uint_10 ArrayStride 4
1816fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 0 Offset 0
1817fd4e5da5Sopenharmony_ciOpDecorate %U_t BufferBlock
1818fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
1819fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
1820fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1821fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
1822fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1823fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1824fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1825fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1826fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
1827fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1828fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
1829fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1830fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
1831fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
1832fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10
1833fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %_arr_float_uint_10
1834fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
1835fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
1836fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
1837fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
1838fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
1839fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
1840fd4e5da5Sopenharmony_ci%main = OpFunction %void None %10
1841fd4e5da5Sopenharmony_ci%25 = OpLabel
1842fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_Function_float Function
1843fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
1844fd4e5da5Sopenharmony_ciOpStore %s %float_0
1845fd4e5da5Sopenharmony_ciOpStore %i %int_0
1846fd4e5da5Sopenharmony_ciOpBranch %26
1847fd4e5da5Sopenharmony_ci%26 = OpLabel
1848fd4e5da5Sopenharmony_ciOpLoopMerge %27 %28 None
1849fd4e5da5Sopenharmony_ciOpBranch %29
1850fd4e5da5Sopenharmony_ci%29 = OpLabel
1851fd4e5da5Sopenharmony_ci%30 = OpLoad %int %i
1852fd4e5da5Sopenharmony_ci%31 = OpSLessThan %bool %30 %int_10
1853fd4e5da5Sopenharmony_ciOpSelectionMerge %32 None
1854fd4e5da5Sopenharmony_ciOpBranchConditional %31 %32 %27
1855fd4e5da5Sopenharmony_ci%32 = OpLabel
1856fd4e5da5Sopenharmony_ci%33 = OpLoad %int %i
1857fd4e5da5Sopenharmony_ci%34 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %33
1858fd4e5da5Sopenharmony_ci%35 = OpLoad %float %34
1859fd4e5da5Sopenharmony_ci%36 = OpLoad %float %s
1860fd4e5da5Sopenharmony_ci%37 = OpFAdd %float %36 %35
1861fd4e5da5Sopenharmony_ciOpStore %s %37
1862fd4e5da5Sopenharmony_ciOpBranch %28
1863fd4e5da5Sopenharmony_ci%28 = OpLabel
1864fd4e5da5Sopenharmony_ci%38 = OpLoad %int %i
1865fd4e5da5Sopenharmony_ci%39 = OpIAdd %int %38 %int_1
1866fd4e5da5Sopenharmony_ciOpStore %i %39
1867fd4e5da5Sopenharmony_ciOpBranch %26
1868fd4e5da5Sopenharmony_ci%27 = OpLabel
1869fd4e5da5Sopenharmony_ci%40 = OpLoad %float %s
1870fd4e5da5Sopenharmony_ciOpStore %o %40
1871fd4e5da5Sopenharmony_ciOpReturn
1872fd4e5da5Sopenharmony_ciOpFunctionEnd
1873fd4e5da5Sopenharmony_ci)";
1874fd4e5da5Sopenharmony_ci
1875fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
1876fd4e5da5Sopenharmony_ci}
1877fd4e5da5Sopenharmony_ci
1878fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateEntireUselessLoop) {
1879fd4e5da5Sopenharmony_ci  // #version 140
1880fd4e5da5Sopenharmony_ci  // in vec4 BaseColor;
1881fd4e5da5Sopenharmony_ci  //
1882fd4e5da5Sopenharmony_ci  // layout(std140) uniform U_t
1883fd4e5da5Sopenharmony_ci  // {
1884fd4e5da5Sopenharmony_ci  //     int g_I ;
1885fd4e5da5Sopenharmony_ci  // } ;
1886fd4e5da5Sopenharmony_ci  //
1887fd4e5da5Sopenharmony_ci  // void main()
1888fd4e5da5Sopenharmony_ci  // {
1889fd4e5da5Sopenharmony_ci  //     vec4 v = BaseColor;
1890fd4e5da5Sopenharmony_ci  //     float df = 0.0;
1891fd4e5da5Sopenharmony_ci  //     int i = 0;
1892fd4e5da5Sopenharmony_ci  //     while (i < g_I) {
1893fd4e5da5Sopenharmony_ci  //       df = df * 0.5;
1894fd4e5da5Sopenharmony_ci  //       i = i + 1;
1895fd4e5da5Sopenharmony_ci  //     }
1896fd4e5da5Sopenharmony_ci  //     gl_FragColor = v;
1897fd4e5da5Sopenharmony_ci  // }
1898fd4e5da5Sopenharmony_ci
1899fd4e5da5Sopenharmony_ci  const std::string predefs1 =
1900fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
1901fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
1902fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
1903fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %gl_FragColor
1904fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
1905fd4e5da5Sopenharmony_ciOpSource GLSL 140
1906fd4e5da5Sopenharmony_ci)";
1907fd4e5da5Sopenharmony_ci
1908fd4e5da5Sopenharmony_ci  const std::string names_before =
1909fd4e5da5Sopenharmony_ci      R"(OpName %main "main"
1910fd4e5da5Sopenharmony_ciOpName %v "v"
1911fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1912fd4e5da5Sopenharmony_ciOpName %df "df"
1913fd4e5da5Sopenharmony_ciOpName %i "i"
1914fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
1915fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_I"
1916fd4e5da5Sopenharmony_ciOpName %_ ""
1917fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
1918fd4e5da5Sopenharmony_ci)";
1919fd4e5da5Sopenharmony_ci
1920fd4e5da5Sopenharmony_ci  const std::string names_after =
1921fd4e5da5Sopenharmony_ci      R"(OpName %main "main"
1922fd4e5da5Sopenharmony_ciOpName %v "v"
1923fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
1924fd4e5da5Sopenharmony_ciOpName %gl_FragColor "gl_FragColor"
1925fd4e5da5Sopenharmony_ci)";
1926fd4e5da5Sopenharmony_ci
1927fd4e5da5Sopenharmony_ci  const std::string predefs2_before =
1928fd4e5da5Sopenharmony_ci      R"(OpMemberDecorate %U_t 0 Offset 0
1929fd4e5da5Sopenharmony_ciOpDecorate %U_t Block
1930fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
1931fd4e5da5Sopenharmony_ci%void = OpTypeVoid
1932fd4e5da5Sopenharmony_ci%11 = OpTypeFunction %void
1933fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1934fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1935fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
1936fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1937fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1938fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
1939fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
1940fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
1941fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
1942fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
1943fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %int
1944fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
1945fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
1946fd4e5da5Sopenharmony_ci%_ptr_Uniform_int = OpTypePointer Uniform %int
1947fd4e5da5Sopenharmony_ci%bool = OpTypeBool
1948fd4e5da5Sopenharmony_ci%float_0_5 = OpConstant %float 0.5
1949fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
1950fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1951fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
1952fd4e5da5Sopenharmony_ci)";
1953fd4e5da5Sopenharmony_ci
1954fd4e5da5Sopenharmony_ci  const std::string predefs2_after =
1955fd4e5da5Sopenharmony_ci      R"(%void = OpTypeVoid
1956fd4e5da5Sopenharmony_ci%11 = OpTypeFunction %void
1957fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
1958fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
1959fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
1960fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
1961fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
1962fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
1963fd4e5da5Sopenharmony_ci%gl_FragColor = OpVariable %_ptr_Output_v4float Output
1964fd4e5da5Sopenharmony_ci)";
1965fd4e5da5Sopenharmony_ci
1966fd4e5da5Sopenharmony_ci  const std::string func_before =
1967fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %11
1968fd4e5da5Sopenharmony_ci%27 = OpLabel
1969fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
1970fd4e5da5Sopenharmony_ci%df = OpVariable %_ptr_Function_float Function
1971fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
1972fd4e5da5Sopenharmony_ci%28 = OpLoad %v4float %BaseColor
1973fd4e5da5Sopenharmony_ciOpStore %v %28
1974fd4e5da5Sopenharmony_ciOpStore %df %float_0
1975fd4e5da5Sopenharmony_ciOpStore %i %int_0
1976fd4e5da5Sopenharmony_ciOpBranch %29
1977fd4e5da5Sopenharmony_ci%29 = OpLabel
1978fd4e5da5Sopenharmony_ciOpLoopMerge %30 %31 None
1979fd4e5da5Sopenharmony_ciOpBranch %32
1980fd4e5da5Sopenharmony_ci%32 = OpLabel
1981fd4e5da5Sopenharmony_ci%33 = OpLoad %int %i
1982fd4e5da5Sopenharmony_ci%34 = OpAccessChain %_ptr_Uniform_int %_ %int_0
1983fd4e5da5Sopenharmony_ci%35 = OpLoad %int %34
1984fd4e5da5Sopenharmony_ci%36 = OpSLessThan %bool %33 %35
1985fd4e5da5Sopenharmony_ciOpBranchConditional %36 %37 %30
1986fd4e5da5Sopenharmony_ci%37 = OpLabel
1987fd4e5da5Sopenharmony_ci%38 = OpLoad %float %df
1988fd4e5da5Sopenharmony_ci%39 = OpFMul %float %38 %float_0_5
1989fd4e5da5Sopenharmony_ciOpStore %df %39
1990fd4e5da5Sopenharmony_ci%40 = OpLoad %int %i
1991fd4e5da5Sopenharmony_ci%41 = OpIAdd %int %40 %int_1
1992fd4e5da5Sopenharmony_ciOpStore %i %41
1993fd4e5da5Sopenharmony_ciOpBranch %31
1994fd4e5da5Sopenharmony_ci%31 = OpLabel
1995fd4e5da5Sopenharmony_ciOpBranch %29
1996fd4e5da5Sopenharmony_ci%30 = OpLabel
1997fd4e5da5Sopenharmony_ci%42 = OpLoad %v4float %v
1998fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %42
1999fd4e5da5Sopenharmony_ciOpReturn
2000fd4e5da5Sopenharmony_ciOpFunctionEnd
2001fd4e5da5Sopenharmony_ci)";
2002fd4e5da5Sopenharmony_ci
2003fd4e5da5Sopenharmony_ci  const std::string func_after =
2004fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %11
2005fd4e5da5Sopenharmony_ci%27 = OpLabel
2006fd4e5da5Sopenharmony_ci%v = OpVariable %_ptr_Function_v4float Function
2007fd4e5da5Sopenharmony_ci%28 = OpLoad %v4float %BaseColor
2008fd4e5da5Sopenharmony_ciOpStore %v %28
2009fd4e5da5Sopenharmony_ciOpBranch %29
2010fd4e5da5Sopenharmony_ci%29 = OpLabel
2011fd4e5da5Sopenharmony_ciOpBranch %30
2012fd4e5da5Sopenharmony_ci%30 = OpLabel
2013fd4e5da5Sopenharmony_ci%42 = OpLoad %v4float %v
2014fd4e5da5Sopenharmony_ciOpStore %gl_FragColor %42
2015fd4e5da5Sopenharmony_ciOpReturn
2016fd4e5da5Sopenharmony_ciOpFunctionEnd
2017fd4e5da5Sopenharmony_ci)";
2018fd4e5da5Sopenharmony_ci
2019fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(
2020fd4e5da5Sopenharmony_ci      predefs1 + names_before + predefs2_before + func_before,
2021fd4e5da5Sopenharmony_ci      predefs1 + names_after + predefs2_after + func_after, true, true);
2022fd4e5da5Sopenharmony_ci}
2023fd4e5da5Sopenharmony_ci
2024fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateBusyLoop) {
2025fd4e5da5Sopenharmony_ci  // Note: SPIR-V edited to replace AtomicAdd(i,0) with AtomicLoad(i)
2026fd4e5da5Sopenharmony_ci  //
2027fd4e5da5Sopenharmony_ci  // #version 450
2028fd4e5da5Sopenharmony_ci  //
2029fd4e5da5Sopenharmony_ci  // layout(std430) buffer I_t
2030fd4e5da5Sopenharmony_ci  // {
2031fd4e5da5Sopenharmony_ci  // 	int g_I;
2032fd4e5da5Sopenharmony_ci  // 	int g_I2;
2033fd4e5da5Sopenharmony_ci  // };
2034fd4e5da5Sopenharmony_ci  //
2035fd4e5da5Sopenharmony_ci  // layout(location = 0) out int o;
2036fd4e5da5Sopenharmony_ci  //
2037fd4e5da5Sopenharmony_ci  // void main(void)
2038fd4e5da5Sopenharmony_ci  // {
2039fd4e5da5Sopenharmony_ci  // 	while (atomicAdd(g_I, 0) == 0) {}
2040fd4e5da5Sopenharmony_ci  // 	o = g_I2;
2041fd4e5da5Sopenharmony_ci  // }
2042fd4e5da5Sopenharmony_ci
2043fd4e5da5Sopenharmony_ci  const std::string assembly =
2044fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
2045fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2046fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2047fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
2048fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2049fd4e5da5Sopenharmony_ciOpSource GLSL 450
2050fd4e5da5Sopenharmony_ciOpName %main "main"
2051fd4e5da5Sopenharmony_ciOpName %I_t "I_t"
2052fd4e5da5Sopenharmony_ciOpMemberName %I_t 0 "g_I"
2053fd4e5da5Sopenharmony_ciOpMemberName %I_t 1 "g_I2"
2054fd4e5da5Sopenharmony_ciOpName %_ ""
2055fd4e5da5Sopenharmony_ciOpName %o "o"
2056fd4e5da5Sopenharmony_ciOpMemberDecorate %I_t 0 Offset 0
2057fd4e5da5Sopenharmony_ciOpMemberDecorate %I_t 1 Offset 4
2058fd4e5da5Sopenharmony_ciOpDecorate %I_t BufferBlock
2059fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
2060fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
2061fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2062fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
2063fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2064fd4e5da5Sopenharmony_ci%I_t = OpTypeStruct %int %int
2065fd4e5da5Sopenharmony_ci%_ptr_Uniform_I_t = OpTypePointer Uniform %I_t
2066fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_I_t Uniform
2067fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2068fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2069fd4e5da5Sopenharmony_ci%_ptr_Uniform_int = OpTypePointer Uniform %int
2070fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2071fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
2072fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
2073fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2074fd4e5da5Sopenharmony_ci%_ptr_Output_int = OpTypePointer Output %int
2075fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_int Output
2076fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
2077fd4e5da5Sopenharmony_ci%18 = OpLabel
2078fd4e5da5Sopenharmony_ciOpBranch %19
2079fd4e5da5Sopenharmony_ci%19 = OpLabel
2080fd4e5da5Sopenharmony_ciOpLoopMerge %20 %21 None
2081fd4e5da5Sopenharmony_ciOpBranch %22
2082fd4e5da5Sopenharmony_ci%22 = OpLabel
2083fd4e5da5Sopenharmony_ci%23 = OpAccessChain %_ptr_Uniform_int %_ %int_0
2084fd4e5da5Sopenharmony_ci%24 = OpAtomicLoad %int %23 %uint_1 %uint_0
2085fd4e5da5Sopenharmony_ci%25 = OpIEqual %bool %24 %int_0
2086fd4e5da5Sopenharmony_ciOpBranchConditional %25 %26 %20
2087fd4e5da5Sopenharmony_ci%26 = OpLabel
2088fd4e5da5Sopenharmony_ciOpBranch %21
2089fd4e5da5Sopenharmony_ci%21 = OpLabel
2090fd4e5da5Sopenharmony_ciOpBranch %19
2091fd4e5da5Sopenharmony_ci%20 = OpLabel
2092fd4e5da5Sopenharmony_ci%27 = OpAccessChain %_ptr_Uniform_int %_ %int_1
2093fd4e5da5Sopenharmony_ci%28 = OpLoad %int %27
2094fd4e5da5Sopenharmony_ciOpStore %o %28
2095fd4e5da5Sopenharmony_ciOpReturn
2096fd4e5da5Sopenharmony_ciOpFunctionEnd
2097fd4e5da5Sopenharmony_ci)";
2098fd4e5da5Sopenharmony_ci
2099fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
2100fd4e5da5Sopenharmony_ci}
2101fd4e5da5Sopenharmony_ci
2102fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateLiveLoop) {
2103fd4e5da5Sopenharmony_ci  // Note: SPIR-V optimized
2104fd4e5da5Sopenharmony_ci  //
2105fd4e5da5Sopenharmony_ci  // #version 430
2106fd4e5da5Sopenharmony_ci  //
2107fd4e5da5Sopenharmony_ci  // layout(std430) buffer U_t
2108fd4e5da5Sopenharmony_ci  // {
2109fd4e5da5Sopenharmony_ci  //     float g_F[10];
2110fd4e5da5Sopenharmony_ci  // };
2111fd4e5da5Sopenharmony_ci  //
2112fd4e5da5Sopenharmony_ci  // layout(location = 0)out float o;
2113fd4e5da5Sopenharmony_ci  //
2114fd4e5da5Sopenharmony_ci  // void main(void)
2115fd4e5da5Sopenharmony_ci  // {
2116fd4e5da5Sopenharmony_ci  //     float s = 0.0;
2117fd4e5da5Sopenharmony_ci  //     for (int i=0; i<10; i++)
2118fd4e5da5Sopenharmony_ci  //         s += g_F[i];
2119fd4e5da5Sopenharmony_ci  //     o = s;
2120fd4e5da5Sopenharmony_ci  // }
2121fd4e5da5Sopenharmony_ci
2122fd4e5da5Sopenharmony_ci  const std::string assembly =
2123fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
2124fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2125fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2126fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
2127fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2128fd4e5da5Sopenharmony_ciOpSource GLSL 430
2129fd4e5da5Sopenharmony_ciOpName %main "main"
2130fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
2131fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_F"
2132fd4e5da5Sopenharmony_ciOpName %_ ""
2133fd4e5da5Sopenharmony_ciOpName %o "o"
2134fd4e5da5Sopenharmony_ciOpDecorate %_arr_float_uint_10 ArrayStride 4
2135fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 0 Offset 0
2136fd4e5da5Sopenharmony_ciOpDecorate %U_t BufferBlock
2137fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
2138fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
2139fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2140fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
2141fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2142fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2143fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2144fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2145fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
2146fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2147fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2148fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
2149fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10
2150fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %_arr_float_uint_10
2151fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
2152fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
2153fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2154fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2155fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2156fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
2157fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
2158fd4e5da5Sopenharmony_ci%21 = OpLabel
2159fd4e5da5Sopenharmony_ciOpBranch %22
2160fd4e5da5Sopenharmony_ci%22 = OpLabel
2161fd4e5da5Sopenharmony_ci%23 = OpPhi %float %float_0 %21 %24 %25
2162fd4e5da5Sopenharmony_ci%26 = OpPhi %int %int_0 %21 %27 %25
2163fd4e5da5Sopenharmony_ciOpLoopMerge %28 %25 None
2164fd4e5da5Sopenharmony_ciOpBranch %29
2165fd4e5da5Sopenharmony_ci%29 = OpLabel
2166fd4e5da5Sopenharmony_ci%30 = OpSLessThan %bool %26 %int_10
2167fd4e5da5Sopenharmony_ciOpBranchConditional %30 %31 %28
2168fd4e5da5Sopenharmony_ci%31 = OpLabel
2169fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %26
2170fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
2171fd4e5da5Sopenharmony_ci%24 = OpFAdd %float %23 %33
2172fd4e5da5Sopenharmony_ciOpBranch %25
2173fd4e5da5Sopenharmony_ci%25 = OpLabel
2174fd4e5da5Sopenharmony_ci%27 = OpIAdd %int %26 %int_1
2175fd4e5da5Sopenharmony_ciOpBranch %22
2176fd4e5da5Sopenharmony_ci%28 = OpLabel
2177fd4e5da5Sopenharmony_ciOpStore %o %23
2178fd4e5da5Sopenharmony_ciOpReturn
2179fd4e5da5Sopenharmony_ciOpFunctionEnd
2180fd4e5da5Sopenharmony_ci)";
2181fd4e5da5Sopenharmony_ci
2182fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
2183fd4e5da5Sopenharmony_ci}
2184fd4e5da5Sopenharmony_ci
2185fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateEntireFunctionBody) {
2186fd4e5da5Sopenharmony_ci  // #version 450
2187fd4e5da5Sopenharmony_ci  //
2188fd4e5da5Sopenharmony_ci  // layout(location = 0) in vec4 BaseColor;
2189fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 OutColor;
2190fd4e5da5Sopenharmony_ci  //
2191fd4e5da5Sopenharmony_ci  // void main()
2192fd4e5da5Sopenharmony_ci  // {
2193fd4e5da5Sopenharmony_ci  //     float d;
2194fd4e5da5Sopenharmony_ci  //     if (BaseColor.x == 0)
2195fd4e5da5Sopenharmony_ci  //       d = BaseColor.y;
2196fd4e5da5Sopenharmony_ci  //     else
2197fd4e5da5Sopenharmony_ci  //       d = BaseColor.z;
2198fd4e5da5Sopenharmony_ci  // }
2199fd4e5da5Sopenharmony_ci
2200fd4e5da5Sopenharmony_ci  const std::string spirv =
2201fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
2202fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2203fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2204fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %BaseColor %OutColor
2205fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2206fd4e5da5Sopenharmony_ciOpSource GLSL 450
2207fd4e5da5Sopenharmony_ciOpName %main "main"
2208fd4e5da5Sopenharmony_ciOpName %BaseColor "BaseColor"
2209fd4e5da5Sopenharmony_ciOpName %d "d"
2210fd4e5da5Sopenharmony_ciOpName %OutColor "OutColor"
2211fd4e5da5Sopenharmony_ciOpDecorate %BaseColor Location 0
2212fd4e5da5Sopenharmony_ciOpDecorate %OutColor Location 0
2213fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2214fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
2215fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2216fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
2217fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
2218fd4e5da5Sopenharmony_ci%BaseColor = OpVariable %_ptr_Input_v4float Input
2219fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2220fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
2221fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
2222fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2223fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2224fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2225fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
2226fd4e5da5Sopenharmony_ci%uint_2 = OpConstant %uint 2
2227fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
2228fd4e5da5Sopenharmony_ci%OutColor = OpVariable %_ptr_Output_v4float Output
2229fd4e5da5Sopenharmony_ci
2230fd4e5da5Sopenharmony_ci; CHECK: = OpFunction
2231fd4e5da5Sopenharmony_ci; CHECK-NEXT: = OpLabel
2232fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[target:%\w+]]
2233fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[target]] = OpLabel
2234fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpReturn
2235fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpFunctionEnd
2236fd4e5da5Sopenharmony_ci
2237fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
2238fd4e5da5Sopenharmony_ci%20 = OpLabel
2239fd4e5da5Sopenharmony_ci%d = OpVariable %_ptr_Function_float Function
2240fd4e5da5Sopenharmony_ci%21 = OpAccessChain %_ptr_Input_float %BaseColor %uint_0
2241fd4e5da5Sopenharmony_ci%22 = OpLoad %float %21
2242fd4e5da5Sopenharmony_ci%23 = OpFOrdEqual %bool %22 %float_0
2243fd4e5da5Sopenharmony_ciOpSelectionMerge %24 None
2244fd4e5da5Sopenharmony_ciOpBranchConditional %23 %25 %26
2245fd4e5da5Sopenharmony_ci%25 = OpLabel
2246fd4e5da5Sopenharmony_ci%27 = OpAccessChain %_ptr_Input_float %BaseColor %uint_1
2247fd4e5da5Sopenharmony_ci%28 = OpLoad %float %27
2248fd4e5da5Sopenharmony_ciOpStore %d %28
2249fd4e5da5Sopenharmony_ciOpBranch %24
2250fd4e5da5Sopenharmony_ci%26 = OpLabel
2251fd4e5da5Sopenharmony_ci%29 = OpAccessChain %_ptr_Input_float %BaseColor %uint_2
2252fd4e5da5Sopenharmony_ci%30 = OpLoad %float %29
2253fd4e5da5Sopenharmony_ciOpStore %d %30
2254fd4e5da5Sopenharmony_ciOpBranch %24
2255fd4e5da5Sopenharmony_ci%24 = OpLabel
2256fd4e5da5Sopenharmony_ciOpReturn
2257fd4e5da5Sopenharmony_ciOpFunctionEnd
2258fd4e5da5Sopenharmony_ci)";
2259fd4e5da5Sopenharmony_ci
2260fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
2261fd4e5da5Sopenharmony_ci}
2262fd4e5da5Sopenharmony_ci
2263fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateUselessInnerLoop) {
2264fd4e5da5Sopenharmony_ci  // #version 430
2265fd4e5da5Sopenharmony_ci  //
2266fd4e5da5Sopenharmony_ci  // layout(std430) buffer U_t
2267fd4e5da5Sopenharmony_ci  // {
2268fd4e5da5Sopenharmony_ci  //     float g_F[10];
2269fd4e5da5Sopenharmony_ci  // };
2270fd4e5da5Sopenharmony_ci  //
2271fd4e5da5Sopenharmony_ci  // layout(location = 0)out float o;
2272fd4e5da5Sopenharmony_ci  //
2273fd4e5da5Sopenharmony_ci  // void main(void)
2274fd4e5da5Sopenharmony_ci  // {
2275fd4e5da5Sopenharmony_ci  //     float s = 0.0;
2276fd4e5da5Sopenharmony_ci  //     for (int i=0; i<10; i++) {
2277fd4e5da5Sopenharmony_ci  //         for (int j=0; j<10; j++) {
2278fd4e5da5Sopenharmony_ci  //         }
2279fd4e5da5Sopenharmony_ci  //         s += g_F[i];
2280fd4e5da5Sopenharmony_ci  //     }
2281fd4e5da5Sopenharmony_ci  //     o = s;
2282fd4e5da5Sopenharmony_ci  // }
2283fd4e5da5Sopenharmony_ci
2284fd4e5da5Sopenharmony_ci  const std::string predefs_before =
2285fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
2286fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2287fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2288fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
2289fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2290fd4e5da5Sopenharmony_ciOpSource GLSL 430
2291fd4e5da5Sopenharmony_ciOpName %main "main"
2292fd4e5da5Sopenharmony_ciOpName %s "s"
2293fd4e5da5Sopenharmony_ciOpName %i "i"
2294fd4e5da5Sopenharmony_ciOpName %j "j"
2295fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
2296fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_F"
2297fd4e5da5Sopenharmony_ciOpName %_ ""
2298fd4e5da5Sopenharmony_ciOpName %o "o"
2299fd4e5da5Sopenharmony_ciOpDecorate %_arr_float_uint_10 ArrayStride 4
2300fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 0 Offset 0
2301fd4e5da5Sopenharmony_ciOpDecorate %U_t BufferBlock
2302fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
2303fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
2304fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2305fd4e5da5Sopenharmony_ci%11 = OpTypeFunction %void
2306fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2307fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2308fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2309fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2310fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2311fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2312fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
2313fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2314fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2315fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2316fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
2317fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10
2318fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %_arr_float_uint_10
2319fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
2320fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
2321fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2322fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2323fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
2324fd4e5da5Sopenharmony_ci)";
2325fd4e5da5Sopenharmony_ci
2326fd4e5da5Sopenharmony_ci  const std::string predefs_after =
2327fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
2328fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2329fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2330fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
2331fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2332fd4e5da5Sopenharmony_ciOpSource GLSL 430
2333fd4e5da5Sopenharmony_ciOpName %main "main"
2334fd4e5da5Sopenharmony_ciOpName %s "s"
2335fd4e5da5Sopenharmony_ciOpName %i "i"
2336fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
2337fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_F"
2338fd4e5da5Sopenharmony_ciOpName %_ ""
2339fd4e5da5Sopenharmony_ciOpName %o "o"
2340fd4e5da5Sopenharmony_ciOpDecorate %_arr_float_uint_10 ArrayStride 4
2341fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 0 Offset 0
2342fd4e5da5Sopenharmony_ciOpDecorate %U_t BufferBlock
2343fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
2344fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
2345fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2346fd4e5da5Sopenharmony_ci%11 = OpTypeFunction %void
2347fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2348fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2349fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2350fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2351fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2352fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2353fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
2354fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2355fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2356fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2357fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
2358fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10
2359fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %_arr_float_uint_10
2360fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
2361fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
2362fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2363fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2364fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
2365fd4e5da5Sopenharmony_ci)";
2366fd4e5da5Sopenharmony_ci
2367fd4e5da5Sopenharmony_ci  const std::string func_before =
2368fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %11
2369fd4e5da5Sopenharmony_ci%26 = OpLabel
2370fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_Function_float Function
2371fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
2372fd4e5da5Sopenharmony_ci%j = OpVariable %_ptr_Function_int Function
2373fd4e5da5Sopenharmony_ciOpStore %s %float_0
2374fd4e5da5Sopenharmony_ciOpStore %i %int_0
2375fd4e5da5Sopenharmony_ciOpBranch %27
2376fd4e5da5Sopenharmony_ci%27 = OpLabel
2377fd4e5da5Sopenharmony_ciOpLoopMerge %28 %29 None
2378fd4e5da5Sopenharmony_ciOpBranch %30
2379fd4e5da5Sopenharmony_ci%30 = OpLabel
2380fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
2381fd4e5da5Sopenharmony_ci%32 = OpSLessThan %bool %31 %int_10
2382fd4e5da5Sopenharmony_ciOpBranchConditional %32 %33 %28
2383fd4e5da5Sopenharmony_ci%33 = OpLabel
2384fd4e5da5Sopenharmony_ciOpStore %j %int_0
2385fd4e5da5Sopenharmony_ciOpBranch %34
2386fd4e5da5Sopenharmony_ci%34 = OpLabel
2387fd4e5da5Sopenharmony_ciOpLoopMerge %35 %36 None
2388fd4e5da5Sopenharmony_ciOpBranch %37
2389fd4e5da5Sopenharmony_ci%37 = OpLabel
2390fd4e5da5Sopenharmony_ci%38 = OpLoad %int %j
2391fd4e5da5Sopenharmony_ci%39 = OpSLessThan %bool %38 %int_10
2392fd4e5da5Sopenharmony_ciOpBranchConditional %39 %40 %35
2393fd4e5da5Sopenharmony_ci%40 = OpLabel
2394fd4e5da5Sopenharmony_ciOpBranch %36
2395fd4e5da5Sopenharmony_ci%36 = OpLabel
2396fd4e5da5Sopenharmony_ci%41 = OpLoad %int %j
2397fd4e5da5Sopenharmony_ci%42 = OpIAdd %int %41 %int_1
2398fd4e5da5Sopenharmony_ciOpStore %j %42
2399fd4e5da5Sopenharmony_ciOpBranch %34
2400fd4e5da5Sopenharmony_ci%35 = OpLabel
2401fd4e5da5Sopenharmony_ci%43 = OpLoad %int %i
2402fd4e5da5Sopenharmony_ci%44 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %43
2403fd4e5da5Sopenharmony_ci%45 = OpLoad %float %44
2404fd4e5da5Sopenharmony_ci%46 = OpLoad %float %s
2405fd4e5da5Sopenharmony_ci%47 = OpFAdd %float %46 %45
2406fd4e5da5Sopenharmony_ciOpStore %s %47
2407fd4e5da5Sopenharmony_ciOpBranch %29
2408fd4e5da5Sopenharmony_ci%29 = OpLabel
2409fd4e5da5Sopenharmony_ci%48 = OpLoad %int %i
2410fd4e5da5Sopenharmony_ci%49 = OpIAdd %int %48 %int_1
2411fd4e5da5Sopenharmony_ciOpStore %i %49
2412fd4e5da5Sopenharmony_ciOpBranch %27
2413fd4e5da5Sopenharmony_ci%28 = OpLabel
2414fd4e5da5Sopenharmony_ci%50 = OpLoad %float %s
2415fd4e5da5Sopenharmony_ciOpStore %o %50
2416fd4e5da5Sopenharmony_ciOpReturn
2417fd4e5da5Sopenharmony_ciOpFunctionEnd
2418fd4e5da5Sopenharmony_ci)";
2419fd4e5da5Sopenharmony_ci
2420fd4e5da5Sopenharmony_ci  const std::string func_after =
2421fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %11
2422fd4e5da5Sopenharmony_ci%26 = OpLabel
2423fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_Function_float Function
2424fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
2425fd4e5da5Sopenharmony_ciOpStore %s %float_0
2426fd4e5da5Sopenharmony_ciOpStore %i %int_0
2427fd4e5da5Sopenharmony_ciOpBranch %27
2428fd4e5da5Sopenharmony_ci%27 = OpLabel
2429fd4e5da5Sopenharmony_ciOpLoopMerge %28 %29 None
2430fd4e5da5Sopenharmony_ciOpBranch %30
2431fd4e5da5Sopenharmony_ci%30 = OpLabel
2432fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
2433fd4e5da5Sopenharmony_ci%32 = OpSLessThan %bool %31 %int_10
2434fd4e5da5Sopenharmony_ciOpBranchConditional %32 %33 %28
2435fd4e5da5Sopenharmony_ci%33 = OpLabel
2436fd4e5da5Sopenharmony_ciOpBranch %34
2437fd4e5da5Sopenharmony_ci%34 = OpLabel
2438fd4e5da5Sopenharmony_ciOpBranch %35
2439fd4e5da5Sopenharmony_ci%35 = OpLabel
2440fd4e5da5Sopenharmony_ci%43 = OpLoad %int %i
2441fd4e5da5Sopenharmony_ci%44 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %43
2442fd4e5da5Sopenharmony_ci%45 = OpLoad %float %44
2443fd4e5da5Sopenharmony_ci%46 = OpLoad %float %s
2444fd4e5da5Sopenharmony_ci%47 = OpFAdd %float %46 %45
2445fd4e5da5Sopenharmony_ciOpStore %s %47
2446fd4e5da5Sopenharmony_ciOpBranch %29
2447fd4e5da5Sopenharmony_ci%29 = OpLabel
2448fd4e5da5Sopenharmony_ci%48 = OpLoad %int %i
2449fd4e5da5Sopenharmony_ci%49 = OpIAdd %int %48 %int_1
2450fd4e5da5Sopenharmony_ciOpStore %i %49
2451fd4e5da5Sopenharmony_ciOpBranch %27
2452fd4e5da5Sopenharmony_ci%28 = OpLabel
2453fd4e5da5Sopenharmony_ci%50 = OpLoad %float %s
2454fd4e5da5Sopenharmony_ciOpStore %o %50
2455fd4e5da5Sopenharmony_ciOpReturn
2456fd4e5da5Sopenharmony_ciOpFunctionEnd
2457fd4e5da5Sopenharmony_ci)";
2458fd4e5da5Sopenharmony_ci
2459fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(
2460fd4e5da5Sopenharmony_ci      predefs_before + func_before, predefs_after + func_after, true, true);
2461fd4e5da5Sopenharmony_ci}
2462fd4e5da5Sopenharmony_ci
2463fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateUselessNestedLoopWithIf) {
2464fd4e5da5Sopenharmony_ci  // #version 430
2465fd4e5da5Sopenharmony_ci  //
2466fd4e5da5Sopenharmony_ci  // layout(std430) buffer U_t
2467fd4e5da5Sopenharmony_ci  // {
2468fd4e5da5Sopenharmony_ci  //     float g_F[10][10];
2469fd4e5da5Sopenharmony_ci  // };
2470fd4e5da5Sopenharmony_ci  //
2471fd4e5da5Sopenharmony_ci  // layout(location = 0)out float o;
2472fd4e5da5Sopenharmony_ci  //
2473fd4e5da5Sopenharmony_ci  // void main(void)
2474fd4e5da5Sopenharmony_ci  // {
2475fd4e5da5Sopenharmony_ci  //     float s = 0.0;
2476fd4e5da5Sopenharmony_ci  //     for (int i=0; i<10; i++) {
2477fd4e5da5Sopenharmony_ci  //         for (int j=0; j<10; j++) {
2478fd4e5da5Sopenharmony_ci  //             float t = g_F[i][j];
2479fd4e5da5Sopenharmony_ci  //             if (t > 0.0)
2480fd4e5da5Sopenharmony_ci  //                 s += t;
2481fd4e5da5Sopenharmony_ci  //         }
2482fd4e5da5Sopenharmony_ci  //     }
2483fd4e5da5Sopenharmony_ci  //     o = 0.0;
2484fd4e5da5Sopenharmony_ci  // }
2485fd4e5da5Sopenharmony_ci
2486fd4e5da5Sopenharmony_ci  const std::string predefs_before =
2487fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
2488fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2489fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2490fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
2491fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2492fd4e5da5Sopenharmony_ciOpSource GLSL 430
2493fd4e5da5Sopenharmony_ciOpName %main "main"
2494fd4e5da5Sopenharmony_ciOpName %s "s"
2495fd4e5da5Sopenharmony_ciOpName %i "i"
2496fd4e5da5Sopenharmony_ciOpName %j "j"
2497fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
2498fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_F"
2499fd4e5da5Sopenharmony_ciOpName %_ ""
2500fd4e5da5Sopenharmony_ciOpName %o "o"
2501fd4e5da5Sopenharmony_ciOpDecorate %_arr_float_uint_10 ArrayStride 4
2502fd4e5da5Sopenharmony_ciOpDecorate %_arr__arr_float_uint_10_uint_10 ArrayStride 40
2503fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 0 Offset 0
2504fd4e5da5Sopenharmony_ciOpDecorate %U_t BufferBlock
2505fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
2506fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
2507fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2508fd4e5da5Sopenharmony_ci%12 = OpTypeFunction %void
2509fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2510fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2511fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2512fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2513fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2514fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2515fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
2516fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2517fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2518fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
2519fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10
2520fd4e5da5Sopenharmony_ci%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10
2521fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %_arr__arr_float_uint_10_uint_10
2522fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
2523fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
2524fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2525fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2526fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2527fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
2528fd4e5da5Sopenharmony_ci)";
2529fd4e5da5Sopenharmony_ci
2530fd4e5da5Sopenharmony_ci  const std::string predefs_after =
2531fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
2532fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2533fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2534fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
2535fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2536fd4e5da5Sopenharmony_ciOpSource GLSL 430
2537fd4e5da5Sopenharmony_ciOpName %main "main"
2538fd4e5da5Sopenharmony_ciOpName %o "o"
2539fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
2540fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2541fd4e5da5Sopenharmony_ci%12 = OpTypeFunction %void
2542fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2543fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2544fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2545fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
2546fd4e5da5Sopenharmony_ci)";
2547fd4e5da5Sopenharmony_ci
2548fd4e5da5Sopenharmony_ci  const std::string func_before =
2549fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %12
2550fd4e5da5Sopenharmony_ci%27 = OpLabel
2551fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_Function_float Function
2552fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
2553fd4e5da5Sopenharmony_ci%j = OpVariable %_ptr_Function_int Function
2554fd4e5da5Sopenharmony_ciOpStore %s %float_0
2555fd4e5da5Sopenharmony_ciOpStore %i %int_0
2556fd4e5da5Sopenharmony_ciOpBranch %28
2557fd4e5da5Sopenharmony_ci%28 = OpLabel
2558fd4e5da5Sopenharmony_ciOpLoopMerge %29 %30 None
2559fd4e5da5Sopenharmony_ciOpBranch %31
2560fd4e5da5Sopenharmony_ci%31 = OpLabel
2561fd4e5da5Sopenharmony_ci%32 = OpLoad %int %i
2562fd4e5da5Sopenharmony_ci%33 = OpSLessThan %bool %32 %int_10
2563fd4e5da5Sopenharmony_ciOpBranchConditional %33 %34 %29
2564fd4e5da5Sopenharmony_ci%34 = OpLabel
2565fd4e5da5Sopenharmony_ciOpStore %j %int_0
2566fd4e5da5Sopenharmony_ciOpBranch %35
2567fd4e5da5Sopenharmony_ci%35 = OpLabel
2568fd4e5da5Sopenharmony_ciOpLoopMerge %36 %37 None
2569fd4e5da5Sopenharmony_ciOpBranch %38
2570fd4e5da5Sopenharmony_ci%38 = OpLabel
2571fd4e5da5Sopenharmony_ci%39 = OpLoad %int %j
2572fd4e5da5Sopenharmony_ci%40 = OpSLessThan %bool %39 %int_10
2573fd4e5da5Sopenharmony_ciOpBranchConditional %40 %41 %36
2574fd4e5da5Sopenharmony_ci%41 = OpLabel
2575fd4e5da5Sopenharmony_ci%42 = OpLoad %int %i
2576fd4e5da5Sopenharmony_ci%43 = OpLoad %int %j
2577fd4e5da5Sopenharmony_ci%44 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %42 %43
2578fd4e5da5Sopenharmony_ci%45 = OpLoad %float %44
2579fd4e5da5Sopenharmony_ci%46 = OpFOrdGreaterThan %bool %45 %float_0
2580fd4e5da5Sopenharmony_ciOpSelectionMerge %47 None
2581fd4e5da5Sopenharmony_ciOpBranchConditional %46 %48 %47
2582fd4e5da5Sopenharmony_ci%48 = OpLabel
2583fd4e5da5Sopenharmony_ci%49 = OpLoad %float %s
2584fd4e5da5Sopenharmony_ci%50 = OpFAdd %float %49 %45
2585fd4e5da5Sopenharmony_ciOpStore %s %50
2586fd4e5da5Sopenharmony_ciOpBranch %47
2587fd4e5da5Sopenharmony_ci%47 = OpLabel
2588fd4e5da5Sopenharmony_ciOpBranch %37
2589fd4e5da5Sopenharmony_ci%37 = OpLabel
2590fd4e5da5Sopenharmony_ci%51 = OpLoad %int %j
2591fd4e5da5Sopenharmony_ci%52 = OpIAdd %int %51 %int_1
2592fd4e5da5Sopenharmony_ciOpStore %j %52
2593fd4e5da5Sopenharmony_ciOpBranch %35
2594fd4e5da5Sopenharmony_ci%36 = OpLabel
2595fd4e5da5Sopenharmony_ciOpBranch %30
2596fd4e5da5Sopenharmony_ci%30 = OpLabel
2597fd4e5da5Sopenharmony_ci%53 = OpLoad %int %i
2598fd4e5da5Sopenharmony_ci%54 = OpIAdd %int %53 %int_1
2599fd4e5da5Sopenharmony_ciOpStore %i %54
2600fd4e5da5Sopenharmony_ciOpBranch %28
2601fd4e5da5Sopenharmony_ci%29 = OpLabel
2602fd4e5da5Sopenharmony_ciOpStore %o %float_0
2603fd4e5da5Sopenharmony_ciOpReturn
2604fd4e5da5Sopenharmony_ciOpFunctionEnd
2605fd4e5da5Sopenharmony_ci)";
2606fd4e5da5Sopenharmony_ci
2607fd4e5da5Sopenharmony_ci  const std::string func_after =
2608fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %12
2609fd4e5da5Sopenharmony_ci%27 = OpLabel
2610fd4e5da5Sopenharmony_ciOpBranch %28
2611fd4e5da5Sopenharmony_ci%28 = OpLabel
2612fd4e5da5Sopenharmony_ciOpBranch %29
2613fd4e5da5Sopenharmony_ci%29 = OpLabel
2614fd4e5da5Sopenharmony_ciOpStore %o %float_0
2615fd4e5da5Sopenharmony_ciOpReturn
2616fd4e5da5Sopenharmony_ciOpFunctionEnd
2617fd4e5da5Sopenharmony_ci)";
2618fd4e5da5Sopenharmony_ci
2619fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(
2620fd4e5da5Sopenharmony_ci      predefs_before + func_before, predefs_after + func_after, true, true);
2621fd4e5da5Sopenharmony_ci}
2622fd4e5da5Sopenharmony_ci
2623fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateEmptyIfBeforeContinue) {
2624fd4e5da5Sopenharmony_ci  // #version 430
2625fd4e5da5Sopenharmony_ci  //
2626fd4e5da5Sopenharmony_ci  // layout(location = 0)out float o;
2627fd4e5da5Sopenharmony_ci  //
2628fd4e5da5Sopenharmony_ci  // void main(void)
2629fd4e5da5Sopenharmony_ci  // {
2630fd4e5da5Sopenharmony_ci  //     float s = 0.0;
2631fd4e5da5Sopenharmony_ci  //     for (int i=0; i<10; i++) {
2632fd4e5da5Sopenharmony_ci  //         s += 1.0;
2633fd4e5da5Sopenharmony_ci  //         if (i > s) {}
2634fd4e5da5Sopenharmony_ci  //     }
2635fd4e5da5Sopenharmony_ci  //     o = s;
2636fd4e5da5Sopenharmony_ci  // }
2637fd4e5da5Sopenharmony_ci
2638fd4e5da5Sopenharmony_ci  const std::string predefs_before =
2639fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
2640fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2641fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2642fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %3
2643fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2644fd4e5da5Sopenharmony_ciOpSource GLSL 430
2645fd4e5da5Sopenharmony_ciOpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
2646fd4e5da5Sopenharmony_ciOpSourceExtension "GL_GOOGLE_include_directive"
2647fd4e5da5Sopenharmony_ciOpName %main "main"
2648fd4e5da5Sopenharmony_ciOpDecorate %3 Location 0
2649fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2650fd4e5da5Sopenharmony_ci%5 = OpTypeFunction %void
2651fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2652fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2653fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2654fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2655fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2656fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
2657fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2658fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
2659fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2660fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2661fd4e5da5Sopenharmony_ci%3 = OpVariable %_ptr_Output_float Output
2662fd4e5da5Sopenharmony_ci)";
2663fd4e5da5Sopenharmony_ci
2664fd4e5da5Sopenharmony_ci  const std::string predefs_after =
2665fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
2666fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2667fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2668fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %3
2669fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2670fd4e5da5Sopenharmony_ciOpSource GLSL 430
2671fd4e5da5Sopenharmony_ciOpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
2672fd4e5da5Sopenharmony_ciOpSourceExtension "GL_GOOGLE_include_directive"
2673fd4e5da5Sopenharmony_ciOpName %main "main"
2674fd4e5da5Sopenharmony_ciOpDecorate %3 Location 0
2675fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2676fd4e5da5Sopenharmony_ci%5 = OpTypeFunction %void
2677fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2678fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2679fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2680fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2681fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
2682fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2683fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
2684fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2685fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2686fd4e5da5Sopenharmony_ci%3 = OpVariable %_ptr_Output_float Output
2687fd4e5da5Sopenharmony_ci)";
2688fd4e5da5Sopenharmony_ci
2689fd4e5da5Sopenharmony_ci  const std::string func_before =
2690fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %5
2691fd4e5da5Sopenharmony_ci%16 = OpLabel
2692fd4e5da5Sopenharmony_ciOpBranch %17
2693fd4e5da5Sopenharmony_ci%17 = OpLabel
2694fd4e5da5Sopenharmony_ci%18 = OpPhi %float %float_0 %16 %19 %20
2695fd4e5da5Sopenharmony_ci%21 = OpPhi %int %int_0 %16 %22 %20
2696fd4e5da5Sopenharmony_ciOpLoopMerge %23 %20 None
2697fd4e5da5Sopenharmony_ciOpBranch %24
2698fd4e5da5Sopenharmony_ci%24 = OpLabel
2699fd4e5da5Sopenharmony_ci%25 = OpSLessThan %bool %21 %int_10
2700fd4e5da5Sopenharmony_ciOpBranchConditional %25 %26 %23
2701fd4e5da5Sopenharmony_ci%26 = OpLabel
2702fd4e5da5Sopenharmony_ci%19 = OpFAdd %float %18 %float_1
2703fd4e5da5Sopenharmony_ci%27 = OpConvertFToS %int %19
2704fd4e5da5Sopenharmony_ci%28 = OpSGreaterThan %bool %21 %27
2705fd4e5da5Sopenharmony_ciOpSelectionMerge %20 None
2706fd4e5da5Sopenharmony_ciOpBranchConditional %28 %29 %20
2707fd4e5da5Sopenharmony_ci%29 = OpLabel
2708fd4e5da5Sopenharmony_ciOpBranch %20
2709fd4e5da5Sopenharmony_ci%20 = OpLabel
2710fd4e5da5Sopenharmony_ci%22 = OpIAdd %int %21 %int_1
2711fd4e5da5Sopenharmony_ciOpBranch %17
2712fd4e5da5Sopenharmony_ci%23 = OpLabel
2713fd4e5da5Sopenharmony_ciOpStore %3 %18
2714fd4e5da5Sopenharmony_ciOpReturn
2715fd4e5da5Sopenharmony_ciOpFunctionEnd
2716fd4e5da5Sopenharmony_ci)";
2717fd4e5da5Sopenharmony_ci
2718fd4e5da5Sopenharmony_ci  const std::string func_after =
2719fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %5
2720fd4e5da5Sopenharmony_ci%16 = OpLabel
2721fd4e5da5Sopenharmony_ciOpBranch %17
2722fd4e5da5Sopenharmony_ci%17 = OpLabel
2723fd4e5da5Sopenharmony_ci%18 = OpPhi %float %float_0 %16 %19 %20
2724fd4e5da5Sopenharmony_ci%21 = OpPhi %int %int_0 %16 %22 %20
2725fd4e5da5Sopenharmony_ciOpLoopMerge %23 %20 None
2726fd4e5da5Sopenharmony_ciOpBranch %24
2727fd4e5da5Sopenharmony_ci%24 = OpLabel
2728fd4e5da5Sopenharmony_ci%25 = OpSLessThan %bool %21 %int_10
2729fd4e5da5Sopenharmony_ciOpBranchConditional %25 %26 %23
2730fd4e5da5Sopenharmony_ci%26 = OpLabel
2731fd4e5da5Sopenharmony_ci%19 = OpFAdd %float %18 %float_1
2732fd4e5da5Sopenharmony_ciOpBranch %20
2733fd4e5da5Sopenharmony_ci%20 = OpLabel
2734fd4e5da5Sopenharmony_ci%22 = OpIAdd %int %21 %int_1
2735fd4e5da5Sopenharmony_ciOpBranch %17
2736fd4e5da5Sopenharmony_ci%23 = OpLabel
2737fd4e5da5Sopenharmony_ciOpStore %3 %18
2738fd4e5da5Sopenharmony_ciOpReturn
2739fd4e5da5Sopenharmony_ciOpFunctionEnd
2740fd4e5da5Sopenharmony_ci)";
2741fd4e5da5Sopenharmony_ci
2742fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(
2743fd4e5da5Sopenharmony_ci      predefs_before + func_before, predefs_after + func_after, true, true);
2744fd4e5da5Sopenharmony_ci}
2745fd4e5da5Sopenharmony_ci
2746fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateLiveNestedLoopWithIf) {
2747fd4e5da5Sopenharmony_ci  // Note: SPIR-V optimized
2748fd4e5da5Sopenharmony_ci  //
2749fd4e5da5Sopenharmony_ci  // #version 430
2750fd4e5da5Sopenharmony_ci  //
2751fd4e5da5Sopenharmony_ci  // layout(std430) buffer U_t
2752fd4e5da5Sopenharmony_ci  // {
2753fd4e5da5Sopenharmony_ci  //     float g_F[10][10];
2754fd4e5da5Sopenharmony_ci  // };
2755fd4e5da5Sopenharmony_ci  //
2756fd4e5da5Sopenharmony_ci  // layout(location = 0)out float o;
2757fd4e5da5Sopenharmony_ci  //
2758fd4e5da5Sopenharmony_ci  // void main(void)
2759fd4e5da5Sopenharmony_ci  // {
2760fd4e5da5Sopenharmony_ci  //     float s = 0.0;
2761fd4e5da5Sopenharmony_ci  //     for (int i=0; i<10; i++) {
2762fd4e5da5Sopenharmony_ci  //         for (int j=0; j<10; j++) {
2763fd4e5da5Sopenharmony_ci  //             float t = g_F[i][j];
2764fd4e5da5Sopenharmony_ci  //             if (t > 0.0)
2765fd4e5da5Sopenharmony_ci  //                 s += t;
2766fd4e5da5Sopenharmony_ci  //         }
2767fd4e5da5Sopenharmony_ci  //     }
2768fd4e5da5Sopenharmony_ci  //     o = s;
2769fd4e5da5Sopenharmony_ci  // }
2770fd4e5da5Sopenharmony_ci
2771fd4e5da5Sopenharmony_ci  const std::string assembly =
2772fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
2773fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2774fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2775fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
2776fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2777fd4e5da5Sopenharmony_ciOpSource GLSL 430
2778fd4e5da5Sopenharmony_ciOpName %main "main"
2779fd4e5da5Sopenharmony_ciOpName %s "s"
2780fd4e5da5Sopenharmony_ciOpName %i "i"
2781fd4e5da5Sopenharmony_ciOpName %j "j"
2782fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
2783fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_F"
2784fd4e5da5Sopenharmony_ciOpName %_ ""
2785fd4e5da5Sopenharmony_ciOpName %o "o"
2786fd4e5da5Sopenharmony_ciOpDecorate %_arr_float_uint_10 ArrayStride 4
2787fd4e5da5Sopenharmony_ciOpDecorate %_arr__arr_float_uint_10_uint_10 ArrayStride 40
2788fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 0 Offset 0
2789fd4e5da5Sopenharmony_ciOpDecorate %U_t BufferBlock
2790fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
2791fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
2792fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2793fd4e5da5Sopenharmony_ci%12 = OpTypeFunction %void
2794fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2795fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2796fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2797fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2798fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2799fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2800fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
2801fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2802fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2803fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
2804fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10
2805fd4e5da5Sopenharmony_ci%_arr__arr_float_uint_10_uint_10 = OpTypeArray %_arr_float_uint_10 %uint_10
2806fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %_arr__arr_float_uint_10_uint_10
2807fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
2808fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
2809fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2810fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2811fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2812fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
2813fd4e5da5Sopenharmony_ci%main = OpFunction %void None %12
2814fd4e5da5Sopenharmony_ci%27 = OpLabel
2815fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_Function_float Function
2816fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
2817fd4e5da5Sopenharmony_ci%j = OpVariable %_ptr_Function_int Function
2818fd4e5da5Sopenharmony_ciOpStore %s %float_0
2819fd4e5da5Sopenharmony_ciOpStore %i %int_0
2820fd4e5da5Sopenharmony_ciOpBranch %28
2821fd4e5da5Sopenharmony_ci%28 = OpLabel
2822fd4e5da5Sopenharmony_ciOpLoopMerge %29 %30 None
2823fd4e5da5Sopenharmony_ciOpBranch %31
2824fd4e5da5Sopenharmony_ci%31 = OpLabel
2825fd4e5da5Sopenharmony_ci%32 = OpLoad %int %i
2826fd4e5da5Sopenharmony_ci%33 = OpSLessThan %bool %32 %int_10
2827fd4e5da5Sopenharmony_ciOpBranchConditional %33 %34 %29
2828fd4e5da5Sopenharmony_ci%34 = OpLabel
2829fd4e5da5Sopenharmony_ciOpStore %j %int_0
2830fd4e5da5Sopenharmony_ciOpBranch %35
2831fd4e5da5Sopenharmony_ci%35 = OpLabel
2832fd4e5da5Sopenharmony_ciOpLoopMerge %36 %37 None
2833fd4e5da5Sopenharmony_ciOpBranch %38
2834fd4e5da5Sopenharmony_ci%38 = OpLabel
2835fd4e5da5Sopenharmony_ci%39 = OpLoad %int %j
2836fd4e5da5Sopenharmony_ci%40 = OpSLessThan %bool %39 %int_10
2837fd4e5da5Sopenharmony_ciOpBranchConditional %40 %41 %36
2838fd4e5da5Sopenharmony_ci%41 = OpLabel
2839fd4e5da5Sopenharmony_ci%42 = OpLoad %int %i
2840fd4e5da5Sopenharmony_ci%43 = OpLoad %int %j
2841fd4e5da5Sopenharmony_ci%44 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %42 %43
2842fd4e5da5Sopenharmony_ci%45 = OpLoad %float %44
2843fd4e5da5Sopenharmony_ci%46 = OpFOrdGreaterThan %bool %45 %float_0
2844fd4e5da5Sopenharmony_ciOpSelectionMerge %47 None
2845fd4e5da5Sopenharmony_ciOpBranchConditional %46 %48 %47
2846fd4e5da5Sopenharmony_ci%48 = OpLabel
2847fd4e5da5Sopenharmony_ci%49 = OpLoad %float %s
2848fd4e5da5Sopenharmony_ci%50 = OpFAdd %float %49 %45
2849fd4e5da5Sopenharmony_ciOpStore %s %50
2850fd4e5da5Sopenharmony_ciOpBranch %47
2851fd4e5da5Sopenharmony_ci%47 = OpLabel
2852fd4e5da5Sopenharmony_ciOpBranch %37
2853fd4e5da5Sopenharmony_ci%37 = OpLabel
2854fd4e5da5Sopenharmony_ci%51 = OpLoad %int %j
2855fd4e5da5Sopenharmony_ci%52 = OpIAdd %int %51 %int_1
2856fd4e5da5Sopenharmony_ciOpStore %j %52
2857fd4e5da5Sopenharmony_ciOpBranch %35
2858fd4e5da5Sopenharmony_ci%36 = OpLabel
2859fd4e5da5Sopenharmony_ciOpBranch %30
2860fd4e5da5Sopenharmony_ci%30 = OpLabel
2861fd4e5da5Sopenharmony_ci%53 = OpLoad %int %i
2862fd4e5da5Sopenharmony_ci%54 = OpIAdd %int %53 %int_1
2863fd4e5da5Sopenharmony_ciOpStore %i %54
2864fd4e5da5Sopenharmony_ciOpBranch %28
2865fd4e5da5Sopenharmony_ci%29 = OpLabel
2866fd4e5da5Sopenharmony_ci%55 = OpLoad %float %s
2867fd4e5da5Sopenharmony_ciOpStore %o %55
2868fd4e5da5Sopenharmony_ciOpReturn
2869fd4e5da5Sopenharmony_ciOpFunctionEnd
2870fd4e5da5Sopenharmony_ci)";
2871fd4e5da5Sopenharmony_ci
2872fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
2873fd4e5da5Sopenharmony_ci}
2874fd4e5da5Sopenharmony_ci
2875fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateIfContinue) {
2876fd4e5da5Sopenharmony_ci  // Do not eliminate continue embedded in if construct
2877fd4e5da5Sopenharmony_ci  //
2878fd4e5da5Sopenharmony_ci  // #version 430
2879fd4e5da5Sopenharmony_ci  //
2880fd4e5da5Sopenharmony_ci  // layout(std430) buffer U_t
2881fd4e5da5Sopenharmony_ci  // {
2882fd4e5da5Sopenharmony_ci  //     float g_F[10];
2883fd4e5da5Sopenharmony_ci  // };
2884fd4e5da5Sopenharmony_ci  //
2885fd4e5da5Sopenharmony_ci  // layout(location = 0)out float o;
2886fd4e5da5Sopenharmony_ci  //
2887fd4e5da5Sopenharmony_ci  // void main(void)
2888fd4e5da5Sopenharmony_ci  // {
2889fd4e5da5Sopenharmony_ci  //     float s = 0.0;
2890fd4e5da5Sopenharmony_ci  //     for (int i=0; i<10; i++) {
2891fd4e5da5Sopenharmony_ci  //         if (i % 2 == 0) continue;
2892fd4e5da5Sopenharmony_ci  //         s += g_F[i];
2893fd4e5da5Sopenharmony_ci  //     }
2894fd4e5da5Sopenharmony_ci  //     o = s;
2895fd4e5da5Sopenharmony_ci  // }
2896fd4e5da5Sopenharmony_ci
2897fd4e5da5Sopenharmony_ci  const std::string assembly =
2898fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
2899fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
2900fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
2901fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
2902fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
2903fd4e5da5Sopenharmony_ciOpSource GLSL 430
2904fd4e5da5Sopenharmony_ciOpName %main "main"
2905fd4e5da5Sopenharmony_ciOpName %s "s"
2906fd4e5da5Sopenharmony_ciOpName %i "i"
2907fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
2908fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_F"
2909fd4e5da5Sopenharmony_ciOpName %_ ""
2910fd4e5da5Sopenharmony_ciOpName %o "o"
2911fd4e5da5Sopenharmony_ciOpDecorate %_arr_float_uint_10 ArrayStride 4
2912fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 0 Offset 0
2913fd4e5da5Sopenharmony_ciOpDecorate %U_t BufferBlock
2914fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
2915fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
2916fd4e5da5Sopenharmony_ci%void = OpTypeVoid
2917fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
2918fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
2919fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
2920fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
2921fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
2922fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
2923fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
2924fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
2925fd4e5da5Sopenharmony_ci%bool = OpTypeBool
2926fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
2927fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
2928fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
2929fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10
2930fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %_arr_float_uint_10
2931fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
2932fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
2933fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
2934fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
2935fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
2936fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
2937fd4e5da5Sopenharmony_ci%main = OpFunction %void None %10
2938fd4e5da5Sopenharmony_ci%26 = OpLabel
2939fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_Function_float Function
2940fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
2941fd4e5da5Sopenharmony_ciOpStore %s %float_0
2942fd4e5da5Sopenharmony_ciOpStore %i %int_0
2943fd4e5da5Sopenharmony_ciOpBranch %27
2944fd4e5da5Sopenharmony_ci%27 = OpLabel
2945fd4e5da5Sopenharmony_ciOpLoopMerge %28 %29 None
2946fd4e5da5Sopenharmony_ciOpBranch %30
2947fd4e5da5Sopenharmony_ci%30 = OpLabel
2948fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
2949fd4e5da5Sopenharmony_ci%32 = OpSLessThan %bool %31 %int_10
2950fd4e5da5Sopenharmony_ciOpBranchConditional %32 %33 %28
2951fd4e5da5Sopenharmony_ci%33 = OpLabel
2952fd4e5da5Sopenharmony_ci%34 = OpLoad %int %i
2953fd4e5da5Sopenharmony_ci%35 = OpSMod %int %34 %int_2
2954fd4e5da5Sopenharmony_ci%36 = OpIEqual %bool %35 %int_0
2955fd4e5da5Sopenharmony_ciOpSelectionMerge %37 None
2956fd4e5da5Sopenharmony_ciOpBranchConditional %36 %38 %37
2957fd4e5da5Sopenharmony_ci%38 = OpLabel
2958fd4e5da5Sopenharmony_ciOpBranch %29
2959fd4e5da5Sopenharmony_ci%37 = OpLabel
2960fd4e5da5Sopenharmony_ci%39 = OpLoad %int %i
2961fd4e5da5Sopenharmony_ci%40 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %39
2962fd4e5da5Sopenharmony_ci%41 = OpLoad %float %40
2963fd4e5da5Sopenharmony_ci%42 = OpLoad %float %s
2964fd4e5da5Sopenharmony_ci%43 = OpFAdd %float %42 %41
2965fd4e5da5Sopenharmony_ciOpStore %s %43
2966fd4e5da5Sopenharmony_ciOpBranch %29
2967fd4e5da5Sopenharmony_ci%29 = OpLabel
2968fd4e5da5Sopenharmony_ci%44 = OpLoad %int %i
2969fd4e5da5Sopenharmony_ci%45 = OpIAdd %int %44 %int_1
2970fd4e5da5Sopenharmony_ciOpStore %i %45
2971fd4e5da5Sopenharmony_ciOpBranch %27
2972fd4e5da5Sopenharmony_ci%28 = OpLabel
2973fd4e5da5Sopenharmony_ci%46 = OpLoad %float %s
2974fd4e5da5Sopenharmony_ciOpStore %o %46
2975fd4e5da5Sopenharmony_ciOpReturn
2976fd4e5da5Sopenharmony_ciOpFunctionEnd
2977fd4e5da5Sopenharmony_ci)";
2978fd4e5da5Sopenharmony_ci
2979fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
2980fd4e5da5Sopenharmony_ci}
2981fd4e5da5Sopenharmony_ci
2982fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateIfContinue2) {
2983fd4e5da5Sopenharmony_ci  // Do not eliminate continue not embedded in if construct
2984fd4e5da5Sopenharmony_ci  //
2985fd4e5da5Sopenharmony_ci  // #version 430
2986fd4e5da5Sopenharmony_ci  //
2987fd4e5da5Sopenharmony_ci  // layout(std430) buffer U_t
2988fd4e5da5Sopenharmony_ci  // {
2989fd4e5da5Sopenharmony_ci  //     float g_F[10];
2990fd4e5da5Sopenharmony_ci  // };
2991fd4e5da5Sopenharmony_ci  //
2992fd4e5da5Sopenharmony_ci  // layout(location = 0)out float o;
2993fd4e5da5Sopenharmony_ci  //
2994fd4e5da5Sopenharmony_ci  // void main(void)
2995fd4e5da5Sopenharmony_ci  // {
2996fd4e5da5Sopenharmony_ci  //     float s = 0.0;
2997fd4e5da5Sopenharmony_ci  //     for (int i=0; i<10; i++) {
2998fd4e5da5Sopenharmony_ci  //         if (i % 2 == 0) continue;
2999fd4e5da5Sopenharmony_ci  //         s += g_F[i];
3000fd4e5da5Sopenharmony_ci  //     }
3001fd4e5da5Sopenharmony_ci  //     o = s;
3002fd4e5da5Sopenharmony_ci  // }
3003fd4e5da5Sopenharmony_ci
3004fd4e5da5Sopenharmony_ci  const std::string assembly =
3005fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
3006fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3007fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3008fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
3009fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3010fd4e5da5Sopenharmony_ciOpSource GLSL 430
3011fd4e5da5Sopenharmony_ciOpName %main "main"
3012fd4e5da5Sopenharmony_ciOpName %s "s"
3013fd4e5da5Sopenharmony_ciOpName %i "i"
3014fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
3015fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_F"
3016fd4e5da5Sopenharmony_ciOpName %_ ""
3017fd4e5da5Sopenharmony_ciOpName %o "o"
3018fd4e5da5Sopenharmony_ciOpDecorate %_arr_float_uint_10 ArrayStride 4
3019fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 0 Offset 0
3020fd4e5da5Sopenharmony_ciOpDecorate %U_t BufferBlock
3021fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
3022fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
3023fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3024fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
3025fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3026fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3027fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
3028fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3029fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
3030fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3031fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
3032fd4e5da5Sopenharmony_ci%bool = OpTypeBool
3033fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
3034fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3035fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
3036fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10
3037fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %_arr_float_uint_10
3038fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
3039fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
3040fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
3041fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
3042fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
3043fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
3044fd4e5da5Sopenharmony_ci%main = OpFunction %void None %10
3045fd4e5da5Sopenharmony_ci%26 = OpLabel
3046fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_Function_float Function
3047fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
3048fd4e5da5Sopenharmony_ciOpStore %s %float_0
3049fd4e5da5Sopenharmony_ciOpStore %i %int_0
3050fd4e5da5Sopenharmony_ciOpBranch %27
3051fd4e5da5Sopenharmony_ci%27 = OpLabel
3052fd4e5da5Sopenharmony_ciOpLoopMerge %28 %29 None
3053fd4e5da5Sopenharmony_ciOpBranch %30
3054fd4e5da5Sopenharmony_ci%30 = OpLabel
3055fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
3056fd4e5da5Sopenharmony_ci%32 = OpSLessThan %bool %31 %int_10
3057fd4e5da5Sopenharmony_ciOpBranchConditional %32 %33 %28
3058fd4e5da5Sopenharmony_ci%33 = OpLabel
3059fd4e5da5Sopenharmony_ci%34 = OpLoad %int %i
3060fd4e5da5Sopenharmony_ci%35 = OpSMod %int %34 %int_2
3061fd4e5da5Sopenharmony_ci%36 = OpIEqual %bool %35 %int_0
3062fd4e5da5Sopenharmony_ciOpBranchConditional %36 %29 %37
3063fd4e5da5Sopenharmony_ci%37 = OpLabel
3064fd4e5da5Sopenharmony_ci%38 = OpLoad %int %i
3065fd4e5da5Sopenharmony_ci%39 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %38
3066fd4e5da5Sopenharmony_ci%40 = OpLoad %float %39
3067fd4e5da5Sopenharmony_ci%41 = OpLoad %float %s
3068fd4e5da5Sopenharmony_ci%42 = OpFAdd %float %41 %40
3069fd4e5da5Sopenharmony_ciOpStore %s %42
3070fd4e5da5Sopenharmony_ciOpBranch %29
3071fd4e5da5Sopenharmony_ci%29 = OpLabel
3072fd4e5da5Sopenharmony_ci%43 = OpLoad %int %i
3073fd4e5da5Sopenharmony_ci%44 = OpIAdd %int %43 %int_1
3074fd4e5da5Sopenharmony_ciOpStore %i %44
3075fd4e5da5Sopenharmony_ciOpBranch %27
3076fd4e5da5Sopenharmony_ci%28 = OpLabel
3077fd4e5da5Sopenharmony_ci%45 = OpLoad %float %s
3078fd4e5da5Sopenharmony_ciOpStore %o %45
3079fd4e5da5Sopenharmony_ciOpReturn
3080fd4e5da5Sopenharmony_ciOpFunctionEnd
3081fd4e5da5Sopenharmony_ci)";
3082fd4e5da5Sopenharmony_ci
3083fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
3084fd4e5da5Sopenharmony_ci}
3085fd4e5da5Sopenharmony_ci
3086fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateIfContinue3) {
3087fd4e5da5Sopenharmony_ci  // Do not eliminate continue as conditional branch with merge instruction
3088fd4e5da5Sopenharmony_ci  // Note: SPIR-V edited to add merge instruction before continue.
3089fd4e5da5Sopenharmony_ci  //
3090fd4e5da5Sopenharmony_ci  // #version 430
3091fd4e5da5Sopenharmony_ci  //
3092fd4e5da5Sopenharmony_ci  // layout(std430) buffer U_t
3093fd4e5da5Sopenharmony_ci  // {
3094fd4e5da5Sopenharmony_ci  //     float g_F[10];
3095fd4e5da5Sopenharmony_ci  // };
3096fd4e5da5Sopenharmony_ci  //
3097fd4e5da5Sopenharmony_ci  // layout(location = 0)out float o;
3098fd4e5da5Sopenharmony_ci  //
3099fd4e5da5Sopenharmony_ci  // void main(void)
3100fd4e5da5Sopenharmony_ci  // {
3101fd4e5da5Sopenharmony_ci  //     float s = 0.0;
3102fd4e5da5Sopenharmony_ci  //     for (int i=0; i<10; i++) {
3103fd4e5da5Sopenharmony_ci  //         if (i % 2 == 0) continue;
3104fd4e5da5Sopenharmony_ci  //         s += g_F[i];
3105fd4e5da5Sopenharmony_ci  //     }
3106fd4e5da5Sopenharmony_ci  //     o = s;
3107fd4e5da5Sopenharmony_ci  // }
3108fd4e5da5Sopenharmony_ci
3109fd4e5da5Sopenharmony_ci  const std::string assembly =
3110fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
3111fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3112fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3113fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
3114fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3115fd4e5da5Sopenharmony_ciOpSource GLSL 430
3116fd4e5da5Sopenharmony_ciOpName %main "main"
3117fd4e5da5Sopenharmony_ciOpName %s "s"
3118fd4e5da5Sopenharmony_ciOpName %i "i"
3119fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
3120fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_F"
3121fd4e5da5Sopenharmony_ciOpName %_ ""
3122fd4e5da5Sopenharmony_ciOpName %o "o"
3123fd4e5da5Sopenharmony_ciOpDecorate %_arr_float_uint_10 ArrayStride 4
3124fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 0 Offset 0
3125fd4e5da5Sopenharmony_ciOpDecorate %U_t BufferBlock
3126fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
3127fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
3128fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3129fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
3130fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3131fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3132fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
3133fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3134fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
3135fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3136fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
3137fd4e5da5Sopenharmony_ci%bool = OpTypeBool
3138fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
3139fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3140fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
3141fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10
3142fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %_arr_float_uint_10
3143fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
3144fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
3145fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
3146fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
3147fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
3148fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
3149fd4e5da5Sopenharmony_ci%main = OpFunction %void None %10
3150fd4e5da5Sopenharmony_ci%26 = OpLabel
3151fd4e5da5Sopenharmony_ci%s = OpVariable %_ptr_Function_float Function
3152fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
3153fd4e5da5Sopenharmony_ciOpStore %s %float_0
3154fd4e5da5Sopenharmony_ciOpStore %i %int_0
3155fd4e5da5Sopenharmony_ciOpBranch %27
3156fd4e5da5Sopenharmony_ci%27 = OpLabel
3157fd4e5da5Sopenharmony_ciOpLoopMerge %28 %29 None
3158fd4e5da5Sopenharmony_ciOpBranch %30
3159fd4e5da5Sopenharmony_ci%30 = OpLabel
3160fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
3161fd4e5da5Sopenharmony_ci%32 = OpSLessThan %bool %31 %int_10
3162fd4e5da5Sopenharmony_ciOpBranchConditional %32 %33 %28
3163fd4e5da5Sopenharmony_ci%33 = OpLabel
3164fd4e5da5Sopenharmony_ci%34 = OpLoad %int %i
3165fd4e5da5Sopenharmony_ci%35 = OpSMod %int %34 %int_2
3166fd4e5da5Sopenharmony_ci%36 = OpIEqual %bool %35 %int_0
3167fd4e5da5Sopenharmony_ciOpSelectionMerge %37 None
3168fd4e5da5Sopenharmony_ciOpBranchConditional %36 %29 %37
3169fd4e5da5Sopenharmony_ci%37 = OpLabel
3170fd4e5da5Sopenharmony_ci%38 = OpLoad %int %i
3171fd4e5da5Sopenharmony_ci%39 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %38
3172fd4e5da5Sopenharmony_ci%40 = OpLoad %float %39
3173fd4e5da5Sopenharmony_ci%41 = OpLoad %float %s
3174fd4e5da5Sopenharmony_ci%42 = OpFAdd %float %41 %40
3175fd4e5da5Sopenharmony_ciOpStore %s %42
3176fd4e5da5Sopenharmony_ciOpBranch %29
3177fd4e5da5Sopenharmony_ci%29 = OpLabel
3178fd4e5da5Sopenharmony_ci%43 = OpLoad %int %i
3179fd4e5da5Sopenharmony_ci%44 = OpIAdd %int %43 %int_1
3180fd4e5da5Sopenharmony_ciOpStore %i %44
3181fd4e5da5Sopenharmony_ciOpBranch %27
3182fd4e5da5Sopenharmony_ci%28 = OpLabel
3183fd4e5da5Sopenharmony_ci%45 = OpLoad %float %s
3184fd4e5da5Sopenharmony_ciOpStore %o %45
3185fd4e5da5Sopenharmony_ciOpReturn
3186fd4e5da5Sopenharmony_ciOpFunctionEnd
3187fd4e5da5Sopenharmony_ci)";
3188fd4e5da5Sopenharmony_ci
3189fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(assembly, assembly, true, true);
3190fd4e5da5Sopenharmony_ci}
3191fd4e5da5Sopenharmony_ci
3192fd4e5da5Sopenharmony_ci// This is not valid input and ADCE does not support variable pointers and only
3193fd4e5da5Sopenharmony_ci// supports shaders.
3194fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, PointerVariable) {
3195fd4e5da5Sopenharmony_ci  // ADCE is able to handle code that contains a load whose base address
3196fd4e5da5Sopenharmony_ci  // comes from a load and not an OpVariable.  I want to see an instruction
3197fd4e5da5Sopenharmony_ci  // removed to be sure that ADCE is not exiting early.
3198fd4e5da5Sopenharmony_ci
3199fd4e5da5Sopenharmony_ci  const std::string before =
3200fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
3201fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3202fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %1 "main" %2
3203fd4e5da5Sopenharmony_ciOpExecutionMode %1 OriginUpperLeft
3204fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_3 0 Offset 0
3205fd4e5da5Sopenharmony_ciOpDecorate %_runtimearr__struct_3 ArrayStride 16
3206fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_5 0 Offset 0
3207fd4e5da5Sopenharmony_ciOpDecorate %_struct_5 BufferBlock
3208fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_6 0 Offset 0
3209fd4e5da5Sopenharmony_ciOpDecorate %_struct_6 BufferBlock
3210fd4e5da5Sopenharmony_ciOpDecorate %2 Location 0
3211fd4e5da5Sopenharmony_ciOpDecorate %7 DescriptorSet 0
3212fd4e5da5Sopenharmony_ciOpDecorate %7 Binding 0
3213fd4e5da5Sopenharmony_ciOpDecorate %8 DescriptorSet 0
3214fd4e5da5Sopenharmony_ciOpDecorate %8 Binding 1
3215fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3216fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
3217fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3218fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3219fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3220fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3221fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
3222fd4e5da5Sopenharmony_ci%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
3223fd4e5da5Sopenharmony_ci%_struct_3 = OpTypeStruct %v4float
3224fd4e5da5Sopenharmony_ci%_runtimearr__struct_3 = OpTypeRuntimeArray %_struct_3
3225fd4e5da5Sopenharmony_ci%_struct_5 = OpTypeStruct %_runtimearr__struct_3
3226fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_5 = OpTypePointer Uniform %_struct_5
3227fd4e5da5Sopenharmony_ci%_struct_6 = OpTypeStruct %int
3228fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_6 = OpTypePointer Uniform %_struct_6
3229fd4e5da5Sopenharmony_ci%_ptr_Function__ptr_Uniform__struct_5 = OpTypePointer Function %_ptr_Uniform__struct_5
3230fd4e5da5Sopenharmony_ci%_ptr_Function__ptr_Uniform__struct_6 = OpTypePointer Function %_ptr_Uniform__struct_6
3231fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3232fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
3233fd4e5da5Sopenharmony_ci%2 = OpVariable %_ptr_Output_v4float Output
3234fd4e5da5Sopenharmony_ci%7 = OpVariable %_ptr_Uniform__struct_5 Uniform
3235fd4e5da5Sopenharmony_ci%8 = OpVariable %_ptr_Uniform__struct_6 Uniform
3236fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %10
3237fd4e5da5Sopenharmony_ci%23 = OpLabel
3238fd4e5da5Sopenharmony_ci%24 = OpVariable %_ptr_Function__ptr_Uniform__struct_5 Function
3239fd4e5da5Sopenharmony_ciOpStore %24 %7
3240fd4e5da5Sopenharmony_ci%26 = OpLoad %_ptr_Uniform__struct_5 %24
3241fd4e5da5Sopenharmony_ci%27 = OpAccessChain %_ptr_Uniform_v4float %26 %int_0 %uint_0 %int_0
3242fd4e5da5Sopenharmony_ci%28 = OpLoad %v4float %27
3243fd4e5da5Sopenharmony_ci%29 = OpCopyObject %v4float %28
3244fd4e5da5Sopenharmony_ciOpStore %2 %28
3245fd4e5da5Sopenharmony_ciOpReturn
3246fd4e5da5Sopenharmony_ciOpFunctionEnd
3247fd4e5da5Sopenharmony_ci)";
3248fd4e5da5Sopenharmony_ci
3249fd4e5da5Sopenharmony_ci  const std::string after =
3250fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
3251fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3252fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %1 "main" %2
3253fd4e5da5Sopenharmony_ciOpExecutionMode %1 OriginUpperLeft
3254fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_3 0 Offset 0
3255fd4e5da5Sopenharmony_ciOpDecorate %_runtimearr__struct_3 ArrayStride 16
3256fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_5 0 Offset 0
3257fd4e5da5Sopenharmony_ciOpDecorate %_struct_5 BufferBlock
3258fd4e5da5Sopenharmony_ciOpDecorate %2 Location 0
3259fd4e5da5Sopenharmony_ciOpDecorate %7 DescriptorSet 0
3260fd4e5da5Sopenharmony_ciOpDecorate %7 Binding 0
3261fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3262fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
3263fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3264fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3265fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3266fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
3267fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
3268fd4e5da5Sopenharmony_ci%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
3269fd4e5da5Sopenharmony_ci%_struct_3 = OpTypeStruct %v4float
3270fd4e5da5Sopenharmony_ci%_runtimearr__struct_3 = OpTypeRuntimeArray %_struct_3
3271fd4e5da5Sopenharmony_ci%_struct_5 = OpTypeStruct %_runtimearr__struct_3
3272fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_5 = OpTypePointer Uniform %_struct_5
3273fd4e5da5Sopenharmony_ci%_ptr_Function__ptr_Uniform__struct_5 = OpTypePointer Function %_ptr_Uniform__struct_5
3274fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3275fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
3276fd4e5da5Sopenharmony_ci%2 = OpVariable %_ptr_Output_v4float Output
3277fd4e5da5Sopenharmony_ci%7 = OpVariable %_ptr_Uniform__struct_5 Uniform
3278fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %10
3279fd4e5da5Sopenharmony_ci%23 = OpLabel
3280fd4e5da5Sopenharmony_ci%24 = OpVariable %_ptr_Function__ptr_Uniform__struct_5 Function
3281fd4e5da5Sopenharmony_ciOpStore %24 %7
3282fd4e5da5Sopenharmony_ci%25 = OpLoad %_ptr_Uniform__struct_5 %24
3283fd4e5da5Sopenharmony_ci%26 = OpAccessChain %_ptr_Uniform_v4float %25 %int_0 %uint_0 %int_0
3284fd4e5da5Sopenharmony_ci%27 = OpLoad %v4float %26
3285fd4e5da5Sopenharmony_ciOpStore %2 %27
3286fd4e5da5Sopenharmony_ciOpReturn
3287fd4e5da5Sopenharmony_ciOpFunctionEnd
3288fd4e5da5Sopenharmony_ci)";
3289fd4e5da5Sopenharmony_ci
3290fd4e5da5Sopenharmony_ci  // The input is not valid and ADCE only supports shaders, but not variable
3291fd4e5da5Sopenharmony_ci  // pointers. Workaround this by enabling relaxed logical pointers in the
3292fd4e5da5Sopenharmony_ci  // validator.
3293fd4e5da5Sopenharmony_ci  ValidatorOptions()->relax_logical_pointer = true;
3294fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(before, after, true, true);
3295fd4e5da5Sopenharmony_ci}
3296fd4e5da5Sopenharmony_ci
3297fd4e5da5Sopenharmony_ci// %dead is unused.  Make sure we remove it along with its name.
3298fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, RemoveUnreferenced) {
3299fd4e5da5Sopenharmony_ci  const std::string before =
3300fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
3301fd4e5da5Sopenharmony_ciOpCapability Linkage
3302fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3303fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3304fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
3305fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3306fd4e5da5Sopenharmony_ciOpSource GLSL 150
3307fd4e5da5Sopenharmony_ciOpName %main "main"
3308fd4e5da5Sopenharmony_ciOpName %dead "dead"
3309fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3310fd4e5da5Sopenharmony_ci%5 = OpTypeFunction %void
3311fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3312fd4e5da5Sopenharmony_ci%_ptr_Private_float = OpTypePointer Private %float
3313fd4e5da5Sopenharmony_ci%dead = OpVariable %_ptr_Private_float Private
3314fd4e5da5Sopenharmony_ci%main = OpFunction %void None %5
3315fd4e5da5Sopenharmony_ci%8 = OpLabel
3316fd4e5da5Sopenharmony_ciOpReturn
3317fd4e5da5Sopenharmony_ciOpFunctionEnd
3318fd4e5da5Sopenharmony_ci)";
3319fd4e5da5Sopenharmony_ci
3320fd4e5da5Sopenharmony_ci  const std::string after =
3321fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
3322fd4e5da5Sopenharmony_ciOpCapability Linkage
3323fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3324fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3325fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
3326fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3327fd4e5da5Sopenharmony_ciOpSource GLSL 150
3328fd4e5da5Sopenharmony_ciOpName %main "main"
3329fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3330fd4e5da5Sopenharmony_ci%5 = OpTypeFunction %void
3331fd4e5da5Sopenharmony_ci%main = OpFunction %void None %5
3332fd4e5da5Sopenharmony_ci%8 = OpLabel
3333fd4e5da5Sopenharmony_ciOpReturn
3334fd4e5da5Sopenharmony_ciOpFunctionEnd
3335fd4e5da5Sopenharmony_ci)";
3336fd4e5da5Sopenharmony_ci
3337fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3338fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(before, after, true, true);
3339fd4e5da5Sopenharmony_ci}
3340fd4e5da5Sopenharmony_ci
3341fd4e5da5Sopenharmony_ci// Delete %dead because it is unreferenced.  Then %initializer becomes
3342fd4e5da5Sopenharmony_ci// unreferenced, so remove it as well.
3343fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, RemoveUnreferencedWithInit1) {
3344fd4e5da5Sopenharmony_ci  const std::string before =
3345fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
3346fd4e5da5Sopenharmony_ciOpCapability Linkage
3347fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3348fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3349fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
3350fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3351fd4e5da5Sopenharmony_ciOpSource GLSL 150
3352fd4e5da5Sopenharmony_ciOpName %main "main"
3353fd4e5da5Sopenharmony_ciOpName %dead "dead"
3354fd4e5da5Sopenharmony_ciOpName %initializer "initializer"
3355fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3356fd4e5da5Sopenharmony_ci%6 = OpTypeFunction %void
3357fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3358fd4e5da5Sopenharmony_ci%_ptr_Private_float = OpTypePointer Private %float
3359fd4e5da5Sopenharmony_ci%initializer = OpVariable %_ptr_Private_float Private
3360fd4e5da5Sopenharmony_ci%dead = OpVariable %_ptr_Private_float Private %initializer
3361fd4e5da5Sopenharmony_ci%main = OpFunction %void None %6
3362fd4e5da5Sopenharmony_ci%9 = OpLabel
3363fd4e5da5Sopenharmony_ciOpReturn
3364fd4e5da5Sopenharmony_ciOpFunctionEnd
3365fd4e5da5Sopenharmony_ci)";
3366fd4e5da5Sopenharmony_ci
3367fd4e5da5Sopenharmony_ci  const std::string after =
3368fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
3369fd4e5da5Sopenharmony_ciOpCapability Linkage
3370fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3371fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3372fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
3373fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3374fd4e5da5Sopenharmony_ciOpSource GLSL 150
3375fd4e5da5Sopenharmony_ciOpName %main "main"
3376fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3377fd4e5da5Sopenharmony_ci%6 = OpTypeFunction %void
3378fd4e5da5Sopenharmony_ci%main = OpFunction %void None %6
3379fd4e5da5Sopenharmony_ci%9 = OpLabel
3380fd4e5da5Sopenharmony_ciOpReturn
3381fd4e5da5Sopenharmony_ciOpFunctionEnd
3382fd4e5da5Sopenharmony_ci)";
3383fd4e5da5Sopenharmony_ci
3384fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3385fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(before, after, true, true);
3386fd4e5da5Sopenharmony_ci}
3387fd4e5da5Sopenharmony_ci
3388fd4e5da5Sopenharmony_ci// Keep %live because it is used, and its initializer.
3389fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, KeepReferenced) {
3390fd4e5da5Sopenharmony_ci  const std::string before =
3391fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
3392fd4e5da5Sopenharmony_ciOpCapability Linkage
3393fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3394fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3395fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %output
3396fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
3397fd4e5da5Sopenharmony_ciOpSource GLSL 150
3398fd4e5da5Sopenharmony_ciOpName %main "main"
3399fd4e5da5Sopenharmony_ciOpName %live "live"
3400fd4e5da5Sopenharmony_ciOpName %initializer "initializer"
3401fd4e5da5Sopenharmony_ciOpName %output "output"
3402fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3403fd4e5da5Sopenharmony_ci%6 = OpTypeFunction %void
3404fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
3405fd4e5da5Sopenharmony_ci%_ptr_Private_float = OpTypePointer Private %float
3406fd4e5da5Sopenharmony_ci%initializer = OpConstant %float 0
3407fd4e5da5Sopenharmony_ci%live = OpVariable %_ptr_Private_float Private %initializer
3408fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
3409fd4e5da5Sopenharmony_ci%output = OpVariable %_ptr_Output_float Output
3410fd4e5da5Sopenharmony_ci%main = OpFunction %void None %6
3411fd4e5da5Sopenharmony_ci%9 = OpLabel
3412fd4e5da5Sopenharmony_ci%10 = OpLoad %float %live
3413fd4e5da5Sopenharmony_ciOpStore %output %10
3414fd4e5da5Sopenharmony_ciOpReturn
3415fd4e5da5Sopenharmony_ciOpFunctionEnd
3416fd4e5da5Sopenharmony_ci)";
3417fd4e5da5Sopenharmony_ci
3418fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3419fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(before, before, true, true);
3420fd4e5da5Sopenharmony_ci}
3421fd4e5da5Sopenharmony_ci
3422fd4e5da5Sopenharmony_ci// This test that the decoration associated with a variable are removed when the
3423fd4e5da5Sopenharmony_ci// variable is removed.
3424fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, RemoveVariableAndDecorations) {
3425fd4e5da5Sopenharmony_ci  const std::string before =
3426fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
3427fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3428fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3429fd4e5da5Sopenharmony_ciOpEntryPoint Vertex %main "main"
3430fd4e5da5Sopenharmony_ciOpSource GLSL 450
3431fd4e5da5Sopenharmony_ciOpName %main "main"
3432fd4e5da5Sopenharmony_ciOpName %B "B"
3433fd4e5da5Sopenharmony_ciOpMemberName %B 0 "a"
3434fd4e5da5Sopenharmony_ciOpName %Bdat "Bdat"
3435fd4e5da5Sopenharmony_ciOpMemberDecorate %B 0 Offset 0
3436fd4e5da5Sopenharmony_ciOpDecorate %B BufferBlock
3437fd4e5da5Sopenharmony_ciOpDecorate %Bdat DescriptorSet 0
3438fd4e5da5Sopenharmony_ciOpDecorate %Bdat Binding 0
3439fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3440fd4e5da5Sopenharmony_ci%6 = OpTypeFunction %void
3441fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3442fd4e5da5Sopenharmony_ci%B = OpTypeStruct %uint
3443fd4e5da5Sopenharmony_ci%_ptr_Uniform_B = OpTypePointer Uniform %B
3444fd4e5da5Sopenharmony_ci%Bdat = OpVariable %_ptr_Uniform_B Uniform
3445fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
3446fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
3447fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
3448fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
3449fd4e5da5Sopenharmony_ci%main = OpFunction %void None %6
3450fd4e5da5Sopenharmony_ci%13 = OpLabel
3451fd4e5da5Sopenharmony_ciOpReturn
3452fd4e5da5Sopenharmony_ciOpFunctionEnd
3453fd4e5da5Sopenharmony_ci)";
3454fd4e5da5Sopenharmony_ci
3455fd4e5da5Sopenharmony_ci  const std::string after =
3456fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
3457fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
3458fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3459fd4e5da5Sopenharmony_ciOpEntryPoint Vertex %main "main"
3460fd4e5da5Sopenharmony_ciOpSource GLSL 450
3461fd4e5da5Sopenharmony_ciOpName %main "main"
3462fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3463fd4e5da5Sopenharmony_ci%6 = OpTypeFunction %void
3464fd4e5da5Sopenharmony_ci%main = OpFunction %void None %6
3465fd4e5da5Sopenharmony_ci%13 = OpLabel
3466fd4e5da5Sopenharmony_ciOpReturn
3467fd4e5da5Sopenharmony_ciOpFunctionEnd
3468fd4e5da5Sopenharmony_ci)";
3469fd4e5da5Sopenharmony_ci
3470fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3471fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(before, after, true, true);
3472fd4e5da5Sopenharmony_ci}
3473fd4e5da5Sopenharmony_ci
3474fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DeadNestedSwitch) {
3475fd4e5da5Sopenharmony_ci  const std::string text = R"(
3476fd4e5da5Sopenharmony_ci; CHECK: OpLabel
3477fd4e5da5Sopenharmony_ci; CHECK: OpBranch [[block:%\w+]]
3478fd4e5da5Sopenharmony_ci; CHECK-NOT: OpSwitch
3479fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[block]] = OpLabel
3480fd4e5da5Sopenharmony_ci; CHECK: OpBranch [[block:%\w+]]
3481fd4e5da5Sopenharmony_ci; CHECK-NOT: OpSwitch
3482fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[block]] = OpLabel
3483fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpStore
3484fd4e5da5Sopenharmony_ciOpCapability Shader
3485fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3486fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %func "func" %x
3487fd4e5da5Sopenharmony_ciOpExecutionMode %func OriginUpperLeft
3488fd4e5da5Sopenharmony_ciOpName %func "func"
3489fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3490fd4e5da5Sopenharmony_ci%1 = OpTypeFunction %void
3491fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3492fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
3493fd4e5da5Sopenharmony_ci%uint_ptr_Output = OpTypePointer Output %uint
3494fd4e5da5Sopenharmony_ci%uint_ptr_Input = OpTypePointer Input %uint
3495fd4e5da5Sopenharmony_ci%x = OpVariable %uint_ptr_Output Output
3496fd4e5da5Sopenharmony_ci%a = OpVariable %uint_ptr_Input Input
3497fd4e5da5Sopenharmony_ci%func = OpFunction %void None %1
3498fd4e5da5Sopenharmony_ci%entry = OpLabel
3499fd4e5da5Sopenharmony_ciOpBranch %header
3500fd4e5da5Sopenharmony_ci%header = OpLabel
3501fd4e5da5Sopenharmony_ci%ld = OpLoad %uint %a
3502fd4e5da5Sopenharmony_ciOpLoopMerge %merge %continue None
3503fd4e5da5Sopenharmony_ciOpBranch %postheader
3504fd4e5da5Sopenharmony_ci%postheader = OpLabel
3505fd4e5da5Sopenharmony_ci; This switch doesn't require an OpSelectionMerge and is nested in the dead loop.
3506fd4e5da5Sopenharmony_ciOpSwitch %ld %merge 0 %extra 1 %continue
3507fd4e5da5Sopenharmony_ci%extra = OpLabel
3508fd4e5da5Sopenharmony_ciOpBranch %continue
3509fd4e5da5Sopenharmony_ci%continue = OpLabel
3510fd4e5da5Sopenharmony_ciOpBranch %header
3511fd4e5da5Sopenharmony_ci%merge = OpLabel
3512fd4e5da5Sopenharmony_ciOpStore %x %uint_0
3513fd4e5da5Sopenharmony_ciOpReturn
3514fd4e5da5Sopenharmony_ciOpFunctionEnd
3515fd4e5da5Sopenharmony_ci)";
3516fd4e5da5Sopenharmony_ci
3517fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
3518fd4e5da5Sopenharmony_ci}
3519fd4e5da5Sopenharmony_ci
3520fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, LiveNestedSwitch) {
3521fd4e5da5Sopenharmony_ci  const std::string text = R"(OpCapability Shader
3522fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3523fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %func "func" %3 %10
3524fd4e5da5Sopenharmony_ciOpExecutionMode %func OriginUpperLeft
3525fd4e5da5Sopenharmony_ciOpName %func "func"
3526fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3527fd4e5da5Sopenharmony_ci%1 = OpTypeFunction %void
3528fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
3529fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
3530fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
3531fd4e5da5Sopenharmony_ci%_ptr_Output_uint = OpTypePointer Output %uint
3532fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
3533fd4e5da5Sopenharmony_ci%3 = OpVariable %_ptr_Output_uint Output
3534fd4e5da5Sopenharmony_ci%10 = OpVariable %_ptr_Input_uint Input
3535fd4e5da5Sopenharmony_ci%func = OpFunction %void None %1
3536fd4e5da5Sopenharmony_ci%11 = OpLabel
3537fd4e5da5Sopenharmony_ciOpBranch %12
3538fd4e5da5Sopenharmony_ci%12 = OpLabel
3539fd4e5da5Sopenharmony_ci%13 = OpLoad %uint %10
3540fd4e5da5Sopenharmony_ciOpLoopMerge %14 %15 None
3541fd4e5da5Sopenharmony_ciOpBranch %16
3542fd4e5da5Sopenharmony_ci%16 = OpLabel
3543fd4e5da5Sopenharmony_ciOpSelectionMerge %18 None
3544fd4e5da5Sopenharmony_ciOpSwitch %13 %18 0 %17 1 %19
3545fd4e5da5Sopenharmony_ci%17 = OpLabel
3546fd4e5da5Sopenharmony_ciOpStore %3 %uint_1
3547fd4e5da5Sopenharmony_ciOpBranch %19
3548fd4e5da5Sopenharmony_ci%19 = OpLabel
3549fd4e5da5Sopenharmony_ciOpBranch %15
3550fd4e5da5Sopenharmony_ci%15 = OpLabel
3551fd4e5da5Sopenharmony_ciOpBranch %12
3552fd4e5da5Sopenharmony_ci%18 = OpLabel
3553fd4e5da5Sopenharmony_ciOpBranch %14
3554fd4e5da5Sopenharmony_ci%14 = OpLabel
3555fd4e5da5Sopenharmony_ciOpStore %3 %uint_0
3556fd4e5da5Sopenharmony_ciOpReturn
3557fd4e5da5Sopenharmony_ciOpFunctionEnd
3558fd4e5da5Sopenharmony_ci)";
3559fd4e5da5Sopenharmony_ci
3560fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3561fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(text, text, false, true);
3562fd4e5da5Sopenharmony_ci}
3563fd4e5da5Sopenharmony_ci
3564fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, BasicDeleteDeadFunction) {
3565fd4e5da5Sopenharmony_ci  // The function Dead should be removed because it is never called.
3566fd4e5da5Sopenharmony_ci  const std::vector<const char*> common_code = {
3567fd4e5da5Sopenharmony_ci      // clang-format off
3568fd4e5da5Sopenharmony_ci               "OpCapability Shader",
3569fd4e5da5Sopenharmony_ci               "OpMemoryModel Logical GLSL450",
3570fd4e5da5Sopenharmony_ci               "OpEntryPoint Fragment %main \"main\"",
3571fd4e5da5Sopenharmony_ci               "OpName %main \"main\"",
3572fd4e5da5Sopenharmony_ci               "OpName %Live \"Live\"",
3573fd4e5da5Sopenharmony_ci       "%void = OpTypeVoid",
3574fd4e5da5Sopenharmony_ci          "%7 = OpTypeFunction %void",
3575fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %7",
3576fd4e5da5Sopenharmony_ci         "%15 = OpLabel",
3577fd4e5da5Sopenharmony_ci         "%16 = OpFunctionCall %void %Live",
3578fd4e5da5Sopenharmony_ci         "%17 = OpFunctionCall %void %Live",
3579fd4e5da5Sopenharmony_ci               "OpReturn",
3580fd4e5da5Sopenharmony_ci               "OpFunctionEnd",
3581fd4e5da5Sopenharmony_ci  "%Live = OpFunction %void None %7",
3582fd4e5da5Sopenharmony_ci         "%20 = OpLabel",
3583fd4e5da5Sopenharmony_ci               "OpReturn",
3584fd4e5da5Sopenharmony_ci               "OpFunctionEnd"
3585fd4e5da5Sopenharmony_ci      // clang-format on
3586fd4e5da5Sopenharmony_ci  };
3587fd4e5da5Sopenharmony_ci
3588fd4e5da5Sopenharmony_ci  const std::vector<const char*> dead_function = {
3589fd4e5da5Sopenharmony_ci      // clang-format off
3590fd4e5da5Sopenharmony_ci      "%Dead = OpFunction %void None %7",
3591fd4e5da5Sopenharmony_ci         "%19 = OpLabel",
3592fd4e5da5Sopenharmony_ci               "OpReturn",
3593fd4e5da5Sopenharmony_ci               "OpFunctionEnd",
3594fd4e5da5Sopenharmony_ci      // clang-format on
3595fd4e5da5Sopenharmony_ci  };
3596fd4e5da5Sopenharmony_ci
3597fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3598fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(
3599fd4e5da5Sopenharmony_ci      JoinAllInsts(Concat(common_code, dead_function)),
3600fd4e5da5Sopenharmony_ci      JoinAllInsts(common_code), /* skip_nop = */ true);
3601fd4e5da5Sopenharmony_ci}
3602fd4e5da5Sopenharmony_ci
3603fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, BasicKeepLiveFunction) {
3604fd4e5da5Sopenharmony_ci  // Everything is reachable from an entry point, so no functions should be
3605fd4e5da5Sopenharmony_ci  // deleted.
3606fd4e5da5Sopenharmony_ci  const std::vector<const char*> text = {
3607fd4e5da5Sopenharmony_ci      // clang-format off
3608fd4e5da5Sopenharmony_ci               "OpCapability Shader",
3609fd4e5da5Sopenharmony_ci               "OpMemoryModel Logical GLSL450",
3610fd4e5da5Sopenharmony_ci               "OpEntryPoint Fragment %main \"main\"",
3611fd4e5da5Sopenharmony_ci               "OpName %main \"main\"",
3612fd4e5da5Sopenharmony_ci               "OpName %Live1 \"Live1\"",
3613fd4e5da5Sopenharmony_ci               "OpName %Live2 \"Live2\"",
3614fd4e5da5Sopenharmony_ci       "%void = OpTypeVoid",
3615fd4e5da5Sopenharmony_ci          "%7 = OpTypeFunction %void",
3616fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %7",
3617fd4e5da5Sopenharmony_ci         "%15 = OpLabel",
3618fd4e5da5Sopenharmony_ci         "%16 = OpFunctionCall %void %Live2",
3619fd4e5da5Sopenharmony_ci         "%17 = OpFunctionCall %void %Live1",
3620fd4e5da5Sopenharmony_ci               "OpReturn",
3621fd4e5da5Sopenharmony_ci               "OpFunctionEnd",
3622fd4e5da5Sopenharmony_ci      "%Live1 = OpFunction %void None %7",
3623fd4e5da5Sopenharmony_ci         "%19 = OpLabel",
3624fd4e5da5Sopenharmony_ci               "OpReturn",
3625fd4e5da5Sopenharmony_ci               "OpFunctionEnd",
3626fd4e5da5Sopenharmony_ci      "%Live2 = OpFunction %void None %7",
3627fd4e5da5Sopenharmony_ci         "%20 = OpLabel",
3628fd4e5da5Sopenharmony_ci               "OpReturn",
3629fd4e5da5Sopenharmony_ci               "OpFunctionEnd"
3630fd4e5da5Sopenharmony_ci      // clang-format on
3631fd4e5da5Sopenharmony_ci  };
3632fd4e5da5Sopenharmony_ci
3633fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3634fd4e5da5Sopenharmony_ci  std::string assembly = JoinAllInsts(text);
3635fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<AggressiveDCEPass>(
3636fd4e5da5Sopenharmony_ci      assembly, /* skip_nop = */ true, /* do_validation = */ false);
3637fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
3638fd4e5da5Sopenharmony_ci  EXPECT_EQ(assembly, std::get<0>(result));
3639fd4e5da5Sopenharmony_ci}
3640fd4e5da5Sopenharmony_ci
3641fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, BasicRemoveDecorationsAndNames) {
3642fd4e5da5Sopenharmony_ci  // We want to remove the names and decorations associated with results that
3643fd4e5da5Sopenharmony_ci  // are removed.  This test will check for that.
3644fd4e5da5Sopenharmony_ci  const std::string text = R"(
3645fd4e5da5Sopenharmony_ci               OpCapability Shader
3646fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
3647fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main"
3648fd4e5da5Sopenharmony_ci               OpName %main "main"
3649fd4e5da5Sopenharmony_ci               OpName %Dead "Dead"
3650fd4e5da5Sopenharmony_ci               OpName %x "x"
3651fd4e5da5Sopenharmony_ci               OpName %y "y"
3652fd4e5da5Sopenharmony_ci               OpName %z "z"
3653fd4e5da5Sopenharmony_ci               OpDecorate %x RelaxedPrecision
3654fd4e5da5Sopenharmony_ci               OpDecorate %y RelaxedPrecision
3655fd4e5da5Sopenharmony_ci               OpDecorate %z RelaxedPrecision
3656fd4e5da5Sopenharmony_ci               OpDecorate %6 RelaxedPrecision
3657fd4e5da5Sopenharmony_ci               OpDecorate %7 RelaxedPrecision
3658fd4e5da5Sopenharmony_ci               OpDecorate %8 RelaxedPrecision
3659fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
3660fd4e5da5Sopenharmony_ci         %10 = OpTypeFunction %void
3661fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
3662fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
3663fd4e5da5Sopenharmony_ci    %float_1 = OpConstant %float 1
3664fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %10
3665fd4e5da5Sopenharmony_ci         %14 = OpLabel
3666fd4e5da5Sopenharmony_ci               OpReturn
3667fd4e5da5Sopenharmony_ci               OpFunctionEnd
3668fd4e5da5Sopenharmony_ci       %Dead = OpFunction %void None %10
3669fd4e5da5Sopenharmony_ci         %15 = OpLabel
3670fd4e5da5Sopenharmony_ci          %x = OpVariable %_ptr_Function_float Function
3671fd4e5da5Sopenharmony_ci          %y = OpVariable %_ptr_Function_float Function
3672fd4e5da5Sopenharmony_ci          %z = OpVariable %_ptr_Function_float Function
3673fd4e5da5Sopenharmony_ci               OpStore %x %float_1
3674fd4e5da5Sopenharmony_ci               OpStore %y %float_1
3675fd4e5da5Sopenharmony_ci          %6 = OpLoad %float %x
3676fd4e5da5Sopenharmony_ci          %7 = OpLoad %float %y
3677fd4e5da5Sopenharmony_ci          %8 = OpFAdd %float %6 %7
3678fd4e5da5Sopenharmony_ci               OpStore %z %8
3679fd4e5da5Sopenharmony_ci               OpReturn
3680fd4e5da5Sopenharmony_ci               OpFunctionEnd)";
3681fd4e5da5Sopenharmony_ci
3682fd4e5da5Sopenharmony_ci  const std::string expected_output = R"(OpCapability Shader
3683fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
3684fd4e5da5Sopenharmony_ciOpEntryPoint Vertex %main "main"
3685fd4e5da5Sopenharmony_ciOpName %main "main"
3686fd4e5da5Sopenharmony_ci%void = OpTypeVoid
3687fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
3688fd4e5da5Sopenharmony_ci%main = OpFunction %void None %10
3689fd4e5da5Sopenharmony_ci%14 = OpLabel
3690fd4e5da5Sopenharmony_ciOpReturn
3691fd4e5da5Sopenharmony_ciOpFunctionEnd
3692fd4e5da5Sopenharmony_ci)";
3693fd4e5da5Sopenharmony_ci
3694fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3695fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(text, expected_output,
3696fd4e5da5Sopenharmony_ci                                           /* skip_nop = */ true);
3697fd4e5da5Sopenharmony_ci}
3698fd4e5da5Sopenharmony_ci
3699fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, BasicAllDeadConstants) {
3700fd4e5da5Sopenharmony_ci  const std::string text = R"(
3701fd4e5da5Sopenharmony_ci  ; CHECK-NOT: OpConstant
3702fd4e5da5Sopenharmony_ci               OpCapability Shader
3703fd4e5da5Sopenharmony_ci               OpCapability Float64
3704fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
3705fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
3706fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main"
3707fd4e5da5Sopenharmony_ci               OpName %main "main"
3708fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
3709fd4e5da5Sopenharmony_ci          %4 = OpTypeFunction %void
3710fd4e5da5Sopenharmony_ci       %bool = OpTypeBool
3711fd4e5da5Sopenharmony_ci       %true = OpConstantTrue %bool
3712fd4e5da5Sopenharmony_ci      %false = OpConstantFalse %bool
3713fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
3714fd4e5da5Sopenharmony_ci          %9 = OpConstant %int 1
3715fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
3716fd4e5da5Sopenharmony_ci         %11 = OpConstant %uint 2
3717fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
3718fd4e5da5Sopenharmony_ci         %13 = OpConstant %float 3.1415
3719fd4e5da5Sopenharmony_ci     %double = OpTypeFloat 64
3720fd4e5da5Sopenharmony_ci         %15 = OpConstant %double 3.14159265358979
3721fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %4
3722fd4e5da5Sopenharmony_ci         %16 = OpLabel
3723fd4e5da5Sopenharmony_ci               OpReturn
3724fd4e5da5Sopenharmony_ci               OpFunctionEnd
3725fd4e5da5Sopenharmony_ci  )";
3726fd4e5da5Sopenharmony_ci
3727fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
3728fd4e5da5Sopenharmony_ci}
3729fd4e5da5Sopenharmony_ci
3730fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, BasicNoneDeadConstants) {
3731fd4e5da5Sopenharmony_ci  const std::vector<const char*> text = {
3732fd4e5da5Sopenharmony_ci      // clang-format off
3733fd4e5da5Sopenharmony_ci                "OpCapability Shader",
3734fd4e5da5Sopenharmony_ci                "OpCapability Float64",
3735fd4e5da5Sopenharmony_ci           "%1 = OpExtInstImport \"GLSL.std.450\"",
3736fd4e5da5Sopenharmony_ci                "OpMemoryModel Logical GLSL450",
3737fd4e5da5Sopenharmony_ci                "OpEntryPoint Vertex %main \"main\" %btv %bfv %iv %uv %fv %dv",
3738fd4e5da5Sopenharmony_ci                "OpName %main \"main\"",
3739fd4e5da5Sopenharmony_ci                "OpName %btv \"btv\"",
3740fd4e5da5Sopenharmony_ci                "OpName %bfv \"bfv\"",
3741fd4e5da5Sopenharmony_ci                "OpName %iv \"iv\"",
3742fd4e5da5Sopenharmony_ci                "OpName %uv \"uv\"",
3743fd4e5da5Sopenharmony_ci                "OpName %fv \"fv\"",
3744fd4e5da5Sopenharmony_ci                "OpName %dv \"dv\"",
3745fd4e5da5Sopenharmony_ci        "%void = OpTypeVoid",
3746fd4e5da5Sopenharmony_ci          "%10 = OpTypeFunction %void",
3747fd4e5da5Sopenharmony_ci        "%bool = OpTypeBool",
3748fd4e5da5Sopenharmony_ci "%_ptr_Output_bool = OpTypePointer Output %bool",
3749fd4e5da5Sopenharmony_ci        "%true = OpConstantTrue %bool",
3750fd4e5da5Sopenharmony_ci       "%false = OpConstantFalse %bool",
3751fd4e5da5Sopenharmony_ci         "%int = OpTypeInt 32 1",
3752fd4e5da5Sopenharmony_ci "%_ptr_Output_int = OpTypePointer Output %int",
3753fd4e5da5Sopenharmony_ci       "%int_1 = OpConstant %int 1",
3754fd4e5da5Sopenharmony_ci        "%uint = OpTypeInt 32 0",
3755fd4e5da5Sopenharmony_ci "%_ptr_Output_uint = OpTypePointer Output %uint",
3756fd4e5da5Sopenharmony_ci      "%uint_2 = OpConstant %uint 2",
3757fd4e5da5Sopenharmony_ci       "%float = OpTypeFloat 32",
3758fd4e5da5Sopenharmony_ci "%_ptr_Output_float = OpTypePointer Output %float",
3759fd4e5da5Sopenharmony_ci  "%float_3_1415 = OpConstant %float 3.1415",
3760fd4e5da5Sopenharmony_ci      "%double = OpTypeFloat 64",
3761fd4e5da5Sopenharmony_ci "%_ptr_Output_double = OpTypePointer Output %double",
3762fd4e5da5Sopenharmony_ci "%double_3_14159265358979 = OpConstant %double 3.14159265358979",
3763fd4e5da5Sopenharmony_ci         "%btv = OpVariable %_ptr_Output_bool Output",
3764fd4e5da5Sopenharmony_ci         "%bfv = OpVariable %_ptr_Output_bool Output",
3765fd4e5da5Sopenharmony_ci          "%iv = OpVariable %_ptr_Output_int Output",
3766fd4e5da5Sopenharmony_ci          "%uv = OpVariable %_ptr_Output_uint Output",
3767fd4e5da5Sopenharmony_ci          "%fv = OpVariable %_ptr_Output_float Output",
3768fd4e5da5Sopenharmony_ci          "%dv = OpVariable %_ptr_Output_double Output",
3769fd4e5da5Sopenharmony_ci        "%main = OpFunction %void None %10",
3770fd4e5da5Sopenharmony_ci          "%27 = OpLabel",
3771fd4e5da5Sopenharmony_ci                "OpStore %btv %true",
3772fd4e5da5Sopenharmony_ci                "OpStore %bfv %false",
3773fd4e5da5Sopenharmony_ci                "OpStore %iv %int_1",
3774fd4e5da5Sopenharmony_ci                "OpStore %uv %uint_2",
3775fd4e5da5Sopenharmony_ci                "OpStore %fv %float_3_1415",
3776fd4e5da5Sopenharmony_ci                "OpStore %dv %double_3_14159265358979",
3777fd4e5da5Sopenharmony_ci                "OpReturn",
3778fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
3779fd4e5da5Sopenharmony_ci      // clang-format on
3780fd4e5da5Sopenharmony_ci  };
3781fd4e5da5Sopenharmony_ci  // All constants are used, so none of them should be eliminated.
3782fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(
3783fd4e5da5Sopenharmony_ci      JoinAllInsts(text), JoinAllInsts(text), /* skip_nop = */ true);
3784fd4e5da5Sopenharmony_ci}
3785fd4e5da5Sopenharmony_ci
3786fd4e5da5Sopenharmony_cistruct AggressiveEliminateDeadConstantTestCase {
3787fd4e5da5Sopenharmony_ci  // Type declarations and constants that should be kept.
3788fd4e5da5Sopenharmony_ci  std::vector<std::string> used_consts;
3789fd4e5da5Sopenharmony_ci  // Instructions that refer to constants, this is added to create uses for
3790fd4e5da5Sopenharmony_ci  // some constants so they won't be treated as dead constants.
3791fd4e5da5Sopenharmony_ci  std::vector<std::string> main_insts;
3792fd4e5da5Sopenharmony_ci  // Dead constants that should be removed.
3793fd4e5da5Sopenharmony_ci  std::vector<std::string> dead_consts;
3794fd4e5da5Sopenharmony_ci  // Expectations
3795fd4e5da5Sopenharmony_ci  std::vector<std::string> checks;
3796fd4e5da5Sopenharmony_ci};
3797fd4e5da5Sopenharmony_ci
3798fd4e5da5Sopenharmony_ci// All types that are potentially required in
3799fd4e5da5Sopenharmony_ci// AggressiveEliminateDeadConstantTest.
3800fd4e5da5Sopenharmony_ciconst std::vector<std::string> CommonTypes = {
3801fd4e5da5Sopenharmony_ci    // clang-format off
3802fd4e5da5Sopenharmony_ci    // scalar types
3803fd4e5da5Sopenharmony_ci    "%bool = OpTypeBool",
3804fd4e5da5Sopenharmony_ci    "%uint = OpTypeInt 32 0",
3805fd4e5da5Sopenharmony_ci    "%int = OpTypeInt 32 1",
3806fd4e5da5Sopenharmony_ci    "%float = OpTypeFloat 32",
3807fd4e5da5Sopenharmony_ci    "%double = OpTypeFloat 64",
3808fd4e5da5Sopenharmony_ci    // vector types
3809fd4e5da5Sopenharmony_ci    "%v2bool = OpTypeVector %bool 2",
3810fd4e5da5Sopenharmony_ci    "%v2uint = OpTypeVector %uint 2",
3811fd4e5da5Sopenharmony_ci    "%v2int = OpTypeVector %int 2",
3812fd4e5da5Sopenharmony_ci    "%v3int = OpTypeVector %int 3",
3813fd4e5da5Sopenharmony_ci    "%v4int = OpTypeVector %int 4",
3814fd4e5da5Sopenharmony_ci    "%v2float = OpTypeVector %float 2",
3815fd4e5da5Sopenharmony_ci    "%v3float = OpTypeVector %float 3",
3816fd4e5da5Sopenharmony_ci    "%v2double = OpTypeVector %double 2",
3817fd4e5da5Sopenharmony_ci    // variable pointer types
3818fd4e5da5Sopenharmony_ci    "%_pf_bool = OpTypePointer Output %bool",
3819fd4e5da5Sopenharmony_ci    "%_pf_uint = OpTypePointer Output %uint",
3820fd4e5da5Sopenharmony_ci    "%_pf_int = OpTypePointer Output %int",
3821fd4e5da5Sopenharmony_ci    "%_pf_float = OpTypePointer Output %float",
3822fd4e5da5Sopenharmony_ci    "%_pf_double = OpTypePointer Output %double",
3823fd4e5da5Sopenharmony_ci    "%_pf_v2int = OpTypePointer Output %v2int",
3824fd4e5da5Sopenharmony_ci    "%_pf_v3int = OpTypePointer Output %v3int",
3825fd4e5da5Sopenharmony_ci    "%_pf_v2float = OpTypePointer Output %v2float",
3826fd4e5da5Sopenharmony_ci    "%_pf_v3float = OpTypePointer Output %v3float",
3827fd4e5da5Sopenharmony_ci    "%_pf_v2double = OpTypePointer Output %v2double",
3828fd4e5da5Sopenharmony_ci    // struct types
3829fd4e5da5Sopenharmony_ci    "%inner_struct = OpTypeStruct %bool %int %float %double",
3830fd4e5da5Sopenharmony_ci    "%outer_struct = OpTypeStruct %inner_struct %int %double",
3831fd4e5da5Sopenharmony_ci    "%flat_struct = OpTypeStruct %bool %int %float %double",
3832fd4e5da5Sopenharmony_ci    // clang-format on
3833fd4e5da5Sopenharmony_ci};
3834fd4e5da5Sopenharmony_ci
3835fd4e5da5Sopenharmony_ciusing AggressiveEliminateDeadConstantTest =
3836fd4e5da5Sopenharmony_ci    PassTest<::testing::TestWithParam<AggressiveEliminateDeadConstantTestCase>>;
3837fd4e5da5Sopenharmony_ci
3838fd4e5da5Sopenharmony_ciTEST_P(AggressiveEliminateDeadConstantTest, Custom) {
3839fd4e5da5Sopenharmony_ci  auto& tc = GetParam();
3840fd4e5da5Sopenharmony_ci  AssemblyBuilder builder;
3841fd4e5da5Sopenharmony_ci  builder.AppendTypesConstantsGlobals(CommonTypes)
3842fd4e5da5Sopenharmony_ci      .AppendTypesConstantsGlobals(tc.used_consts)
3843fd4e5da5Sopenharmony_ci      .AppendInMain(tc.main_insts);
3844fd4e5da5Sopenharmony_ci  const std::string expected = builder.GetCode();
3845fd4e5da5Sopenharmony_ci  builder.AppendTypesConstantsGlobals(tc.dead_consts);
3846fd4e5da5Sopenharmony_ci  builder.PrependPreamble(tc.checks);
3847fd4e5da5Sopenharmony_ci  const std::string assembly_with_dead_const = builder.GetCode();
3848fd4e5da5Sopenharmony_ci
3849fd4e5da5Sopenharmony_ci  // Do not enable validation. As the input code is invalid from the base
3850fd4e5da5Sopenharmony_ci  // tests (ported from other passes).
3851fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(assembly_with_dead_const, false);
3852fd4e5da5Sopenharmony_ci}
3853fd4e5da5Sopenharmony_ci
3854fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3855fd4e5da5Sopenharmony_ci    ScalarTypeConstants, AggressiveEliminateDeadConstantTest,
3856fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<AggressiveEliminateDeadConstantTestCase>({
3857fd4e5da5Sopenharmony_ci        // clang-format off
3858fd4e5da5Sopenharmony_ci        // Scalar type constants, one dead constant and one used constant.
3859fd4e5da5Sopenharmony_ci        {
3860fd4e5da5Sopenharmony_ci            /* .used_consts = */
3861fd4e5da5Sopenharmony_ci            {
3862fd4e5da5Sopenharmony_ci              "%used_const_int = OpConstant %int 1",
3863fd4e5da5Sopenharmony_ci            },
3864fd4e5da5Sopenharmony_ci            /* .main_insts = */
3865fd4e5da5Sopenharmony_ci            {
3866fd4e5da5Sopenharmony_ci              "%int_var = OpVariable %_pf_int Output",
3867fd4e5da5Sopenharmony_ci              "OpStore %int_var %used_const_int",
3868fd4e5da5Sopenharmony_ci            },
3869fd4e5da5Sopenharmony_ci            /* .dead_consts = */
3870fd4e5da5Sopenharmony_ci            {
3871fd4e5da5Sopenharmony_ci              "%dead_const_int = OpConstant %int 1",
3872fd4e5da5Sopenharmony_ci            },
3873fd4e5da5Sopenharmony_ci            /* .checks = */
3874fd4e5da5Sopenharmony_ci            {
3875fd4e5da5Sopenharmony_ci              "; CHECK: [[const:%\\w+]] = OpConstant %int 1",
3876fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
3877fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[const]]",
3878fd4e5da5Sopenharmony_ci            },
3879fd4e5da5Sopenharmony_ci        },
3880fd4e5da5Sopenharmony_ci        {
3881fd4e5da5Sopenharmony_ci            /* .used_consts = */
3882fd4e5da5Sopenharmony_ci            {
3883fd4e5da5Sopenharmony_ci              "%used_const_uint = OpConstant %uint 1",
3884fd4e5da5Sopenharmony_ci            },
3885fd4e5da5Sopenharmony_ci            /* .main_insts = */
3886fd4e5da5Sopenharmony_ci            {
3887fd4e5da5Sopenharmony_ci              "%uint_var = OpVariable %_pf_uint Output",
3888fd4e5da5Sopenharmony_ci              "OpStore %uint_var %used_const_uint",
3889fd4e5da5Sopenharmony_ci            },
3890fd4e5da5Sopenharmony_ci            /* .dead_consts = */
3891fd4e5da5Sopenharmony_ci            {
3892fd4e5da5Sopenharmony_ci              "%dead_const_uint = OpConstant %uint 1",
3893fd4e5da5Sopenharmony_ci            },
3894fd4e5da5Sopenharmony_ci            /* .checks = */
3895fd4e5da5Sopenharmony_ci            {
3896fd4e5da5Sopenharmony_ci              "; CHECK: [[const:%\\w+]] = OpConstant %uint 1",
3897fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
3898fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[const]]",
3899fd4e5da5Sopenharmony_ci            },
3900fd4e5da5Sopenharmony_ci        },
3901fd4e5da5Sopenharmony_ci        {
3902fd4e5da5Sopenharmony_ci            /* .used_consts = */
3903fd4e5da5Sopenharmony_ci            {
3904fd4e5da5Sopenharmony_ci              "%used_const_float = OpConstant %float 3.1415",
3905fd4e5da5Sopenharmony_ci            },
3906fd4e5da5Sopenharmony_ci            /* .main_insts = */
3907fd4e5da5Sopenharmony_ci            {
3908fd4e5da5Sopenharmony_ci              "%float_var = OpVariable %_pf_float Output",
3909fd4e5da5Sopenharmony_ci              "OpStore %float_var %used_const_float",
3910fd4e5da5Sopenharmony_ci            },
3911fd4e5da5Sopenharmony_ci            /* .dead_consts = */
3912fd4e5da5Sopenharmony_ci            {
3913fd4e5da5Sopenharmony_ci              "%dead_const_float = OpConstant %float 3.1415",
3914fd4e5da5Sopenharmony_ci            },
3915fd4e5da5Sopenharmony_ci            /* .checks = */
3916fd4e5da5Sopenharmony_ci            {
3917fd4e5da5Sopenharmony_ci              "; CHECK: [[const:%\\w+]] = OpConstant %float 3.1415",
3918fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
3919fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[const]]",
3920fd4e5da5Sopenharmony_ci            },
3921fd4e5da5Sopenharmony_ci        },
3922fd4e5da5Sopenharmony_ci        {
3923fd4e5da5Sopenharmony_ci            /* .used_consts = */
3924fd4e5da5Sopenharmony_ci            {
3925fd4e5da5Sopenharmony_ci              "%used_const_double = OpConstant %double 3.14",
3926fd4e5da5Sopenharmony_ci            },
3927fd4e5da5Sopenharmony_ci            /* .main_insts = */
3928fd4e5da5Sopenharmony_ci            {
3929fd4e5da5Sopenharmony_ci              "%double_var = OpVariable %_pf_double Output",
3930fd4e5da5Sopenharmony_ci              "OpStore %double_var %used_const_double",
3931fd4e5da5Sopenharmony_ci            },
3932fd4e5da5Sopenharmony_ci            /* .dead_consts = */
3933fd4e5da5Sopenharmony_ci            {
3934fd4e5da5Sopenharmony_ci              "%dead_const_double = OpConstant %double 3.14",
3935fd4e5da5Sopenharmony_ci            },
3936fd4e5da5Sopenharmony_ci            /* .checks = */
3937fd4e5da5Sopenharmony_ci            {
3938fd4e5da5Sopenharmony_ci              "; CHECK: [[const:%\\w+]] = OpConstant %double 3.14",
3939fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
3940fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[const]]",
3941fd4e5da5Sopenharmony_ci            },
3942fd4e5da5Sopenharmony_ci        },
3943fd4e5da5Sopenharmony_ci        // clang-format on
3944fd4e5da5Sopenharmony_ci    })));
3945fd4e5da5Sopenharmony_ci
3946fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
3947fd4e5da5Sopenharmony_ci    VectorTypeConstants, AggressiveEliminateDeadConstantTest,
3948fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<AggressiveEliminateDeadConstantTestCase>({
3949fd4e5da5Sopenharmony_ci        // clang-format off
3950fd4e5da5Sopenharmony_ci        // Tests eliminating dead constant type ivec2. One dead constant vector
3951fd4e5da5Sopenharmony_ci        // and one used constant vector, each built from its own group of
3952fd4e5da5Sopenharmony_ci        // scalar constants.
3953fd4e5da5Sopenharmony_ci        {
3954fd4e5da5Sopenharmony_ci            /* .used_consts = */
3955fd4e5da5Sopenharmony_ci            {
3956fd4e5da5Sopenharmony_ci              "%used_int_x = OpConstant %int 1",
3957fd4e5da5Sopenharmony_ci              "%used_int_y = OpConstant %int 2",
3958fd4e5da5Sopenharmony_ci              "%used_v2int = OpConstantComposite %v2int %used_int_x %used_int_y",
3959fd4e5da5Sopenharmony_ci            },
3960fd4e5da5Sopenharmony_ci            /* .main_insts = */
3961fd4e5da5Sopenharmony_ci            {
3962fd4e5da5Sopenharmony_ci              "%v2int_var = OpVariable %_pf_v2int Output",
3963fd4e5da5Sopenharmony_ci              "OpStore %v2int_var %used_v2int",
3964fd4e5da5Sopenharmony_ci            },
3965fd4e5da5Sopenharmony_ci            /* .dead_consts = */
3966fd4e5da5Sopenharmony_ci            {
3967fd4e5da5Sopenharmony_ci              "%dead_int_x = OpConstant %int 1",
3968fd4e5da5Sopenharmony_ci              "%dead_int_y = OpConstant %int 2",
3969fd4e5da5Sopenharmony_ci              "%dead_v2int = OpConstantComposite %v2int %dead_int_x %dead_int_y",
3970fd4e5da5Sopenharmony_ci            },
3971fd4e5da5Sopenharmony_ci            /* .checks = */
3972fd4e5da5Sopenharmony_ci            {
3973fd4e5da5Sopenharmony_ci              "; CHECK: [[constx:%\\w+]] = OpConstant %int 1",
3974fd4e5da5Sopenharmony_ci              "; CHECK: [[consty:%\\w+]] = OpConstant %int 2",
3975fd4e5da5Sopenharmony_ci              "; CHECK: [[const:%\\w+]] = OpConstantComposite %v2int [[constx]] [[consty]]",
3976fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
3977fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[const]]",
3978fd4e5da5Sopenharmony_ci            },
3979fd4e5da5Sopenharmony_ci        },
3980fd4e5da5Sopenharmony_ci        // Tests eliminating dead constant ivec3. One dead constant vector and
3981fd4e5da5Sopenharmony_ci        // one used constant vector. But both built from a same group of
3982fd4e5da5Sopenharmony_ci        // scalar constants.
3983fd4e5da5Sopenharmony_ci        {
3984fd4e5da5Sopenharmony_ci            /* .used_consts = */
3985fd4e5da5Sopenharmony_ci            {
3986fd4e5da5Sopenharmony_ci              "%used_int_x = OpConstant %int 1",
3987fd4e5da5Sopenharmony_ci              "%used_int_y = OpConstant %int 2",
3988fd4e5da5Sopenharmony_ci              "%used_int_z = OpConstant %int 3",
3989fd4e5da5Sopenharmony_ci              "%used_v3int = OpConstantComposite %v3int %used_int_x %used_int_y %used_int_z",
3990fd4e5da5Sopenharmony_ci            },
3991fd4e5da5Sopenharmony_ci            /* .main_insts = */
3992fd4e5da5Sopenharmony_ci            {
3993fd4e5da5Sopenharmony_ci              "%v3int_var = OpVariable %_pf_v3int Output",
3994fd4e5da5Sopenharmony_ci              "OpStore %v3int_var %used_v3int",
3995fd4e5da5Sopenharmony_ci            },
3996fd4e5da5Sopenharmony_ci            /* .dead_consts = */
3997fd4e5da5Sopenharmony_ci            {
3998fd4e5da5Sopenharmony_ci              "%dead_v3int = OpConstantComposite %v3int %used_int_x %used_int_y %used_int_z",
3999fd4e5da5Sopenharmony_ci            },
4000fd4e5da5Sopenharmony_ci            /* .checks = */
4001fd4e5da5Sopenharmony_ci            {
4002fd4e5da5Sopenharmony_ci              "; CHECK: [[constx:%\\w+]] = OpConstant %int 1",
4003fd4e5da5Sopenharmony_ci              "; CHECK: [[consty:%\\w+]] = OpConstant %int 2",
4004fd4e5da5Sopenharmony_ci              "; CHECK: [[constz:%\\w+]] = OpConstant %int 3",
4005fd4e5da5Sopenharmony_ci              "; CHECK: [[const:%\\w+]] = OpConstantComposite %v3int [[constx]] [[consty]] [[constz]]",
4006fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4007fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[const]]",
4008fd4e5da5Sopenharmony_ci            },
4009fd4e5da5Sopenharmony_ci        },
4010fd4e5da5Sopenharmony_ci        // Tests eliminating dead constant vec2. One dead constant vector and
4011fd4e5da5Sopenharmony_ci        // one used constant vector. Each built from its own group of scalar
4012fd4e5da5Sopenharmony_ci        // constants.
4013fd4e5da5Sopenharmony_ci        {
4014fd4e5da5Sopenharmony_ci            /* .used_consts = */
4015fd4e5da5Sopenharmony_ci            {
4016fd4e5da5Sopenharmony_ci              "%used_float_x = OpConstant %float 3.1415",
4017fd4e5da5Sopenharmony_ci              "%used_float_y = OpConstant %float 4.13",
4018fd4e5da5Sopenharmony_ci              "%used_v2float = OpConstantComposite %v2float %used_float_x %used_float_y",
4019fd4e5da5Sopenharmony_ci            },
4020fd4e5da5Sopenharmony_ci            /* .main_insts = */
4021fd4e5da5Sopenharmony_ci            {
4022fd4e5da5Sopenharmony_ci              "%v2float_var = OpVariable %_pf_v2float Output",
4023fd4e5da5Sopenharmony_ci              "OpStore %v2float_var %used_v2float",
4024fd4e5da5Sopenharmony_ci            },
4025fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4026fd4e5da5Sopenharmony_ci            {
4027fd4e5da5Sopenharmony_ci              "%dead_float_x = OpConstant %float 3.1415",
4028fd4e5da5Sopenharmony_ci              "%dead_float_y = OpConstant %float 4.13",
4029fd4e5da5Sopenharmony_ci              "%dead_v2float = OpConstantComposite %v2float %dead_float_x %dead_float_y",
4030fd4e5da5Sopenharmony_ci            },
4031fd4e5da5Sopenharmony_ci            /* .checks = */
4032fd4e5da5Sopenharmony_ci            {
4033fd4e5da5Sopenharmony_ci              "; CHECK: [[constx:%\\w+]] = OpConstant %float 3.1415",
4034fd4e5da5Sopenharmony_ci              "; CHECK: [[consty:%\\w+]] = OpConstant %float 4.13",
4035fd4e5da5Sopenharmony_ci              "; CHECK: [[const:%\\w+]] = OpConstantComposite %v2float [[constx]] [[consty]]",
4036fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4037fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[const]]",
4038fd4e5da5Sopenharmony_ci            },
4039fd4e5da5Sopenharmony_ci        },
4040fd4e5da5Sopenharmony_ci        // Tests eliminating dead constant vec3. One dead constant vector and
4041fd4e5da5Sopenharmony_ci        // one used constant vector. Both built from a same group of scalar
4042fd4e5da5Sopenharmony_ci        // constants.
4043fd4e5da5Sopenharmony_ci        {
4044fd4e5da5Sopenharmony_ci            /* .used_consts = */
4045fd4e5da5Sopenharmony_ci            {
4046fd4e5da5Sopenharmony_ci              "%used_float_x = OpConstant %float 3.1415",
4047fd4e5da5Sopenharmony_ci              "%used_float_y = OpConstant %float 4.25",
4048fd4e5da5Sopenharmony_ci              "%used_float_z = OpConstant %float 4.75",
4049fd4e5da5Sopenharmony_ci              "%used_v3float = OpConstantComposite %v3float %used_float_x %used_float_y %used_float_z",
4050fd4e5da5Sopenharmony_ci            },
4051fd4e5da5Sopenharmony_ci            /* .main_insts = */
4052fd4e5da5Sopenharmony_ci            {
4053fd4e5da5Sopenharmony_ci              "%v3float_var = OpVariable %_pf_v3float Output",
4054fd4e5da5Sopenharmony_ci              "OpStore %v3float_var %used_v3float",
4055fd4e5da5Sopenharmony_ci            },
4056fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4057fd4e5da5Sopenharmony_ci            {
4058fd4e5da5Sopenharmony_ci              "%dead_v3float = OpConstantComposite %v3float %used_float_x %used_float_y %used_float_z",
4059fd4e5da5Sopenharmony_ci            },
4060fd4e5da5Sopenharmony_ci            /* .checks = */
4061fd4e5da5Sopenharmony_ci            {
4062fd4e5da5Sopenharmony_ci              "; CHECK: [[constx:%\\w+]] = OpConstant %float 3.1415",
4063fd4e5da5Sopenharmony_ci              "; CHECK: [[consty:%\\w+]] = OpConstant %float 4.25",
4064fd4e5da5Sopenharmony_ci              "; CHECK: [[constz:%\\w+]] = OpConstant %float 4.75",
4065fd4e5da5Sopenharmony_ci              "; CHECK: [[const:%\\w+]] = OpConstantComposite %v3float [[constx]] [[consty]]",
4066fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4067fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[const]]",
4068fd4e5da5Sopenharmony_ci            },
4069fd4e5da5Sopenharmony_ci        },
4070fd4e5da5Sopenharmony_ci        // clang-format on
4071fd4e5da5Sopenharmony_ci    })));
4072fd4e5da5Sopenharmony_ci
4073fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
4074fd4e5da5Sopenharmony_ci    StructTypeConstants, AggressiveEliminateDeadConstantTest,
4075fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<AggressiveEliminateDeadConstantTestCase>({
4076fd4e5da5Sopenharmony_ci        // clang-format off
4077fd4e5da5Sopenharmony_ci        // A plain struct type dead constants. All of its components are dead
4078fd4e5da5Sopenharmony_ci        // constants too.
4079fd4e5da5Sopenharmony_ci        {
4080fd4e5da5Sopenharmony_ci            /* .used_consts = */ {},
4081fd4e5da5Sopenharmony_ci            /* .main_insts = */ {},
4082fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4083fd4e5da5Sopenharmony_ci            {
4084fd4e5da5Sopenharmony_ci              "%dead_bool = OpConstantTrue %bool",
4085fd4e5da5Sopenharmony_ci              "%dead_int = OpConstant %int 1",
4086fd4e5da5Sopenharmony_ci              "%dead_float = OpConstant %float 2.5",
4087fd4e5da5Sopenharmony_ci              "%dead_double = OpConstant %double 3.14159265358979",
4088fd4e5da5Sopenharmony_ci              "%dead_struct = OpConstantComposite %flat_struct %dead_bool %dead_int %dead_float %dead_double",
4089fd4e5da5Sopenharmony_ci            },
4090fd4e5da5Sopenharmony_ci            /* .checks = */
4091fd4e5da5Sopenharmony_ci            {
4092fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4093fd4e5da5Sopenharmony_ci            },
4094fd4e5da5Sopenharmony_ci        },
4095fd4e5da5Sopenharmony_ci        // A plain struct type dead constants. Some of its components are dead
4096fd4e5da5Sopenharmony_ci        // constants while others are not.
4097fd4e5da5Sopenharmony_ci        {
4098fd4e5da5Sopenharmony_ci            /* .used_consts = */
4099fd4e5da5Sopenharmony_ci            {
4100fd4e5da5Sopenharmony_ci                "%used_int = OpConstant %int 1",
4101fd4e5da5Sopenharmony_ci                "%used_double = OpConstant %double 3.14159265358979",
4102fd4e5da5Sopenharmony_ci            },
4103fd4e5da5Sopenharmony_ci            /* .main_insts = */
4104fd4e5da5Sopenharmony_ci            {
4105fd4e5da5Sopenharmony_ci                "%int_var = OpVariable %_pf_int Output",
4106fd4e5da5Sopenharmony_ci                "OpStore %int_var %used_int",
4107fd4e5da5Sopenharmony_ci                "%double_var = OpVariable %_pf_double Output",
4108fd4e5da5Sopenharmony_ci                "OpStore %double_var %used_double",
4109fd4e5da5Sopenharmony_ci            },
4110fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4111fd4e5da5Sopenharmony_ci            {
4112fd4e5da5Sopenharmony_ci                "%dead_bool = OpConstantTrue %bool",
4113fd4e5da5Sopenharmony_ci                "%dead_float = OpConstant %float 2.5",
4114fd4e5da5Sopenharmony_ci                "%dead_struct = OpConstantComposite %flat_struct %dead_bool %used_int %dead_float %used_double",
4115fd4e5da5Sopenharmony_ci            },
4116fd4e5da5Sopenharmony_ci            /* .checks = */
4117fd4e5da5Sopenharmony_ci            {
4118fd4e5da5Sopenharmony_ci              "; CHECK: [[int:%\\w+]] = OpConstant %int 1",
4119fd4e5da5Sopenharmony_ci              "; CHECK: [[double:%\\w+]] = OpConstant %double 3.14159265358979",
4120fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4121fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[int]]",
4122fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[double]]",
4123fd4e5da5Sopenharmony_ci            },
4124fd4e5da5Sopenharmony_ci        },
4125fd4e5da5Sopenharmony_ci        // A nesting struct type dead constants. All components of both outer
4126fd4e5da5Sopenharmony_ci        // and inner structs are dead and should be removed after dead constant
4127fd4e5da5Sopenharmony_ci        // elimination.
4128fd4e5da5Sopenharmony_ci        {
4129fd4e5da5Sopenharmony_ci            /* .used_consts = */ {},
4130fd4e5da5Sopenharmony_ci            /* .main_insts = */ {},
4131fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4132fd4e5da5Sopenharmony_ci            {
4133fd4e5da5Sopenharmony_ci              "%dead_bool = OpConstantTrue %bool",
4134fd4e5da5Sopenharmony_ci              "%dead_int = OpConstant %int 1",
4135fd4e5da5Sopenharmony_ci              "%dead_float = OpConstant %float 2.5",
4136fd4e5da5Sopenharmony_ci              "%dead_double = OpConstant %double 3.1415926535",
4137fd4e5da5Sopenharmony_ci              "%dead_inner_struct = OpConstantComposite %inner_struct %dead_bool %dead_int %dead_float %dead_double",
4138fd4e5da5Sopenharmony_ci              "%dead_int2 = OpConstant %int 2",
4139fd4e5da5Sopenharmony_ci              "%dead_double2 = OpConstant %double 1.428571428514",
4140fd4e5da5Sopenharmony_ci              "%dead_outer_struct = OpConstantComposite %outer_struct %dead_inner_struct %dead_int2 %dead_double2",
4141fd4e5da5Sopenharmony_ci            },
4142fd4e5da5Sopenharmony_ci            /* .checks = */
4143fd4e5da5Sopenharmony_ci            {
4144fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4145fd4e5da5Sopenharmony_ci            },
4146fd4e5da5Sopenharmony_ci        },
4147fd4e5da5Sopenharmony_ci        // A nesting struct type dead constants. Some of its components are
4148fd4e5da5Sopenharmony_ci        // dead constants while others are not.
4149fd4e5da5Sopenharmony_ci        {
4150fd4e5da5Sopenharmony_ci            /* .used_consts = */
4151fd4e5da5Sopenharmony_ci            {
4152fd4e5da5Sopenharmony_ci              "%used_int = OpConstant %int 1",
4153fd4e5da5Sopenharmony_ci              "%used_double = OpConstant %double 3.14159265358979",
4154fd4e5da5Sopenharmony_ci            },
4155fd4e5da5Sopenharmony_ci            /* .main_insts = */
4156fd4e5da5Sopenharmony_ci            {
4157fd4e5da5Sopenharmony_ci              "%int_var = OpVariable %_pf_int Output",
4158fd4e5da5Sopenharmony_ci              "OpStore %int_var %used_int",
4159fd4e5da5Sopenharmony_ci              "%double_var = OpVariable %_pf_double Output",
4160fd4e5da5Sopenharmony_ci              "OpStore %double_var %used_double",
4161fd4e5da5Sopenharmony_ci            },
4162fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4163fd4e5da5Sopenharmony_ci            {
4164fd4e5da5Sopenharmony_ci              "%dead_bool = OpConstantTrue %bool",
4165fd4e5da5Sopenharmony_ci              "%dead_float = OpConstant %float 2.5",
4166fd4e5da5Sopenharmony_ci              "%dead_inner_struct = OpConstantComposite %inner_struct %dead_bool %used_int %dead_float %used_double",
4167fd4e5da5Sopenharmony_ci              "%dead_int = OpConstant %int 2",
4168fd4e5da5Sopenharmony_ci              "%dead_outer_struct = OpConstantComposite %outer_struct %dead_inner_struct %dead_int %used_double",
4169fd4e5da5Sopenharmony_ci            },
4170fd4e5da5Sopenharmony_ci            /* .checks = */
4171fd4e5da5Sopenharmony_ci            {
4172fd4e5da5Sopenharmony_ci              "; CHECK: [[int:%\\w+]] = OpConstant %int 1",
4173fd4e5da5Sopenharmony_ci              "; CHECK: [[double:%\\w+]] = OpConstant %double 3.14159265358979",
4174fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4175fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[int]]",
4176fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[double]]",
4177fd4e5da5Sopenharmony_ci            },
4178fd4e5da5Sopenharmony_ci        },
4179fd4e5da5Sopenharmony_ci        // A nesting struct case. The inner struct is used while the outer struct is not
4180fd4e5da5Sopenharmony_ci        {
4181fd4e5da5Sopenharmony_ci          /* .used_const = */
4182fd4e5da5Sopenharmony_ci          {
4183fd4e5da5Sopenharmony_ci            "%used_bool = OpConstantTrue %bool",
4184fd4e5da5Sopenharmony_ci            "%used_int = OpConstant %int 1",
4185fd4e5da5Sopenharmony_ci            "%used_float = OpConstant %float 1.23",
4186fd4e5da5Sopenharmony_ci            "%used_double = OpConstant %double 1.2345678901234",
4187fd4e5da5Sopenharmony_ci            "%used_inner_struct = OpConstantComposite %inner_struct %used_bool %used_int %used_float %used_double",
4188fd4e5da5Sopenharmony_ci          },
4189fd4e5da5Sopenharmony_ci          /* .main_insts = */
4190fd4e5da5Sopenharmony_ci          {
4191fd4e5da5Sopenharmony_ci            "%bool_var = OpVariable %_pf_bool Output",
4192fd4e5da5Sopenharmony_ci            "%bool_from_inner_struct = OpCompositeExtract %bool %used_inner_struct 0",
4193fd4e5da5Sopenharmony_ci            "OpStore %bool_var %bool_from_inner_struct",
4194fd4e5da5Sopenharmony_ci          },
4195fd4e5da5Sopenharmony_ci          /* .dead_consts = */
4196fd4e5da5Sopenharmony_ci          {
4197fd4e5da5Sopenharmony_ci            "%dead_int = OpConstant %int 2",
4198fd4e5da5Sopenharmony_ci            "%dead_outer_struct = OpConstantComposite %outer_struct %used_inner_struct %dead_int %used_double"
4199fd4e5da5Sopenharmony_ci          },
4200fd4e5da5Sopenharmony_ci          /* .checks = */
4201fd4e5da5Sopenharmony_ci          {
4202fd4e5da5Sopenharmony_ci            "; CHECK: [[bool:%\\w+]] = OpConstantTrue",
4203fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpConstant %int 1",
4204fd4e5da5Sopenharmony_ci            "; CHECK: [[float:%\\w+]] = OpConstant %float 1.23",
4205fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpConstant %double 1.2345678901234",
4206fd4e5da5Sopenharmony_ci            "; CHECK: [[struct:%\\w+]] = OpConstantComposite %inner_struct [[bool]] [[int]] [[float]] [[double]]",
4207fd4e5da5Sopenharmony_ci            "; CHECK-NOT: OpConstant",
4208fd4e5da5Sopenharmony_ci            "; CHECK: OpCompositeExtract %bool [[struct]]",
4209fd4e5da5Sopenharmony_ci          }
4210fd4e5da5Sopenharmony_ci        },
4211fd4e5da5Sopenharmony_ci        // A nesting struct case. The outer struct is used, so the inner struct should not
4212fd4e5da5Sopenharmony_ci        // be removed even though it is not used anywhere.
4213fd4e5da5Sopenharmony_ci        {
4214fd4e5da5Sopenharmony_ci          /* .used_const = */
4215fd4e5da5Sopenharmony_ci          {
4216fd4e5da5Sopenharmony_ci            "%used_bool = OpConstantTrue %bool",
4217fd4e5da5Sopenharmony_ci            "%used_int = OpConstant %int 1",
4218fd4e5da5Sopenharmony_ci            "%used_float = OpConstant %float 1.23",
4219fd4e5da5Sopenharmony_ci            "%used_double = OpConstant %double 1.2345678901234",
4220fd4e5da5Sopenharmony_ci            "%used_inner_struct = OpConstantComposite %inner_struct %used_bool %used_int %used_float %used_double",
4221fd4e5da5Sopenharmony_ci            "%used_outer_struct = OpConstantComposite %outer_struct %used_inner_struct %used_int %used_double"
4222fd4e5da5Sopenharmony_ci          },
4223fd4e5da5Sopenharmony_ci          /* .main_insts = */
4224fd4e5da5Sopenharmony_ci          {
4225fd4e5da5Sopenharmony_ci            "%int_var = OpVariable %_pf_int Output",
4226fd4e5da5Sopenharmony_ci            "%int_from_outer_struct = OpCompositeExtract %int %used_outer_struct 1",
4227fd4e5da5Sopenharmony_ci            "OpStore %int_var %int_from_outer_struct",
4228fd4e5da5Sopenharmony_ci          },
4229fd4e5da5Sopenharmony_ci          /* .dead_consts = */ {},
4230fd4e5da5Sopenharmony_ci          /* .checks = */
4231fd4e5da5Sopenharmony_ci          {
4232fd4e5da5Sopenharmony_ci            "; CHECK: [[bool:%\\w+]] = OpConstantTrue %bool",
4233fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpConstant %int 1",
4234fd4e5da5Sopenharmony_ci            "; CHECK: [[float:%\\w+]] = OpConstant %float 1.23",
4235fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpConstant %double 1.2345678901234",
4236fd4e5da5Sopenharmony_ci            "; CHECK: [[inner_struct:%\\w+]] = OpConstantComposite %inner_struct %used_bool %used_int %used_float %used_double",
4237fd4e5da5Sopenharmony_ci            "; CHECK: [[outer_struct:%\\w+]] = OpConstantComposite %outer_struct %used_inner_struct %used_int %used_double",
4238fd4e5da5Sopenharmony_ci            "; CHECK: OpCompositeExtract %int [[outer_struct]]",
4239fd4e5da5Sopenharmony_ci          },
4240fd4e5da5Sopenharmony_ci        },
4241fd4e5da5Sopenharmony_ci        // clang-format on
4242fd4e5da5Sopenharmony_ci    })));
4243fd4e5da5Sopenharmony_ci
4244fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
4245fd4e5da5Sopenharmony_ci    ScalarTypeSpecConstants, AggressiveEliminateDeadConstantTest,
4246fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<AggressiveEliminateDeadConstantTestCase>({
4247fd4e5da5Sopenharmony_ci        // clang-format off
4248fd4e5da5Sopenharmony_ci        // All scalar type spec constants.
4249fd4e5da5Sopenharmony_ci        {
4250fd4e5da5Sopenharmony_ci            /* .used_consts = */
4251fd4e5da5Sopenharmony_ci            {
4252fd4e5da5Sopenharmony_ci              "%used_bool = OpSpecConstantTrue %bool",
4253fd4e5da5Sopenharmony_ci              "%used_uint = OpSpecConstant %uint 2",
4254fd4e5da5Sopenharmony_ci              "%used_int = OpSpecConstant %int 2",
4255fd4e5da5Sopenharmony_ci              "%used_float = OpSpecConstant %float 2.5",
4256fd4e5da5Sopenharmony_ci              "%used_double = OpSpecConstant %double 1.428571428514",
4257fd4e5da5Sopenharmony_ci            },
4258fd4e5da5Sopenharmony_ci            /* .main_insts = */
4259fd4e5da5Sopenharmony_ci            {
4260fd4e5da5Sopenharmony_ci              "%bool_var = OpVariable %_pf_bool Output",
4261fd4e5da5Sopenharmony_ci              "%uint_var = OpVariable %_pf_uint Output",
4262fd4e5da5Sopenharmony_ci              "%int_var = OpVariable %_pf_int Output",
4263fd4e5da5Sopenharmony_ci              "%float_var = OpVariable %_pf_float Output",
4264fd4e5da5Sopenharmony_ci              "%double_var = OpVariable %_pf_double Output",
4265fd4e5da5Sopenharmony_ci              "OpStore %bool_var %used_bool",
4266fd4e5da5Sopenharmony_ci              "OpStore %uint_var %used_uint",
4267fd4e5da5Sopenharmony_ci              "OpStore %int_var %used_int",
4268fd4e5da5Sopenharmony_ci              "OpStore %float_var %used_float",
4269fd4e5da5Sopenharmony_ci              "OpStore %double_var %used_double",
4270fd4e5da5Sopenharmony_ci            },
4271fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4272fd4e5da5Sopenharmony_ci            {
4273fd4e5da5Sopenharmony_ci              "%dead_bool = OpSpecConstantTrue %bool",
4274fd4e5da5Sopenharmony_ci              "%dead_uint = OpSpecConstant %uint 2",
4275fd4e5da5Sopenharmony_ci              "%dead_int = OpSpecConstant %int 2",
4276fd4e5da5Sopenharmony_ci              "%dead_float = OpSpecConstant %float 2.5",
4277fd4e5da5Sopenharmony_ci              "%dead_double = OpSpecConstant %double 1.428571428514",
4278fd4e5da5Sopenharmony_ci            },
4279fd4e5da5Sopenharmony_ci            /* .checks = */
4280fd4e5da5Sopenharmony_ci            {
4281fd4e5da5Sopenharmony_ci              "; CHECK: [[bool:%\\w+]] = OpSpecConstantTrue %bool",
4282fd4e5da5Sopenharmony_ci              "; CHECK: [[uint:%\\w+]] = OpSpecConstant %uint 2",
4283fd4e5da5Sopenharmony_ci              "; CHECK: [[int:%\\w+]] = OpSpecConstant %int 2",
4284fd4e5da5Sopenharmony_ci              "; CHECK: [[float:%\\w+]] = OpSpecConstant %float 2.5",
4285fd4e5da5Sopenharmony_ci              "; CHECK: [[double:%\\w+]] = OpSpecConstant %double 1.428571428514",
4286fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpSpecConstant",
4287fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[bool]]",
4288fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[uint]]",
4289fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[int]]",
4290fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[float]]",
4291fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[double]]",
4292fd4e5da5Sopenharmony_ci            },
4293fd4e5da5Sopenharmony_ci        },
4294fd4e5da5Sopenharmony_ci        // clang-format on
4295fd4e5da5Sopenharmony_ci    })));
4296fd4e5da5Sopenharmony_ci
4297fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
4298fd4e5da5Sopenharmony_ci    VectorTypeSpecConstants, AggressiveEliminateDeadConstantTest,
4299fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<AggressiveEliminateDeadConstantTestCase>({
4300fd4e5da5Sopenharmony_ci        // clang-format off
4301fd4e5da5Sopenharmony_ci        // Bool vector type spec constants. One vector has all component dead,
4302fd4e5da5Sopenharmony_ci        // another vector has one dead boolean and one used boolean.
4303fd4e5da5Sopenharmony_ci        {
4304fd4e5da5Sopenharmony_ci            /* .used_consts = */
4305fd4e5da5Sopenharmony_ci            {
4306fd4e5da5Sopenharmony_ci              "%used_bool = OpSpecConstantTrue %bool",
4307fd4e5da5Sopenharmony_ci            },
4308fd4e5da5Sopenharmony_ci            /* .main_insts = */
4309fd4e5da5Sopenharmony_ci            {
4310fd4e5da5Sopenharmony_ci              "%bool_var = OpVariable %_pf_bool Output",
4311fd4e5da5Sopenharmony_ci              "OpStore %bool_var %used_bool",
4312fd4e5da5Sopenharmony_ci            },
4313fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4314fd4e5da5Sopenharmony_ci            {
4315fd4e5da5Sopenharmony_ci              "%dead_bool = OpSpecConstantFalse %bool",
4316fd4e5da5Sopenharmony_ci              "%dead_bool_vec1 = OpSpecConstantComposite %v2bool %dead_bool %dead_bool",
4317fd4e5da5Sopenharmony_ci              "%dead_bool_vec2 = OpSpecConstantComposite %v2bool %dead_bool %used_bool",
4318fd4e5da5Sopenharmony_ci            },
4319fd4e5da5Sopenharmony_ci            /* .checks = */
4320fd4e5da5Sopenharmony_ci            {
4321fd4e5da5Sopenharmony_ci              "; CHECK: [[bool:%\\w+]] = OpSpecConstantTrue %bool",
4322fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpSpecConstant",
4323fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[bool]]",
4324fd4e5da5Sopenharmony_ci            },
4325fd4e5da5Sopenharmony_ci        },
4326fd4e5da5Sopenharmony_ci
4327fd4e5da5Sopenharmony_ci        // Uint vector type spec constants. One vector has all component dead,
4328fd4e5da5Sopenharmony_ci        // another vector has one dead unsigned integer and one used unsigned
4329fd4e5da5Sopenharmony_ci        // integer.
4330fd4e5da5Sopenharmony_ci        {
4331fd4e5da5Sopenharmony_ci            /* .used_consts = */
4332fd4e5da5Sopenharmony_ci            {
4333fd4e5da5Sopenharmony_ci              "%used_uint = OpSpecConstant %uint 3",
4334fd4e5da5Sopenharmony_ci            },
4335fd4e5da5Sopenharmony_ci            /* .main_insts = */
4336fd4e5da5Sopenharmony_ci            {
4337fd4e5da5Sopenharmony_ci              "%uint_var = OpVariable %_pf_uint Output",
4338fd4e5da5Sopenharmony_ci              "OpStore %uint_var %used_uint",
4339fd4e5da5Sopenharmony_ci            },
4340fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4341fd4e5da5Sopenharmony_ci            {
4342fd4e5da5Sopenharmony_ci              "%dead_uint = OpSpecConstant %uint 1",
4343fd4e5da5Sopenharmony_ci              "%dead_uint_vec1 = OpSpecConstantComposite %v2uint %dead_uint %dead_uint",
4344fd4e5da5Sopenharmony_ci              "%dead_uint_vec2 = OpSpecConstantComposite %v2uint %dead_uint %used_uint",
4345fd4e5da5Sopenharmony_ci            },
4346fd4e5da5Sopenharmony_ci            /* .checks = */
4347fd4e5da5Sopenharmony_ci            {
4348fd4e5da5Sopenharmony_ci              "; CHECK: [[uint:%\\w+]] = OpSpecConstant %uint 3",
4349fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpSpecConstant",
4350fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[uint]]",
4351fd4e5da5Sopenharmony_ci            },
4352fd4e5da5Sopenharmony_ci        },
4353fd4e5da5Sopenharmony_ci
4354fd4e5da5Sopenharmony_ci        // Int vector type spec constants. One vector has all component dead,
4355fd4e5da5Sopenharmony_ci        // another vector has one dead integer and one used integer.
4356fd4e5da5Sopenharmony_ci        {
4357fd4e5da5Sopenharmony_ci            /* .used_consts = */
4358fd4e5da5Sopenharmony_ci            {
4359fd4e5da5Sopenharmony_ci              "%used_int = OpSpecConstant %int 3",
4360fd4e5da5Sopenharmony_ci            },
4361fd4e5da5Sopenharmony_ci            /* .main_insts = */
4362fd4e5da5Sopenharmony_ci            {
4363fd4e5da5Sopenharmony_ci              "%int_var = OpVariable %_pf_int Output",
4364fd4e5da5Sopenharmony_ci              "OpStore %int_var %used_int",
4365fd4e5da5Sopenharmony_ci            },
4366fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4367fd4e5da5Sopenharmony_ci            {
4368fd4e5da5Sopenharmony_ci              "%dead_int = OpSpecConstant %int 1",
4369fd4e5da5Sopenharmony_ci              "%dead_int_vec1 = OpSpecConstantComposite %v2int %dead_int %dead_int",
4370fd4e5da5Sopenharmony_ci              "%dead_int_vec2 = OpSpecConstantComposite %v2int %dead_int %used_int",
4371fd4e5da5Sopenharmony_ci            },
4372fd4e5da5Sopenharmony_ci            /* .checks = */
4373fd4e5da5Sopenharmony_ci            {
4374fd4e5da5Sopenharmony_ci              "; CHECK: [[int:%\\w+]] = OpSpecConstant %int 3",
4375fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpSpecConstant",
4376fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[int]]",
4377fd4e5da5Sopenharmony_ci            },
4378fd4e5da5Sopenharmony_ci        },
4379fd4e5da5Sopenharmony_ci
4380fd4e5da5Sopenharmony_ci        // Int vector type spec constants built with both spec constants and
4381fd4e5da5Sopenharmony_ci        // front-end constants.
4382fd4e5da5Sopenharmony_ci        {
4383fd4e5da5Sopenharmony_ci            /* .used_consts = */
4384fd4e5da5Sopenharmony_ci            {
4385fd4e5da5Sopenharmony_ci              "%used_spec_int = OpSpecConstant %int 3",
4386fd4e5da5Sopenharmony_ci              "%used_front_end_int = OpConstant %int 3",
4387fd4e5da5Sopenharmony_ci            },
4388fd4e5da5Sopenharmony_ci            /* .main_insts = */
4389fd4e5da5Sopenharmony_ci            {
4390fd4e5da5Sopenharmony_ci              "%int_var1 = OpVariable %_pf_int Output",
4391fd4e5da5Sopenharmony_ci              "OpStore %int_var1 %used_spec_int",
4392fd4e5da5Sopenharmony_ci              "%int_var2 = OpVariable %_pf_int Output",
4393fd4e5da5Sopenharmony_ci              "OpStore %int_var2 %used_front_end_int",
4394fd4e5da5Sopenharmony_ci            },
4395fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4396fd4e5da5Sopenharmony_ci            {
4397fd4e5da5Sopenharmony_ci              "%dead_spec_int = OpSpecConstant %int 1",
4398fd4e5da5Sopenharmony_ci              "%dead_front_end_int = OpConstant %int 1",
4399fd4e5da5Sopenharmony_ci              // Dead front-end and dead spec constants
4400fd4e5da5Sopenharmony_ci              "%dead_int_vec1 = OpSpecConstantComposite %v2int %dead_spec_int %dead_front_end_int",
4401fd4e5da5Sopenharmony_ci              // Used front-end and dead spec constants
4402fd4e5da5Sopenharmony_ci              "%dead_int_vec2 = OpSpecConstantComposite %v2int %dead_spec_int %used_front_end_int",
4403fd4e5da5Sopenharmony_ci              // Dead front-end and used spec constants
4404fd4e5da5Sopenharmony_ci              "%dead_int_vec3 = OpSpecConstantComposite %v2int %dead_front_end_int %used_spec_int",
4405fd4e5da5Sopenharmony_ci            },
4406fd4e5da5Sopenharmony_ci            /* .checks = */
4407fd4e5da5Sopenharmony_ci            {
4408fd4e5da5Sopenharmony_ci              "; CHECK: [[int1:%\\w+]] = OpSpecConstant %int 3",
4409fd4e5da5Sopenharmony_ci              "; CHECK: [[int2:%\\w+]] = OpConstant %int 3",
4410fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpSpecConstant",
4411fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4412fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[int1]]",
4413fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[int2]]",
4414fd4e5da5Sopenharmony_ci            },
4415fd4e5da5Sopenharmony_ci        },
4416fd4e5da5Sopenharmony_ci        // clang-format on
4417fd4e5da5Sopenharmony_ci    })));
4418fd4e5da5Sopenharmony_ci
4419fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
4420fd4e5da5Sopenharmony_ci    SpecConstantOp, AggressiveEliminateDeadConstantTest,
4421fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<AggressiveEliminateDeadConstantTestCase>({
4422fd4e5da5Sopenharmony_ci        // clang-format off
4423fd4e5da5Sopenharmony_ci        // Cast operations: uint <-> int <-> bool
4424fd4e5da5Sopenharmony_ci        {
4425fd4e5da5Sopenharmony_ci            /* .used_consts = */ {},
4426fd4e5da5Sopenharmony_ci            /* .main_insts = */ {},
4427fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4428fd4e5da5Sopenharmony_ci            {
4429fd4e5da5Sopenharmony_ci              // Assistant constants, only used in dead spec constant
4430fd4e5da5Sopenharmony_ci              // operations.
4431fd4e5da5Sopenharmony_ci              "%signed_zero = OpConstant %int 0",
4432fd4e5da5Sopenharmony_ci              "%signed_zero_vec = OpConstantComposite %v2int %signed_zero %signed_zero",
4433fd4e5da5Sopenharmony_ci              "%unsigned_zero = OpConstant %uint 0",
4434fd4e5da5Sopenharmony_ci              "%unsigned_zero_vec = OpConstantComposite %v2uint %unsigned_zero %unsigned_zero",
4435fd4e5da5Sopenharmony_ci              "%signed_one = OpConstant %int 1",
4436fd4e5da5Sopenharmony_ci              "%signed_one_vec = OpConstantComposite %v2int %signed_one %signed_one",
4437fd4e5da5Sopenharmony_ci              "%unsigned_one = OpConstant %uint 1",
4438fd4e5da5Sopenharmony_ci              "%unsigned_one_vec = OpConstantComposite %v2uint %unsigned_one %unsigned_one",
4439fd4e5da5Sopenharmony_ci
4440fd4e5da5Sopenharmony_ci              // Spec constants that support casting to each other.
4441fd4e5da5Sopenharmony_ci              "%dead_bool = OpSpecConstantTrue %bool",
4442fd4e5da5Sopenharmony_ci              "%dead_uint = OpSpecConstant %uint 1",
4443fd4e5da5Sopenharmony_ci              "%dead_int = OpSpecConstant %int 2",
4444fd4e5da5Sopenharmony_ci              "%dead_bool_vec = OpSpecConstantComposite %v2bool %dead_bool %dead_bool",
4445fd4e5da5Sopenharmony_ci              "%dead_uint_vec = OpSpecConstantComposite %v2uint %dead_uint %dead_uint",
4446fd4e5da5Sopenharmony_ci              "%dead_int_vec = OpSpecConstantComposite %v2int %dead_int %dead_int",
4447fd4e5da5Sopenharmony_ci
4448fd4e5da5Sopenharmony_ci              // Scalar cast to boolean spec constant.
4449fd4e5da5Sopenharmony_ci              "%int_to_bool = OpSpecConstantOp %bool INotEqual %dead_int %signed_zero",
4450fd4e5da5Sopenharmony_ci              "%uint_to_bool = OpSpecConstantOp %bool INotEqual %dead_uint %unsigned_zero",
4451fd4e5da5Sopenharmony_ci
4452fd4e5da5Sopenharmony_ci              // Vector cast to boolean spec constant.
4453fd4e5da5Sopenharmony_ci              "%int_to_bool_vec = OpSpecConstantOp %v2bool INotEqual %dead_int_vec %signed_zero_vec",
4454fd4e5da5Sopenharmony_ci              "%uint_to_bool_vec = OpSpecConstantOp %v2bool INotEqual %dead_uint_vec %unsigned_zero_vec",
4455fd4e5da5Sopenharmony_ci
4456fd4e5da5Sopenharmony_ci              // Scalar cast to int spec constant.
4457fd4e5da5Sopenharmony_ci              "%bool_to_int = OpSpecConstantOp %int Select %dead_bool %signed_one %signed_zero",
4458fd4e5da5Sopenharmony_ci              "%uint_to_int = OpSpecConstantOp %uint IAdd %dead_uint %unsigned_zero",
4459fd4e5da5Sopenharmony_ci
4460fd4e5da5Sopenharmony_ci              // Vector cast to int spec constant.
4461fd4e5da5Sopenharmony_ci              "%bool_to_int_vec = OpSpecConstantOp %v2int Select %dead_bool_vec %signed_one_vec %signed_zero_vec",
4462fd4e5da5Sopenharmony_ci              "%uint_to_int_vec = OpSpecConstantOp %v2uint IAdd %dead_uint_vec %unsigned_zero_vec",
4463fd4e5da5Sopenharmony_ci
4464fd4e5da5Sopenharmony_ci              // Scalar cast to uint spec constant.
4465fd4e5da5Sopenharmony_ci              "%bool_to_uint = OpSpecConstantOp %uint Select %dead_bool %unsigned_one %unsigned_zero",
4466fd4e5da5Sopenharmony_ci              "%int_to_uint_vec = OpSpecConstantOp %uint IAdd %dead_int %signed_zero",
4467fd4e5da5Sopenharmony_ci
4468fd4e5da5Sopenharmony_ci              // Vector cast to uint spec constant.
4469fd4e5da5Sopenharmony_ci              "%bool_to_uint_vec = OpSpecConstantOp %v2uint Select %dead_bool_vec %unsigned_one_vec %unsigned_zero_vec",
4470fd4e5da5Sopenharmony_ci              "%int_to_uint = OpSpecConstantOp %v2uint IAdd %dead_int_vec %signed_zero_vec",
4471fd4e5da5Sopenharmony_ci            },
4472fd4e5da5Sopenharmony_ci            /* .checks = */
4473fd4e5da5Sopenharmony_ci            {
4474fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4475fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpSpecConstant",
4476fd4e5da5Sopenharmony_ci            },
4477fd4e5da5Sopenharmony_ci        },
4478fd4e5da5Sopenharmony_ci
4479fd4e5da5Sopenharmony_ci        // Add, sub, mul, div, rem.
4480fd4e5da5Sopenharmony_ci        {
4481fd4e5da5Sopenharmony_ci            /* .used_consts = */ {},
4482fd4e5da5Sopenharmony_ci            /* .main_insts = */ {},
4483fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4484fd4e5da5Sopenharmony_ci            {
4485fd4e5da5Sopenharmony_ci              "%dead_spec_int_a = OpSpecConstant %int 1",
4486fd4e5da5Sopenharmony_ci              "%dead_spec_int_a_vec = OpSpecConstantComposite %v2int %dead_spec_int_a %dead_spec_int_a",
4487fd4e5da5Sopenharmony_ci
4488fd4e5da5Sopenharmony_ci              "%dead_spec_int_b = OpSpecConstant %int 2",
4489fd4e5da5Sopenharmony_ci              "%dead_spec_int_b_vec = OpSpecConstantComposite %v2int %dead_spec_int_b %dead_spec_int_b",
4490fd4e5da5Sopenharmony_ci
4491fd4e5da5Sopenharmony_ci              "%dead_const_int_c = OpConstant %int 3",
4492fd4e5da5Sopenharmony_ci              "%dead_const_int_c_vec = OpConstantComposite %v2int %dead_const_int_c %dead_const_int_c",
4493fd4e5da5Sopenharmony_ci
4494fd4e5da5Sopenharmony_ci              // Add
4495fd4e5da5Sopenharmony_ci              "%add_a_b = OpSpecConstantOp %int IAdd %dead_spec_int_a %dead_spec_int_b",
4496fd4e5da5Sopenharmony_ci              "%add_a_b_vec = OpSpecConstantOp %v2int IAdd %dead_spec_int_a_vec %dead_spec_int_b_vec",
4497fd4e5da5Sopenharmony_ci
4498fd4e5da5Sopenharmony_ci              // Sub
4499fd4e5da5Sopenharmony_ci              "%sub_a_b = OpSpecConstantOp %int ISub %dead_spec_int_a %dead_spec_int_b",
4500fd4e5da5Sopenharmony_ci              "%sub_a_b_vec = OpSpecConstantOp %v2int ISub %dead_spec_int_a_vec %dead_spec_int_b_vec",
4501fd4e5da5Sopenharmony_ci
4502fd4e5da5Sopenharmony_ci              // Mul
4503fd4e5da5Sopenharmony_ci              "%mul_a_b = OpSpecConstantOp %int IMul %dead_spec_int_a %dead_spec_int_b",
4504fd4e5da5Sopenharmony_ci              "%mul_a_b_vec = OpSpecConstantOp %v2int IMul %dead_spec_int_a_vec %dead_spec_int_b_vec",
4505fd4e5da5Sopenharmony_ci
4506fd4e5da5Sopenharmony_ci              // Div
4507fd4e5da5Sopenharmony_ci              "%div_a_b = OpSpecConstantOp %int SDiv %dead_spec_int_a %dead_spec_int_b",
4508fd4e5da5Sopenharmony_ci              "%div_a_b_vec = OpSpecConstantOp %v2int SDiv %dead_spec_int_a_vec %dead_spec_int_b_vec",
4509fd4e5da5Sopenharmony_ci
4510fd4e5da5Sopenharmony_ci              // Bitwise Xor
4511fd4e5da5Sopenharmony_ci              "%xor_a_b = OpSpecConstantOp %int BitwiseXor %dead_spec_int_a %dead_spec_int_b",
4512fd4e5da5Sopenharmony_ci              "%xor_a_b_vec = OpSpecConstantOp %v2int BitwiseXor %dead_spec_int_a_vec %dead_spec_int_b_vec",
4513fd4e5da5Sopenharmony_ci
4514fd4e5da5Sopenharmony_ci              // Scalar Comparison
4515fd4e5da5Sopenharmony_ci              "%less_a_b = OpSpecConstantOp %bool SLessThan %dead_spec_int_a %dead_spec_int_b",
4516fd4e5da5Sopenharmony_ci            },
4517fd4e5da5Sopenharmony_ci            /* .checks = */
4518fd4e5da5Sopenharmony_ci            {
4519fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4520fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpSpecConstant",
4521fd4e5da5Sopenharmony_ci            },
4522fd4e5da5Sopenharmony_ci        },
4523fd4e5da5Sopenharmony_ci
4524fd4e5da5Sopenharmony_ci        // Vectors without used swizzles should be removed.
4525fd4e5da5Sopenharmony_ci        {
4526fd4e5da5Sopenharmony_ci            /* .used_consts = */
4527fd4e5da5Sopenharmony_ci            {
4528fd4e5da5Sopenharmony_ci              "%used_int = OpConstant %int 3",
4529fd4e5da5Sopenharmony_ci            },
4530fd4e5da5Sopenharmony_ci            /* .main_insts = */
4531fd4e5da5Sopenharmony_ci            {
4532fd4e5da5Sopenharmony_ci              "%int_var = OpVariable %_pf_int Output",
4533fd4e5da5Sopenharmony_ci              "OpStore %int_var %used_int",
4534fd4e5da5Sopenharmony_ci            },
4535fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4536fd4e5da5Sopenharmony_ci            {
4537fd4e5da5Sopenharmony_ci              "%dead_int = OpConstant %int 3",
4538fd4e5da5Sopenharmony_ci
4539fd4e5da5Sopenharmony_ci              "%dead_spec_int_a = OpSpecConstant %int 1",
4540fd4e5da5Sopenharmony_ci              "%vec_a = OpSpecConstantComposite %v4int %dead_spec_int_a %dead_spec_int_a %dead_int %dead_int",
4541fd4e5da5Sopenharmony_ci
4542fd4e5da5Sopenharmony_ci              "%dead_spec_int_b = OpSpecConstant %int 2",
4543fd4e5da5Sopenharmony_ci              "%vec_b = OpSpecConstantComposite %v4int %dead_spec_int_b %dead_spec_int_b %used_int %used_int",
4544fd4e5da5Sopenharmony_ci
4545fd4e5da5Sopenharmony_ci              // Extract scalar
4546fd4e5da5Sopenharmony_ci              "%a_x = OpSpecConstantOp %int CompositeExtract %vec_a 0",
4547fd4e5da5Sopenharmony_ci              "%b_x = OpSpecConstantOp %int CompositeExtract %vec_b 0",
4548fd4e5da5Sopenharmony_ci
4549fd4e5da5Sopenharmony_ci              // Extract vector
4550fd4e5da5Sopenharmony_ci              "%a_xy = OpSpecConstantOp %v2int VectorShuffle %vec_a %vec_a 0 1",
4551fd4e5da5Sopenharmony_ci              "%b_xy = OpSpecConstantOp %v2int VectorShuffle %vec_b %vec_b 0 1",
4552fd4e5da5Sopenharmony_ci            },
4553fd4e5da5Sopenharmony_ci            /* .checks = */
4554fd4e5da5Sopenharmony_ci            {
4555fd4e5da5Sopenharmony_ci              "; CHECK: [[int:%\\w+]] = OpConstant %int 3",
4556fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4557fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpSpecConstant",
4558fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[int]]",
4559fd4e5da5Sopenharmony_ci            },
4560fd4e5da5Sopenharmony_ci        },
4561fd4e5da5Sopenharmony_ci        // Vectors with used swizzles should not be removed.
4562fd4e5da5Sopenharmony_ci        {
4563fd4e5da5Sopenharmony_ci            /* .used_consts = */
4564fd4e5da5Sopenharmony_ci            {
4565fd4e5da5Sopenharmony_ci              "%used_int = OpConstant %int 3",
4566fd4e5da5Sopenharmony_ci              "%used_spec_int_a = OpSpecConstant %int 1",
4567fd4e5da5Sopenharmony_ci              "%used_spec_int_b = OpSpecConstant %int 2",
4568fd4e5da5Sopenharmony_ci              // Create vectors
4569fd4e5da5Sopenharmony_ci              "%vec_a = OpSpecConstantComposite %v4int %used_spec_int_a %used_spec_int_a %used_int %used_int",
4570fd4e5da5Sopenharmony_ci              "%vec_b = OpSpecConstantComposite %v4int %used_spec_int_b %used_spec_int_b %used_int %used_int",
4571fd4e5da5Sopenharmony_ci              // Extract vector
4572fd4e5da5Sopenharmony_ci              "%a_xy = OpSpecConstantOp %v2int VectorShuffle %vec_a %vec_a 0 1",
4573fd4e5da5Sopenharmony_ci              "%b_xy = OpSpecConstantOp %v2int VectorShuffle %vec_b %vec_b 0 1",
4574fd4e5da5Sopenharmony_ci            },
4575fd4e5da5Sopenharmony_ci            /* .main_insts = */
4576fd4e5da5Sopenharmony_ci            {
4577fd4e5da5Sopenharmony_ci              "%v2int_var_a = OpVariable %_pf_v2int Output",
4578fd4e5da5Sopenharmony_ci              "%v2int_var_b = OpVariable %_pf_v2int Output",
4579fd4e5da5Sopenharmony_ci              "OpStore %v2int_var_a %a_xy",
4580fd4e5da5Sopenharmony_ci              "OpStore %v2int_var_b %b_xy",
4581fd4e5da5Sopenharmony_ci            },
4582fd4e5da5Sopenharmony_ci            /* .dead_consts = */ {},
4583fd4e5da5Sopenharmony_ci            /* .checks = */
4584fd4e5da5Sopenharmony_ci            {
4585fd4e5da5Sopenharmony_ci              "; CHECK: [[int:%\\w+]] = OpConstant %int 3",
4586fd4e5da5Sopenharmony_ci              "; CHECK: [[a:%\\w+]] = OpSpecConstant %int 1",
4587fd4e5da5Sopenharmony_ci              "; CHECK: [[b:%\\w+]] = OpSpecConstant %int 2",
4588fd4e5da5Sopenharmony_ci              "; CHECK: [[veca:%\\w+]] = OpSpecConstantComposite %v4int [[a]] [[a]] [[int]] [[int]]",
4589fd4e5da5Sopenharmony_ci              "; CHECK: [[vecb:%\\w+]] = OpSpecConstantComposite %v4int [[b]] [[b]] [[int]] [[int]]",
4590fd4e5da5Sopenharmony_ci              "; CHECK: [[exa:%\\w+]] = OpSpecConstantOp %v2int VectorShuffle [[veca]] [[veca]] 0 1",
4591fd4e5da5Sopenharmony_ci              "; CHECK: [[exb:%\\w+]] = OpSpecConstantOp %v2int VectorShuffle [[vecb]] [[vecb]] 0 1",
4592fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4593fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpSpecConstant",
4594fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[exa]]",
4595fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[exb]]",
4596fd4e5da5Sopenharmony_ci            },
4597fd4e5da5Sopenharmony_ci        },
4598fd4e5da5Sopenharmony_ci        // clang-format on
4599fd4e5da5Sopenharmony_ci    })));
4600fd4e5da5Sopenharmony_ci
4601fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(
4602fd4e5da5Sopenharmony_ci    LongDefUseChain, AggressiveEliminateDeadConstantTest,
4603fd4e5da5Sopenharmony_ci    ::testing::ValuesIn(std::vector<AggressiveEliminateDeadConstantTestCase>({
4604fd4e5da5Sopenharmony_ci        // clang-format off
4605fd4e5da5Sopenharmony_ci        // Long Def-Use chain with binary operations.
4606fd4e5da5Sopenharmony_ci        {
4607fd4e5da5Sopenharmony_ci            /* .used_consts = */
4608fd4e5da5Sopenharmony_ci            {
4609fd4e5da5Sopenharmony_ci              "%array_size = OpConstant %int 4",
4610fd4e5da5Sopenharmony_ci              "%type_arr_int_4 = OpTypeArray %int %array_size",
4611fd4e5da5Sopenharmony_ci              "%used_int_0 = OpConstant %int 100",
4612fd4e5da5Sopenharmony_ci              "%used_int_1 = OpConstant %int 1",
4613fd4e5da5Sopenharmony_ci              "%used_int_2 = OpSpecConstantOp %int IAdd %used_int_0 %used_int_1",
4614fd4e5da5Sopenharmony_ci              "%used_int_3 = OpSpecConstantOp %int ISub %used_int_0 %used_int_2",
4615fd4e5da5Sopenharmony_ci              "%used_int_4 = OpSpecConstantOp %int IAdd %used_int_0 %used_int_3",
4616fd4e5da5Sopenharmony_ci              "%used_int_5 = OpSpecConstantOp %int ISub %used_int_0 %used_int_4",
4617fd4e5da5Sopenharmony_ci              "%used_int_6 = OpSpecConstantOp %int IAdd %used_int_0 %used_int_5",
4618fd4e5da5Sopenharmony_ci              "%used_int_7 = OpSpecConstantOp %int ISub %used_int_0 %used_int_6",
4619fd4e5da5Sopenharmony_ci              "%used_int_8 = OpSpecConstantOp %int IAdd %used_int_0 %used_int_7",
4620fd4e5da5Sopenharmony_ci              "%used_int_9 = OpSpecConstantOp %int ISub %used_int_0 %used_int_8",
4621fd4e5da5Sopenharmony_ci              "%used_int_10 = OpSpecConstantOp %int IAdd %used_int_0 %used_int_9",
4622fd4e5da5Sopenharmony_ci              "%used_int_11 = OpSpecConstantOp %int ISub %used_int_0 %used_int_10",
4623fd4e5da5Sopenharmony_ci              "%used_int_12 = OpSpecConstantOp %int IAdd %used_int_0 %used_int_11",
4624fd4e5da5Sopenharmony_ci              "%used_int_13 = OpSpecConstantOp %int ISub %used_int_0 %used_int_12",
4625fd4e5da5Sopenharmony_ci              "%used_int_14 = OpSpecConstantOp %int IAdd %used_int_0 %used_int_13",
4626fd4e5da5Sopenharmony_ci              "%used_int_15 = OpSpecConstantOp %int ISub %used_int_0 %used_int_14",
4627fd4e5da5Sopenharmony_ci              "%used_int_16 = OpSpecConstantOp %int ISub %used_int_0 %used_int_15",
4628fd4e5da5Sopenharmony_ci              "%used_int_17 = OpSpecConstantOp %int IAdd %used_int_0 %used_int_16",
4629fd4e5da5Sopenharmony_ci              "%used_int_18 = OpSpecConstantOp %int ISub %used_int_0 %used_int_17",
4630fd4e5da5Sopenharmony_ci              "%used_int_19 = OpSpecConstantOp %int IAdd %used_int_0 %used_int_18",
4631fd4e5da5Sopenharmony_ci              "%used_int_20 = OpSpecConstantOp %int ISub %used_int_0 %used_int_19",
4632fd4e5da5Sopenharmony_ci              "%used_vec_a = OpSpecConstantComposite %v2int %used_int_18 %used_int_19",
4633fd4e5da5Sopenharmony_ci              "%used_vec_b = OpSpecConstantOp %v2int IMul %used_vec_a %used_vec_a",
4634fd4e5da5Sopenharmony_ci              "%used_int_21 = OpSpecConstantOp %int CompositeExtract %used_vec_b 0",
4635fd4e5da5Sopenharmony_ci              "%used_array = OpConstantComposite %type_arr_int_4 %used_int_20 %used_int_20 %used_int_21 %used_int_21",
4636fd4e5da5Sopenharmony_ci            },
4637fd4e5da5Sopenharmony_ci            /* .main_insts = */
4638fd4e5da5Sopenharmony_ci            {
4639fd4e5da5Sopenharmony_ci              "%int_var = OpVariable %_pf_int Output",
4640fd4e5da5Sopenharmony_ci              "%used_array_2 = OpCompositeExtract %int %used_array 2",
4641fd4e5da5Sopenharmony_ci              "OpStore %int_var %used_array_2",
4642fd4e5da5Sopenharmony_ci            },
4643fd4e5da5Sopenharmony_ci            /* .dead_consts = */
4644fd4e5da5Sopenharmony_ci            {
4645fd4e5da5Sopenharmony_ci              "%dead_int_1 = OpConstant %int 2",
4646fd4e5da5Sopenharmony_ci              "%dead_int_2 = OpSpecConstantOp %int IAdd %used_int_0 %dead_int_1",
4647fd4e5da5Sopenharmony_ci              "%dead_int_3 = OpSpecConstantOp %int ISub %used_int_0 %dead_int_2",
4648fd4e5da5Sopenharmony_ci              "%dead_int_4 = OpSpecConstantOp %int IAdd %used_int_0 %dead_int_3",
4649fd4e5da5Sopenharmony_ci              "%dead_int_5 = OpSpecConstantOp %int ISub %used_int_0 %dead_int_4",
4650fd4e5da5Sopenharmony_ci              "%dead_int_6 = OpSpecConstantOp %int IAdd %used_int_0 %dead_int_5",
4651fd4e5da5Sopenharmony_ci              "%dead_int_7 = OpSpecConstantOp %int ISub %used_int_0 %dead_int_6",
4652fd4e5da5Sopenharmony_ci              "%dead_int_8 = OpSpecConstantOp %int IAdd %used_int_0 %dead_int_7",
4653fd4e5da5Sopenharmony_ci              "%dead_int_9 = OpSpecConstantOp %int ISub %used_int_0 %dead_int_8",
4654fd4e5da5Sopenharmony_ci              "%dead_int_10 = OpSpecConstantOp %int IAdd %used_int_0 %dead_int_9",
4655fd4e5da5Sopenharmony_ci              "%dead_int_11 = OpSpecConstantOp %int ISub %used_int_0 %dead_int_10",
4656fd4e5da5Sopenharmony_ci              "%dead_int_12 = OpSpecConstantOp %int IAdd %used_int_0 %dead_int_11",
4657fd4e5da5Sopenharmony_ci              "%dead_int_13 = OpSpecConstantOp %int ISub %used_int_0 %dead_int_12",
4658fd4e5da5Sopenharmony_ci              "%dead_int_14 = OpSpecConstantOp %int IAdd %used_int_0 %dead_int_13",
4659fd4e5da5Sopenharmony_ci              "%dead_int_15 = OpSpecConstantOp %int ISub %used_int_0 %dead_int_14",
4660fd4e5da5Sopenharmony_ci              "%dead_int_16 = OpSpecConstantOp %int ISub %used_int_0 %dead_int_15",
4661fd4e5da5Sopenharmony_ci              "%dead_int_17 = OpSpecConstantOp %int IAdd %used_int_0 %dead_int_16",
4662fd4e5da5Sopenharmony_ci              "%dead_int_18 = OpSpecConstantOp %int ISub %used_int_0 %dead_int_17",
4663fd4e5da5Sopenharmony_ci              "%dead_int_19 = OpSpecConstantOp %int IAdd %used_int_0 %dead_int_18",
4664fd4e5da5Sopenharmony_ci              "%dead_int_20 = OpSpecConstantOp %int ISub %used_int_0 %dead_int_19",
4665fd4e5da5Sopenharmony_ci              "%dead_vec_a = OpSpecConstantComposite %v2int %dead_int_18 %dead_int_19",
4666fd4e5da5Sopenharmony_ci              "%dead_vec_b = OpSpecConstantOp %v2int IMul %dead_vec_a %dead_vec_a",
4667fd4e5da5Sopenharmony_ci              "%dead_int_21 = OpSpecConstantOp %int CompositeExtract %dead_vec_b 0",
4668fd4e5da5Sopenharmony_ci              "%dead_array = OpConstantComposite %type_arr_int_4 %dead_int_20 %used_int_20 %dead_int_19 %used_int_19",
4669fd4e5da5Sopenharmony_ci            },
4670fd4e5da5Sopenharmony_ci            /* .checks = */
4671fd4e5da5Sopenharmony_ci            {
4672fd4e5da5Sopenharmony_ci              "; CHECK: OpConstant %int 4",
4673fd4e5da5Sopenharmony_ci              "; CHECK: [[array:%\\w+]] = OpConstantComposite %type_arr_int_4 %used_int_20 %used_int_20 %used_int_21 %used_int_21",
4674fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpConstant",
4675fd4e5da5Sopenharmony_ci              "; CHECK-NOT: OpSpecConstant",
4676fd4e5da5Sopenharmony_ci              "; CHECK: OpStore {{%\\w+}} [[array]]",
4677fd4e5da5Sopenharmony_ci            },
4678fd4e5da5Sopenharmony_ci        },
4679fd4e5da5Sopenharmony_ci        // Long Def-Use chain with swizzle
4680fd4e5da5Sopenharmony_ci        // clang-format on
4681fd4e5da5Sopenharmony_ci    })));
4682fd4e5da5Sopenharmony_ci
4683fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DeadDecorationGroup) {
4684fd4e5da5Sopenharmony_ci  // The decoration group should be eliminated because the target of group
4685fd4e5da5Sopenharmony_ci  // decorate is dead.
4686fd4e5da5Sopenharmony_ci  const std::string text = R"(
4687fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorat
4688fd4e5da5Sopenharmony_ci; CHECK-NOT: OpGroupDecorate
4689fd4e5da5Sopenharmony_ciOpCapability Shader
4690fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4691fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
4692fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4693fd4e5da5Sopenharmony_ciOpDecorate %1 Restrict
4694fd4e5da5Sopenharmony_ciOpDecorate %1 Aliased
4695fd4e5da5Sopenharmony_ci%1 = OpDecorationGroup
4696fd4e5da5Sopenharmony_ciOpGroupDecorate %1 %var
4697fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4698fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void
4699fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4700fd4e5da5Sopenharmony_ci%uint_ptr = OpTypePointer Function %uint
4701fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func
4702fd4e5da5Sopenharmony_ci%2 = OpLabel
4703fd4e5da5Sopenharmony_ci%var = OpVariable %uint_ptr Function
4704fd4e5da5Sopenharmony_ciOpReturn
4705fd4e5da5Sopenharmony_ciOpFunctionEnd
4706fd4e5da5Sopenharmony_ci  )";
4707fd4e5da5Sopenharmony_ci
4708fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
4709fd4e5da5Sopenharmony_ci}
4710fd4e5da5Sopenharmony_ci
4711fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DeadDecorationGroupAndValidDecorationMgr) {
4712fd4e5da5Sopenharmony_ci  // The decoration group should be eliminated because the target of group
4713fd4e5da5Sopenharmony_ci  // decorate is dead.
4714fd4e5da5Sopenharmony_ci  const std::string text = R"(
4715fd4e5da5Sopenharmony_ciOpCapability Shader
4716fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4717fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
4718fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4719fd4e5da5Sopenharmony_ciOpDecorate %1 Restrict
4720fd4e5da5Sopenharmony_ciOpDecorate %1 Aliased
4721fd4e5da5Sopenharmony_ci%1 = OpDecorationGroup
4722fd4e5da5Sopenharmony_ciOpGroupDecorate %1 %var
4723fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4724fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void
4725fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4726fd4e5da5Sopenharmony_ci%uint_ptr = OpTypePointer Function %uint
4727fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func
4728fd4e5da5Sopenharmony_ci%2 = OpLabel
4729fd4e5da5Sopenharmony_ci%var = OpVariable %uint_ptr Function
4730fd4e5da5Sopenharmony_ciOpReturn
4731fd4e5da5Sopenharmony_ciOpFunctionEnd
4732fd4e5da5Sopenharmony_ci  )";
4733fd4e5da5Sopenharmony_ci
4734fd4e5da5Sopenharmony_ci  auto pass = MakeUnique<AggressiveDCEPass>();
4735fd4e5da5Sopenharmony_ci  auto consumer = [](spv_message_level_t, const char*, const spv_position_t&,
4736fd4e5da5Sopenharmony_ci                     const char* message) {
4737fd4e5da5Sopenharmony_ci    std::cerr << message << std::endl;
4738fd4e5da5Sopenharmony_ci  };
4739fd4e5da5Sopenharmony_ci  auto context = BuildModule(SPV_ENV_UNIVERSAL_1_1, consumer, text);
4740fd4e5da5Sopenharmony_ci
4741fd4e5da5Sopenharmony_ci  // Build the decoration manager before the pass.
4742fd4e5da5Sopenharmony_ci  context->get_decoration_mgr();
4743fd4e5da5Sopenharmony_ci
4744fd4e5da5Sopenharmony_ci  const auto status = pass->Run(context.get());
4745fd4e5da5Sopenharmony_ci  EXPECT_EQ(status, Pass::Status::SuccessWithChange);
4746fd4e5da5Sopenharmony_ci}
4747fd4e5da5Sopenharmony_ci
4748fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, ParitallyDeadDecorationGroup) {
4749fd4e5da5Sopenharmony_ci  const std::string text = R"(
4750fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[grp:%\w+]] Restrict
4751fd4e5da5Sopenharmony_ci; CHECK: [[grp]] = OpDecorationGroup
4752fd4e5da5Sopenharmony_ci; CHECK: OpGroupDecorate [[grp]] [[output:%\w+]]
4753fd4e5da5Sopenharmony_ci; CHECK: [[output]] = OpVariable {{%\w+}} Output
4754fd4e5da5Sopenharmony_ci; CHECK-NOT: OpVariable {{%\w+}} Function
4755fd4e5da5Sopenharmony_ciOpCapability Shader
4756fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4757fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %output
4758fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4759fd4e5da5Sopenharmony_ciOpDecorate %1 Restrict
4760fd4e5da5Sopenharmony_ci%1 = OpDecorationGroup
4761fd4e5da5Sopenharmony_ciOpGroupDecorate %1 %var %output
4762fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4763fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void
4764fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4765fd4e5da5Sopenharmony_ci%uint_ptr_Function = OpTypePointer Function %uint
4766fd4e5da5Sopenharmony_ci%uint_ptr_Output = OpTypePointer Output %uint
4767fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
4768fd4e5da5Sopenharmony_ci%output = OpVariable %uint_ptr_Output Output
4769fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func
4770fd4e5da5Sopenharmony_ci%2 = OpLabel
4771fd4e5da5Sopenharmony_ci%var = OpVariable %uint_ptr_Function Function
4772fd4e5da5Sopenharmony_ciOpStore %output %uint_0
4773fd4e5da5Sopenharmony_ciOpReturn
4774fd4e5da5Sopenharmony_ciOpFunctionEnd
4775fd4e5da5Sopenharmony_ci  )";
4776fd4e5da5Sopenharmony_ci
4777fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
4778fd4e5da5Sopenharmony_ci}
4779fd4e5da5Sopenharmony_ci
4780fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, ParitallyDeadDecorationGroupDifferentGroupDecorate) {
4781fd4e5da5Sopenharmony_ci  const std::string text = R"(
4782fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[grp:%\w+]] Restrict
4783fd4e5da5Sopenharmony_ci; CHECK: [[grp]] = OpDecorationGroup
4784fd4e5da5Sopenharmony_ci; CHECK: OpGroupDecorate [[grp]] [[output:%\w+]]
4785fd4e5da5Sopenharmony_ci; CHECK-NOT: OpGroupDecorate
4786fd4e5da5Sopenharmony_ci; CHECK: [[output]] = OpVariable {{%\w+}} Output
4787fd4e5da5Sopenharmony_ci; CHECK-NOT: OpVariable {{%\w+}} Function
4788fd4e5da5Sopenharmony_ciOpCapability Shader
4789fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4790fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %output
4791fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4792fd4e5da5Sopenharmony_ciOpDecorate %1 Restrict
4793fd4e5da5Sopenharmony_ci%1 = OpDecorationGroup
4794fd4e5da5Sopenharmony_ciOpGroupDecorate %1 %output
4795fd4e5da5Sopenharmony_ciOpGroupDecorate %1 %var
4796fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4797fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void
4798fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4799fd4e5da5Sopenharmony_ci%uint_ptr_Function = OpTypePointer Function %uint
4800fd4e5da5Sopenharmony_ci%uint_ptr_Output = OpTypePointer Output %uint
4801fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
4802fd4e5da5Sopenharmony_ci%output = OpVariable %uint_ptr_Output Output
4803fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func
4804fd4e5da5Sopenharmony_ci%2 = OpLabel
4805fd4e5da5Sopenharmony_ci%var = OpVariable %uint_ptr_Function Function
4806fd4e5da5Sopenharmony_ciOpStore %output %uint_0
4807fd4e5da5Sopenharmony_ciOpReturn
4808fd4e5da5Sopenharmony_ciOpFunctionEnd
4809fd4e5da5Sopenharmony_ci  )";
4810fd4e5da5Sopenharmony_ci
4811fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
4812fd4e5da5Sopenharmony_ci}
4813fd4e5da5Sopenharmony_ci
4814fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DeadGroupMemberDecorate) {
4815fd4e5da5Sopenharmony_ci  const std::string text = R"(
4816fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDec
4817fd4e5da5Sopenharmony_ci; CHECK-NOT: OpGroup
4818fd4e5da5Sopenharmony_ciOpCapability Shader
4819fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4820fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
4821fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4822fd4e5da5Sopenharmony_ciOpDecorate %1 Offset 0
4823fd4e5da5Sopenharmony_ciOpDecorate %1 Uniform
4824fd4e5da5Sopenharmony_ci%1 = OpDecorationGroup
4825fd4e5da5Sopenharmony_ciOpGroupMemberDecorate %1 %var 0
4826fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4827fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void
4828fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4829fd4e5da5Sopenharmony_ci%struct = OpTypeStruct %uint %uint
4830fd4e5da5Sopenharmony_ci%struct_ptr = OpTypePointer Function %struct
4831fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func
4832fd4e5da5Sopenharmony_ci%2 = OpLabel
4833fd4e5da5Sopenharmony_ci%var = OpVariable %struct_ptr Function
4834fd4e5da5Sopenharmony_ciOpReturn
4835fd4e5da5Sopenharmony_ciOpFunctionEnd
4836fd4e5da5Sopenharmony_ci  )";
4837fd4e5da5Sopenharmony_ci
4838fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
4839fd4e5da5Sopenharmony_ci}
4840fd4e5da5Sopenharmony_ci
4841fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, PartiallyDeadGroupMemberDecorate) {
4842fd4e5da5Sopenharmony_ci  const std::string text = R"(
4843fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[grp:%\w+]] Offset 0
4844fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[grp]] RelaxedPrecision
4845fd4e5da5Sopenharmony_ci; CHECK: [[grp]] = OpDecorationGroup
4846fd4e5da5Sopenharmony_ci; CHECK: OpGroupMemberDecorate [[grp]] [[output:%\w+]] 1
4847fd4e5da5Sopenharmony_ci; CHECK: [[output]] = OpTypeStruct
4848fd4e5da5Sopenharmony_ci; CHECK-NOT: OpTypeStruct
4849fd4e5da5Sopenharmony_ciOpCapability Shader
4850fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4851fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %output
4852fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4853fd4e5da5Sopenharmony_ciOpDecorate %1 Offset 0
4854fd4e5da5Sopenharmony_ciOpDecorate %1 RelaxedPrecision
4855fd4e5da5Sopenharmony_ci%1 = OpDecorationGroup
4856fd4e5da5Sopenharmony_ciOpGroupMemberDecorate %1 %var_struct 0 %output_struct 1
4857fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4858fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void
4859fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4860fd4e5da5Sopenharmony_ci%var_struct = OpTypeStruct %uint %uint
4861fd4e5da5Sopenharmony_ci%output_struct = OpTypeStruct %uint %uint
4862fd4e5da5Sopenharmony_ci%struct_ptr_Function = OpTypePointer Function %var_struct
4863fd4e5da5Sopenharmony_ci%struct_ptr_Output = OpTypePointer Output %output_struct
4864fd4e5da5Sopenharmony_ci%uint_ptr_Output = OpTypePointer Output %uint
4865fd4e5da5Sopenharmony_ci%output = OpVariable %struct_ptr_Output Output
4866fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
4867fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func
4868fd4e5da5Sopenharmony_ci%2 = OpLabel
4869fd4e5da5Sopenharmony_ci%var = OpVariable %struct_ptr_Function Function
4870fd4e5da5Sopenharmony_ci%3 = OpAccessChain %uint_ptr_Output %output %uint_0
4871fd4e5da5Sopenharmony_ciOpStore %3 %uint_0
4872fd4e5da5Sopenharmony_ciOpReturn
4873fd4e5da5Sopenharmony_ciOpFunctionEnd
4874fd4e5da5Sopenharmony_ci  )";
4875fd4e5da5Sopenharmony_ci
4876fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
4877fd4e5da5Sopenharmony_ci}
4878fd4e5da5Sopenharmony_ci
4879fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest,
4880fd4e5da5Sopenharmony_ci       PartiallyDeadGroupMemberDecorateDifferentGroupDecorate) {
4881fd4e5da5Sopenharmony_ci  const std::string text = R"(
4882fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[grp:%\w+]] Offset 0
4883fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[grp]] RelaxedPrecision
4884fd4e5da5Sopenharmony_ci; CHECK: [[grp]] = OpDecorationGroup
4885fd4e5da5Sopenharmony_ci; CHECK: OpGroupMemberDecorate [[grp]] [[output:%\w+]] 1
4886fd4e5da5Sopenharmony_ci; CHECK-NOT: OpGroupMemberDecorate
4887fd4e5da5Sopenharmony_ci; CHECK: [[output]] = OpTypeStruct
4888fd4e5da5Sopenharmony_ci; CHECK-NOT: OpTypeStruct
4889fd4e5da5Sopenharmony_ciOpCapability Shader
4890fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4891fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %output
4892fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
4893fd4e5da5Sopenharmony_ciOpDecorate %1 Offset 0
4894fd4e5da5Sopenharmony_ciOpDecorate %1 RelaxedPrecision
4895fd4e5da5Sopenharmony_ci%1 = OpDecorationGroup
4896fd4e5da5Sopenharmony_ciOpGroupMemberDecorate %1 %var_struct 0
4897fd4e5da5Sopenharmony_ciOpGroupMemberDecorate %1 %output_struct 1
4898fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4899fd4e5da5Sopenharmony_ci%func = OpTypeFunction %void
4900fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4901fd4e5da5Sopenharmony_ci%var_struct = OpTypeStruct %uint %uint
4902fd4e5da5Sopenharmony_ci%output_struct = OpTypeStruct %uint %uint
4903fd4e5da5Sopenharmony_ci%struct_ptr_Function = OpTypePointer Function %var_struct
4904fd4e5da5Sopenharmony_ci%struct_ptr_Output = OpTypePointer Output %output_struct
4905fd4e5da5Sopenharmony_ci%uint_ptr_Output = OpTypePointer Output %uint
4906fd4e5da5Sopenharmony_ci%output = OpVariable %struct_ptr_Output Output
4907fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
4908fd4e5da5Sopenharmony_ci%main = OpFunction %void None %func
4909fd4e5da5Sopenharmony_ci%2 = OpLabel
4910fd4e5da5Sopenharmony_ci%var = OpVariable %struct_ptr_Function Function
4911fd4e5da5Sopenharmony_ci%3 = OpAccessChain %uint_ptr_Output %output %uint_0
4912fd4e5da5Sopenharmony_ciOpStore %3 %uint_0
4913fd4e5da5Sopenharmony_ciOpReturn
4914fd4e5da5Sopenharmony_ciOpFunctionEnd
4915fd4e5da5Sopenharmony_ci  )";
4916fd4e5da5Sopenharmony_ci
4917fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
4918fd4e5da5Sopenharmony_ci}
4919fd4e5da5Sopenharmony_ci
4920fd4e5da5Sopenharmony_ci// Test for #1404
4921fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DontRemoveWorkgroupSize) {
4922fd4e5da5Sopenharmony_ci  const std::string text = R"(
4923fd4e5da5Sopenharmony_ci; CHECK: OpDecorate [[wgs:%\w+]] BuiltIn WorkgroupSize
4924fd4e5da5Sopenharmony_ci; CHECK: [[wgs]] = OpSpecConstantComposite
4925fd4e5da5Sopenharmony_ciOpCapability Shader
4926fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4927fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %func "func"
4928fd4e5da5Sopenharmony_ciOpExecutionMode %func LocalSize 1 1 1
4929fd4e5da5Sopenharmony_ciOpDecorate %1 BuiltIn WorkgroupSize
4930fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4931fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0
4932fd4e5da5Sopenharmony_ci%functy = OpTypeFunction %void
4933fd4e5da5Sopenharmony_ci%v3int = OpTypeVector %int 3
4934fd4e5da5Sopenharmony_ci%2 = OpSpecConstant %int 1
4935fd4e5da5Sopenharmony_ci%1 = OpSpecConstantComposite %v3int %2 %2 %2
4936fd4e5da5Sopenharmony_ci%func = OpFunction %void None %functy
4937fd4e5da5Sopenharmony_ci%3 = OpLabel
4938fd4e5da5Sopenharmony_ciOpReturn
4939fd4e5da5Sopenharmony_ciOpFunctionEnd
4940fd4e5da5Sopenharmony_ci)";
4941fd4e5da5Sopenharmony_ci
4942fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
4943fd4e5da5Sopenharmony_ci}
4944fd4e5da5Sopenharmony_ci
4945fd4e5da5Sopenharmony_ci// Test for #1214
4946fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, LoopHeaderIsAlsoAnotherLoopMerge) {
4947fd4e5da5Sopenharmony_ci  const std::string text = R"(OpCapability Shader
4948fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4949fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %1 "func" %2
4950fd4e5da5Sopenharmony_ciOpExecutionMode %1 OriginUpperLeft
4951fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4952fd4e5da5Sopenharmony_ci%bool = OpTypeBool
4953fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool
4954fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
4955fd4e5da5Sopenharmony_ci%_ptr_Output_uint = OpTypePointer Output %uint
4956fd4e5da5Sopenharmony_ci%2 = OpVariable %_ptr_Output_uint Output
4957fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
4958fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
4959fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %9
4960fd4e5da5Sopenharmony_ci%10 = OpLabel
4961fd4e5da5Sopenharmony_ciOpBranch %11
4962fd4e5da5Sopenharmony_ci%11 = OpLabel
4963fd4e5da5Sopenharmony_ciOpLoopMerge %12 %13 None
4964fd4e5da5Sopenharmony_ciOpBranchConditional %true %14 %13
4965fd4e5da5Sopenharmony_ci%14 = OpLabel
4966fd4e5da5Sopenharmony_ciOpStore %2 %uint_0
4967fd4e5da5Sopenharmony_ciOpLoopMerge %15 %16 None
4968fd4e5da5Sopenharmony_ciOpBranchConditional %true %15 %16
4969fd4e5da5Sopenharmony_ci%16 = OpLabel
4970fd4e5da5Sopenharmony_ciOpBranch %14
4971fd4e5da5Sopenharmony_ci%15 = OpLabel
4972fd4e5da5Sopenharmony_ciOpBranchConditional %true %12 %13
4973fd4e5da5Sopenharmony_ci%13 = OpLabel
4974fd4e5da5Sopenharmony_ciOpBranch %11
4975fd4e5da5Sopenharmony_ci%12 = OpLabel
4976fd4e5da5Sopenharmony_ci%17 = OpPhi %uint %uint_0 %15 %uint_0 %18
4977fd4e5da5Sopenharmony_ciOpStore %2 %17
4978fd4e5da5Sopenharmony_ciOpLoopMerge %19 %18 None
4979fd4e5da5Sopenharmony_ciOpBranchConditional %true %19 %18
4980fd4e5da5Sopenharmony_ci%18 = OpLabel
4981fd4e5da5Sopenharmony_ciOpBranch %12
4982fd4e5da5Sopenharmony_ci%19 = OpLabel
4983fd4e5da5Sopenharmony_ciOpReturn
4984fd4e5da5Sopenharmony_ciOpFunctionEnd
4985fd4e5da5Sopenharmony_ci)";
4986fd4e5da5Sopenharmony_ci
4987fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(text, text, true, true);
4988fd4e5da5Sopenharmony_ci}
4989fd4e5da5Sopenharmony_ci
4990fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, BreaksDontVisitPhis) {
4991fd4e5da5Sopenharmony_ci  const std::string text = R"(
4992fd4e5da5Sopenharmony_ciOpCapability Shader
4993fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
4994fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %func "func" %var
4995fd4e5da5Sopenharmony_ciOpExecutionMode %func OriginUpperLeft
4996fd4e5da5Sopenharmony_ci%void = OpTypeVoid
4997fd4e5da5Sopenharmony_ci%bool = OpTypeBool
4998fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool
4999fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0
5000fd4e5da5Sopenharmony_ci%int_ptr_Output = OpTypePointer Output %int
5001fd4e5da5Sopenharmony_ci%var = OpVariable %int_ptr_Output Output
5002fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0
5003fd4e5da5Sopenharmony_ci%functy = OpTypeFunction %void
5004fd4e5da5Sopenharmony_ci%func = OpFunction %void None %functy
5005fd4e5da5Sopenharmony_ci%entry = OpLabel
5006fd4e5da5Sopenharmony_ciOpBranch %outer_header
5007fd4e5da5Sopenharmony_ci%outer_header = OpLabel
5008fd4e5da5Sopenharmony_ciOpLoopMerge %outer_merge %outer_continue None
5009fd4e5da5Sopenharmony_ciOpBranchConditional %true %inner_header %outer_continue
5010fd4e5da5Sopenharmony_ci%inner_header = OpLabel
5011fd4e5da5Sopenharmony_ci%phi = OpPhi %int %int0 %outer_header %int0 %inner_continue
5012fd4e5da5Sopenharmony_ciOpStore %var %phi
5013fd4e5da5Sopenharmony_ciOpLoopMerge %inner_merge %inner_continue None
5014fd4e5da5Sopenharmony_ciOpBranchConditional %true %inner_merge %inner_continue
5015fd4e5da5Sopenharmony_ci%inner_continue = OpLabel
5016fd4e5da5Sopenharmony_ciOpBranch %inner_header
5017fd4e5da5Sopenharmony_ci%inner_merge = OpLabel
5018fd4e5da5Sopenharmony_ciOpBranch %outer_continue
5019fd4e5da5Sopenharmony_ci%outer_continue = OpLabel
5020fd4e5da5Sopenharmony_ci%p = OpPhi %int %int0 %outer_header %int0 %inner_merge
5021fd4e5da5Sopenharmony_ciOpStore %var %p
5022fd4e5da5Sopenharmony_ciOpBranch %outer_header
5023fd4e5da5Sopenharmony_ci%outer_merge = OpLabel
5024fd4e5da5Sopenharmony_ciOpReturn
5025fd4e5da5Sopenharmony_ciOpFunctionEnd
5026fd4e5da5Sopenharmony_ci)";
5027fd4e5da5Sopenharmony_ci
5028fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange,
5029fd4e5da5Sopenharmony_ci            std::get<1>(SinglePassRunAndDisassemble<AggressiveDCEPass>(
5030fd4e5da5Sopenharmony_ci                text, false, true)));
5031fd4e5da5Sopenharmony_ci}
5032fd4e5da5Sopenharmony_ci
5033fd4e5da5Sopenharmony_ci// Test for #1212
5034fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, ConstStoreInnerLoop) {
5035fd4e5da5Sopenharmony_ci  const std::string text = R"(OpCapability Shader
5036fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5037fd4e5da5Sopenharmony_ciOpEntryPoint Vertex %1 "main" %2
5038fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5039fd4e5da5Sopenharmony_ci%4 = OpTypeFunction %void
5040fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5041fd4e5da5Sopenharmony_ci%bool = OpTypeBool
5042fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool
5043fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
5044fd4e5da5Sopenharmony_ci%2 = OpVariable %_ptr_Output_float Output
5045fd4e5da5Sopenharmony_ci%float_3 = OpConstant %float 3
5046fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %4
5047fd4e5da5Sopenharmony_ci%13 = OpLabel
5048fd4e5da5Sopenharmony_ciOpBranch %14
5049fd4e5da5Sopenharmony_ci%14 = OpLabel
5050fd4e5da5Sopenharmony_ciOpLoopMerge %15 %16 None
5051fd4e5da5Sopenharmony_ciOpBranchConditional %true %17 %15
5052fd4e5da5Sopenharmony_ci%17 = OpLabel
5053fd4e5da5Sopenharmony_ciOpStore %2 %float_3
5054fd4e5da5Sopenharmony_ciOpLoopMerge %18 %17 None
5055fd4e5da5Sopenharmony_ciOpBranchConditional %true %18 %17
5056fd4e5da5Sopenharmony_ci%18 = OpLabel
5057fd4e5da5Sopenharmony_ciOpBranch %15
5058fd4e5da5Sopenharmony_ci%16 = OpLabel
5059fd4e5da5Sopenharmony_ciOpBranch %14
5060fd4e5da5Sopenharmony_ci%15 = OpLabel
5061fd4e5da5Sopenharmony_ciOpBranch %20
5062fd4e5da5Sopenharmony_ci%20 = OpLabel
5063fd4e5da5Sopenharmony_ciOpReturn
5064fd4e5da5Sopenharmony_ciOpFunctionEnd
5065fd4e5da5Sopenharmony_ci)";
5066fd4e5da5Sopenharmony_ci
5067fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5068fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(text, text, true, true);
5069fd4e5da5Sopenharmony_ci}
5070fd4e5da5Sopenharmony_ci
5071fd4e5da5Sopenharmony_ci// Test for #1212
5072fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, InnerLoopCopy) {
5073fd4e5da5Sopenharmony_ci  const std::string text = R"(OpCapability Shader
5074fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5075fd4e5da5Sopenharmony_ciOpEntryPoint Vertex %1 "main" %2 %3
5076fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5077fd4e5da5Sopenharmony_ci%5 = OpTypeFunction %void
5078fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5079fd4e5da5Sopenharmony_ci%bool = OpTypeBool
5080fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool
5081fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
5082fd4e5da5Sopenharmony_ci%_ptr_Input_float = OpTypePointer Input %float
5083fd4e5da5Sopenharmony_ci%2 = OpVariable %_ptr_Output_float Output
5084fd4e5da5Sopenharmony_ci%3 = OpVariable %_ptr_Input_float Input
5085fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %5
5086fd4e5da5Sopenharmony_ci%14 = OpLabel
5087fd4e5da5Sopenharmony_ciOpBranch %15
5088fd4e5da5Sopenharmony_ci%15 = OpLabel
5089fd4e5da5Sopenharmony_ciOpLoopMerge %16 %17 None
5090fd4e5da5Sopenharmony_ciOpBranchConditional %true %18 %16
5091fd4e5da5Sopenharmony_ci%18 = OpLabel
5092fd4e5da5Sopenharmony_ci%19 = OpLoad %float %3
5093fd4e5da5Sopenharmony_ciOpStore %2 %19
5094fd4e5da5Sopenharmony_ciOpLoopMerge %20 %18 None
5095fd4e5da5Sopenharmony_ciOpBranchConditional %true %20 %18
5096fd4e5da5Sopenharmony_ci%20 = OpLabel
5097fd4e5da5Sopenharmony_ciOpBranch %16
5098fd4e5da5Sopenharmony_ci%17 = OpLabel
5099fd4e5da5Sopenharmony_ciOpBranch %15
5100fd4e5da5Sopenharmony_ci%16 = OpLabel
5101fd4e5da5Sopenharmony_ciOpBranch %22
5102fd4e5da5Sopenharmony_ci%22 = OpLabel
5103fd4e5da5Sopenharmony_ciOpReturn
5104fd4e5da5Sopenharmony_ciOpFunctionEnd
5105fd4e5da5Sopenharmony_ci)";
5106fd4e5da5Sopenharmony_ci
5107fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5108fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(text, text, true, true);
5109fd4e5da5Sopenharmony_ci}
5110fd4e5da5Sopenharmony_ci
5111fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, AtomicAdd) {
5112fd4e5da5Sopenharmony_ci  const std::string text = R"(OpCapability SampledBuffer
5113fd4e5da5Sopenharmony_ciOpCapability StorageImageExtendedFormats
5114fd4e5da5Sopenharmony_ciOpCapability ImageBuffer
5115fd4e5da5Sopenharmony_ciOpCapability Shader
5116fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5117fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5118fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %2 "min"
5119fd4e5da5Sopenharmony_ciOpExecutionMode %2 LocalSize 64 1 1
5120fd4e5da5Sopenharmony_ciOpSource HLSL 600
5121fd4e5da5Sopenharmony_ciOpDecorate %4 DescriptorSet 4
5122fd4e5da5Sopenharmony_ciOpDecorate %4 Binding 70
5123fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
5124fd4e5da5Sopenharmony_ci%6 = OpTypeImage %uint Buffer 0 0 0 2 R32ui
5125fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_6 = OpTypePointer UniformConstant %6
5126fd4e5da5Sopenharmony_ci%_ptr_Private_6 = OpTypePointer Private %6
5127fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5128fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void
5129fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
5130fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
5131fd4e5da5Sopenharmony_ci%_ptr_Image_uint = OpTypePointer Image %uint
5132fd4e5da5Sopenharmony_ci%4 = OpVariable %_ptr_UniformConstant_6 UniformConstant
5133fd4e5da5Sopenharmony_ci%16 = OpVariable %_ptr_Private_6 Private
5134fd4e5da5Sopenharmony_ci%2 = OpFunction %void None %10
5135fd4e5da5Sopenharmony_ci%17 = OpLabel
5136fd4e5da5Sopenharmony_ci%18 = OpLoad %6 %4
5137fd4e5da5Sopenharmony_ciOpStore %16 %18
5138fd4e5da5Sopenharmony_ci%19 = OpImageTexelPointer %_ptr_Image_uint %16 %uint_0 %uint_0
5139fd4e5da5Sopenharmony_ci%20 = OpAtomicIAdd %uint %19 %uint_1 %uint_0 %uint_1
5140fd4e5da5Sopenharmony_ciOpReturn
5141fd4e5da5Sopenharmony_ciOpFunctionEnd
5142fd4e5da5Sopenharmony_ci)";
5143fd4e5da5Sopenharmony_ci
5144fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5145fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(text, text, true, true);
5146fd4e5da5Sopenharmony_ci}
5147fd4e5da5Sopenharmony_ci
5148fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, SafelyRemoveDecorateString) {
5149fd4e5da5Sopenharmony_ci  const std::string preamble = R"(OpCapability Shader
5150fd4e5da5Sopenharmony_ciOpExtension "SPV_GOOGLE_hlsl_functionality1"
5151fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5152fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %1 "main"
5153fd4e5da5Sopenharmony_ciOpExecutionMode %1 OriginUpperLeft
5154fd4e5da5Sopenharmony_ci)";
5155fd4e5da5Sopenharmony_ci
5156fd4e5da5Sopenharmony_ci  const std::string body_before =
5157fd4e5da5Sopenharmony_ci      R"(OpDecorateStringGOOGLE %2 HlslSemanticGOOGLE "FOOBAR"
5158fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5159fd4e5da5Sopenharmony_ci%4 = OpTypeFunction %void
5160fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
5161fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
5162fd4e5da5Sopenharmony_ci%2 = OpVariable %_ptr_StorageBuffer_uint StorageBuffer
5163fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %4
5164fd4e5da5Sopenharmony_ci%7 = OpLabel
5165fd4e5da5Sopenharmony_ciOpReturn
5166fd4e5da5Sopenharmony_ciOpFunctionEnd
5167fd4e5da5Sopenharmony_ci)";
5168fd4e5da5Sopenharmony_ci
5169fd4e5da5Sopenharmony_ci  const std::string body_after = R"(%void = OpTypeVoid
5170fd4e5da5Sopenharmony_ci%4 = OpTypeFunction %void
5171fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %4
5172fd4e5da5Sopenharmony_ci%7 = OpLabel
5173fd4e5da5Sopenharmony_ciOpReturn
5174fd4e5da5Sopenharmony_ciOpFunctionEnd
5175fd4e5da5Sopenharmony_ci)";
5176fd4e5da5Sopenharmony_ci
5177fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5178fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(preamble + body_before,
5179fd4e5da5Sopenharmony_ci                                           preamble + body_after, true, true);
5180fd4e5da5Sopenharmony_ci}
5181fd4e5da5Sopenharmony_ci
5182fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, CopyMemoryToGlobal) {
5183fd4e5da5Sopenharmony_ci  // |local| is loaded in an OpCopyMemory instruction.  So the store must be
5184fd4e5da5Sopenharmony_ci  // kept alive.
5185fd4e5da5Sopenharmony_ci  const std::string test =
5186fd4e5da5Sopenharmony_ci      R"(OpCapability Geometry
5187fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5188fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5189fd4e5da5Sopenharmony_ciOpEntryPoint Geometry %main "main" %global
5190fd4e5da5Sopenharmony_ciOpExecutionMode %main Triangles
5191fd4e5da5Sopenharmony_ciOpExecutionMode %main Invocations 1
5192fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputTriangleStrip
5193fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputVertices 5
5194fd4e5da5Sopenharmony_ciOpSource GLSL 440
5195fd4e5da5Sopenharmony_ciOpName %main "main"
5196fd4e5da5Sopenharmony_ciOpName %local "local"
5197fd4e5da5Sopenharmony_ciOpName %global "global"
5198fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5199fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
5200fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5201fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
5202fd4e5da5Sopenharmony_ci%12 = OpConstantNull %v4float
5203fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
5204fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
5205fd4e5da5Sopenharmony_ci%global = OpVariable %_ptr_Output_v4float Output
5206fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
5207fd4e5da5Sopenharmony_ci%19 = OpLabel
5208fd4e5da5Sopenharmony_ci%local = OpVariable %_ptr_Function_v4float Function
5209fd4e5da5Sopenharmony_ciOpStore %local %12
5210fd4e5da5Sopenharmony_ciOpCopyMemory %global %local
5211fd4e5da5Sopenharmony_ciOpEndPrimitive
5212fd4e5da5Sopenharmony_ciOpReturn
5213fd4e5da5Sopenharmony_ciOpFunctionEnd
5214fd4e5da5Sopenharmony_ci)";
5215fd4e5da5Sopenharmony_ci
5216fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5217fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(test, test, true, true);
5218fd4e5da5Sopenharmony_ci}
5219fd4e5da5Sopenharmony_ci
5220fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, CopyMemoryToLocal) {
5221fd4e5da5Sopenharmony_ci  // Make sure the store to |local2| using OpCopyMemory is kept and keeps
5222fd4e5da5Sopenharmony_ci  // |local1| alive.
5223fd4e5da5Sopenharmony_ci  const std::string test =
5224fd4e5da5Sopenharmony_ci      R"(OpCapability Geometry
5225fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5226fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5227fd4e5da5Sopenharmony_ciOpEntryPoint Geometry %main "main" %global
5228fd4e5da5Sopenharmony_ciOpExecutionMode %main Triangles
5229fd4e5da5Sopenharmony_ciOpExecutionMode %main Invocations 1
5230fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputTriangleStrip
5231fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputVertices 5
5232fd4e5da5Sopenharmony_ciOpSource GLSL 440
5233fd4e5da5Sopenharmony_ciOpName %main "main"
5234fd4e5da5Sopenharmony_ciOpName %local1 "local1"
5235fd4e5da5Sopenharmony_ciOpName %local2 "local2"
5236fd4e5da5Sopenharmony_ciOpName %global "global"
5237fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5238fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
5239fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5240fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
5241fd4e5da5Sopenharmony_ci%12 = OpConstantNull %v4float
5242fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
5243fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
5244fd4e5da5Sopenharmony_ci%global = OpVariable %_ptr_Output_v4float Output
5245fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
5246fd4e5da5Sopenharmony_ci%19 = OpLabel
5247fd4e5da5Sopenharmony_ci%local1 = OpVariable %_ptr_Function_v4float Function
5248fd4e5da5Sopenharmony_ci%local2 = OpVariable %_ptr_Function_v4float Function
5249fd4e5da5Sopenharmony_ciOpStore %local1 %12
5250fd4e5da5Sopenharmony_ciOpCopyMemory %local2 %local1
5251fd4e5da5Sopenharmony_ciOpCopyMemory %global %local2
5252fd4e5da5Sopenharmony_ciOpEndPrimitive
5253fd4e5da5Sopenharmony_ciOpReturn
5254fd4e5da5Sopenharmony_ciOpFunctionEnd
5255fd4e5da5Sopenharmony_ci)";
5256fd4e5da5Sopenharmony_ci
5257fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5258fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(test, test, true, true);
5259fd4e5da5Sopenharmony_ci}
5260fd4e5da5Sopenharmony_ci
5261fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, RemoveCopyMemoryToLocal) {
5262fd4e5da5Sopenharmony_ci  // Test that we remove function scope variables that are stored to using
5263fd4e5da5Sopenharmony_ci  // OpCopyMemory, but are never loaded.  We can remove both |local1| and
5264fd4e5da5Sopenharmony_ci  // |local2|.
5265fd4e5da5Sopenharmony_ci  const std::string test =
5266fd4e5da5Sopenharmony_ci      R"(OpCapability Geometry
5267fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5268fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5269fd4e5da5Sopenharmony_ciOpEntryPoint Geometry %main "main" %global
5270fd4e5da5Sopenharmony_ciOpExecutionMode %main Triangles
5271fd4e5da5Sopenharmony_ciOpExecutionMode %main Invocations 1
5272fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputTriangleStrip
5273fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputVertices 5
5274fd4e5da5Sopenharmony_ciOpSource GLSL 440
5275fd4e5da5Sopenharmony_ciOpName %main "main"
5276fd4e5da5Sopenharmony_ciOpName %local1 "local1"
5277fd4e5da5Sopenharmony_ciOpName %local2 "local2"
5278fd4e5da5Sopenharmony_ciOpName %global "global"
5279fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5280fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
5281fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5282fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
5283fd4e5da5Sopenharmony_ci%12 = OpConstantNull %v4float
5284fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
5285fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
5286fd4e5da5Sopenharmony_ci%global = OpVariable %_ptr_Output_v4float Output
5287fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
5288fd4e5da5Sopenharmony_ci%19 = OpLabel
5289fd4e5da5Sopenharmony_ci%local1 = OpVariable %_ptr_Function_v4float Function
5290fd4e5da5Sopenharmony_ci%local2 = OpVariable %_ptr_Function_v4float Function
5291fd4e5da5Sopenharmony_ciOpStore %local1 %12
5292fd4e5da5Sopenharmony_ciOpCopyMemory %local2 %local1
5293fd4e5da5Sopenharmony_ciOpEndPrimitive
5294fd4e5da5Sopenharmony_ciOpReturn
5295fd4e5da5Sopenharmony_ciOpFunctionEnd
5296fd4e5da5Sopenharmony_ci)";
5297fd4e5da5Sopenharmony_ci
5298fd4e5da5Sopenharmony_ci  const std::string result =
5299fd4e5da5Sopenharmony_ci      R"(OpCapability Geometry
5300fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5301fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5302fd4e5da5Sopenharmony_ciOpEntryPoint Geometry %main "main" %global
5303fd4e5da5Sopenharmony_ciOpExecutionMode %main Triangles
5304fd4e5da5Sopenharmony_ciOpExecutionMode %main Invocations 1
5305fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputTriangleStrip
5306fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputVertices 5
5307fd4e5da5Sopenharmony_ciOpSource GLSL 440
5308fd4e5da5Sopenharmony_ciOpName %main "main"
5309fd4e5da5Sopenharmony_ciOpName %global "global"
5310fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5311fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
5312fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5313fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
5314fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
5315fd4e5da5Sopenharmony_ci%global = OpVariable %_ptr_Output_v4float Output
5316fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
5317fd4e5da5Sopenharmony_ci%19 = OpLabel
5318fd4e5da5Sopenharmony_ciOpEndPrimitive
5319fd4e5da5Sopenharmony_ciOpReturn
5320fd4e5da5Sopenharmony_ciOpFunctionEnd
5321fd4e5da5Sopenharmony_ci)";
5322fd4e5da5Sopenharmony_ci
5323fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5324fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(test, result, true, true);
5325fd4e5da5Sopenharmony_ci}
5326fd4e5da5Sopenharmony_ci
5327fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, RemoveCopyMemoryToLocal2) {
5328fd4e5da5Sopenharmony_ci  // We are able to remove "local2" because it is not loaded, but have to keep
5329fd4e5da5Sopenharmony_ci  // the stores to "local1".
5330fd4e5da5Sopenharmony_ci  const std::string test =
5331fd4e5da5Sopenharmony_ci      R"(OpCapability Geometry
5332fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5333fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5334fd4e5da5Sopenharmony_ciOpEntryPoint Geometry %main "main" %global
5335fd4e5da5Sopenharmony_ciOpExecutionMode %main Triangles
5336fd4e5da5Sopenharmony_ciOpExecutionMode %main Invocations 1
5337fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputTriangleStrip
5338fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputVertices 5
5339fd4e5da5Sopenharmony_ciOpSource GLSL 440
5340fd4e5da5Sopenharmony_ciOpName %main "main"
5341fd4e5da5Sopenharmony_ciOpName %local1 "local1"
5342fd4e5da5Sopenharmony_ciOpName %local2 "local2"
5343fd4e5da5Sopenharmony_ciOpName %global "global"
5344fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5345fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
5346fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5347fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
5348fd4e5da5Sopenharmony_ci%12 = OpConstantNull %v4float
5349fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
5350fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
5351fd4e5da5Sopenharmony_ci%global = OpVariable %_ptr_Output_v4float Output
5352fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
5353fd4e5da5Sopenharmony_ci%19 = OpLabel
5354fd4e5da5Sopenharmony_ci%local1 = OpVariable %_ptr_Function_v4float Function
5355fd4e5da5Sopenharmony_ci%local2 = OpVariable %_ptr_Function_v4float Function
5356fd4e5da5Sopenharmony_ciOpStore %local1 %12
5357fd4e5da5Sopenharmony_ciOpCopyMemory %local2 %local1
5358fd4e5da5Sopenharmony_ciOpCopyMemory %global %local1
5359fd4e5da5Sopenharmony_ciOpEndPrimitive
5360fd4e5da5Sopenharmony_ciOpReturn
5361fd4e5da5Sopenharmony_ciOpFunctionEnd
5362fd4e5da5Sopenharmony_ci)";
5363fd4e5da5Sopenharmony_ci
5364fd4e5da5Sopenharmony_ci  const std::string result =
5365fd4e5da5Sopenharmony_ci      R"(OpCapability Geometry
5366fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5367fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5368fd4e5da5Sopenharmony_ciOpEntryPoint Geometry %main "main" %global
5369fd4e5da5Sopenharmony_ciOpExecutionMode %main Triangles
5370fd4e5da5Sopenharmony_ciOpExecutionMode %main Invocations 1
5371fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputTriangleStrip
5372fd4e5da5Sopenharmony_ciOpExecutionMode %main OutputVertices 5
5373fd4e5da5Sopenharmony_ciOpSource GLSL 440
5374fd4e5da5Sopenharmony_ciOpName %main "main"
5375fd4e5da5Sopenharmony_ciOpName %local1 "local1"
5376fd4e5da5Sopenharmony_ciOpName %global "global"
5377fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5378fd4e5da5Sopenharmony_ci%7 = OpTypeFunction %void
5379fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5380fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
5381fd4e5da5Sopenharmony_ci%12 = OpConstantNull %v4float
5382fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
5383fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
5384fd4e5da5Sopenharmony_ci%global = OpVariable %_ptr_Output_v4float Output
5385fd4e5da5Sopenharmony_ci%main = OpFunction %void None %7
5386fd4e5da5Sopenharmony_ci%19 = OpLabel
5387fd4e5da5Sopenharmony_ci%local1 = OpVariable %_ptr_Function_v4float Function
5388fd4e5da5Sopenharmony_ciOpStore %local1 %12
5389fd4e5da5Sopenharmony_ciOpCopyMemory %global %local1
5390fd4e5da5Sopenharmony_ciOpEndPrimitive
5391fd4e5da5Sopenharmony_ciOpReturn
5392fd4e5da5Sopenharmony_ciOpFunctionEnd
5393fd4e5da5Sopenharmony_ci)";
5394fd4e5da5Sopenharmony_ci
5395fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5396fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(test, result, true, true);
5397fd4e5da5Sopenharmony_ci}
5398fd4e5da5Sopenharmony_ci
5399fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, StructuredIfWithConditionalExit) {
5400fd4e5da5Sopenharmony_ci  // We are able to remove "local2" because it is not loaded, but have to keep
5401fd4e5da5Sopenharmony_ci  // the stores to "local1".
5402fd4e5da5Sopenharmony_ci  const std::string test =
5403fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
5404fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5405fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5406fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
5407fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
5408fd4e5da5Sopenharmony_ciOpSource GLSL 140
5409fd4e5da5Sopenharmony_ciOpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
5410fd4e5da5Sopenharmony_ciOpSourceExtension "GL_GOOGLE_include_directive"
5411fd4e5da5Sopenharmony_ciOpName %main "main"
5412fd4e5da5Sopenharmony_ciOpName %a "a"
5413fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5414fd4e5da5Sopenharmony_ci%5 = OpTypeFunction %void
5415fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
5416fd4e5da5Sopenharmony_ci%_ptr_Uniform_int = OpTypePointer Uniform %int
5417fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
5418fd4e5da5Sopenharmony_ci%bool = OpTypeBool
5419fd4e5da5Sopenharmony_ci%int_100 = OpConstant %int 100
5420fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
5421fd4e5da5Sopenharmony_ci%a = OpVariable %_ptr_Uniform_int Uniform
5422fd4e5da5Sopenharmony_ci%main = OpFunction %void None %5
5423fd4e5da5Sopenharmony_ci%12 = OpLabel
5424fd4e5da5Sopenharmony_ci%13 = OpLoad %int %a
5425fd4e5da5Sopenharmony_ci%14 = OpSGreaterThan %bool %13 %int_0
5426fd4e5da5Sopenharmony_ciOpSelectionMerge %15 None
5427fd4e5da5Sopenharmony_ciOpBranchConditional %14 %16 %15
5428fd4e5da5Sopenharmony_ci%16 = OpLabel
5429fd4e5da5Sopenharmony_ci%17 = OpLoad %int %a
5430fd4e5da5Sopenharmony_ci%18 = OpSLessThan %bool %17 %int_100
5431fd4e5da5Sopenharmony_ciOpBranchConditional %18 %19 %15
5432fd4e5da5Sopenharmony_ci%19 = OpLabel
5433fd4e5da5Sopenharmony_ciOpStore %a %int_1
5434fd4e5da5Sopenharmony_ciOpBranch %15
5435fd4e5da5Sopenharmony_ci%15 = OpLabel
5436fd4e5da5Sopenharmony_ciOpReturn
5437fd4e5da5Sopenharmony_ciOpFunctionEnd
5438fd4e5da5Sopenharmony_ci)";
5439fd4e5da5Sopenharmony_ci
5440fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5441fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(test, test, true, true);
5442fd4e5da5Sopenharmony_ci}
5443fd4e5da5Sopenharmony_ci
5444fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, CountingLoopNotEliminated) {
5445fd4e5da5Sopenharmony_ci  // #version 310 es
5446fd4e5da5Sopenharmony_ci  //
5447fd4e5da5Sopenharmony_ci  // precision highp float;
5448fd4e5da5Sopenharmony_ci  // precision highp int;
5449fd4e5da5Sopenharmony_ci  //
5450fd4e5da5Sopenharmony_ci  // layout(location = 0) out vec4 _GLF_color;
5451fd4e5da5Sopenharmony_ci  //
5452fd4e5da5Sopenharmony_ci  // void main()
5453fd4e5da5Sopenharmony_ci  // {
5454fd4e5da5Sopenharmony_ci  //   float data[1];
5455fd4e5da5Sopenharmony_ci  //   for (int c = 0; c < 1; c++) {
5456fd4e5da5Sopenharmony_ci  //     if (true) {
5457fd4e5da5Sopenharmony_ci  //       do {
5458fd4e5da5Sopenharmony_ci  //         for (int i = 0; i < 1; i++) {
5459fd4e5da5Sopenharmony_ci  //           data[i] = 1.0;
5460fd4e5da5Sopenharmony_ci  //         }
5461fd4e5da5Sopenharmony_ci  //       } while (false);
5462fd4e5da5Sopenharmony_ci  //     }
5463fd4e5da5Sopenharmony_ci  //   }
5464fd4e5da5Sopenharmony_ci  //   _GLF_color = vec4(data[0], 0.0, 0.0, 1.0);
5465fd4e5da5Sopenharmony_ci  // }
5466fd4e5da5Sopenharmony_ci  const std::string test =
5467fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
5468fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5469fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5470fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %_GLF_color
5471fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
5472fd4e5da5Sopenharmony_ciOpSource ESSL 310
5473fd4e5da5Sopenharmony_ciOpName %main "main"
5474fd4e5da5Sopenharmony_ciOpName %c "c"
5475fd4e5da5Sopenharmony_ciOpName %i "i"
5476fd4e5da5Sopenharmony_ciOpName %data "data"
5477fd4e5da5Sopenharmony_ciOpName %_GLF_color "_GLF_color"
5478fd4e5da5Sopenharmony_ciOpDecorate %_GLF_color Location 0
5479fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5480fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
5481fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
5482fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
5483fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
5484fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
5485fd4e5da5Sopenharmony_ci%bool = OpTypeBool
5486fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5487fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
5488fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
5489fd4e5da5Sopenharmony_ci%_arr_float_uint_1 = OpTypeArray %float %uint_1
5490fd4e5da5Sopenharmony_ci%_ptr_Function__arr_float_uint_1 = OpTypePointer Function %_arr_float_uint_1
5491fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
5492fd4e5da5Sopenharmony_ci%_ptr_Function_float = OpTypePointer Function %float
5493fd4e5da5Sopenharmony_ci%false = OpConstantFalse %bool
5494fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
5495fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
5496fd4e5da5Sopenharmony_ci%_GLF_color = OpVariable %_ptr_Output_v4float Output
5497fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
5498fd4e5da5Sopenharmony_ci%main = OpFunction %void None %8
5499fd4e5da5Sopenharmony_ci%26 = OpLabel
5500fd4e5da5Sopenharmony_ci%c = OpVariable %_ptr_Function_int Function
5501fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
5502fd4e5da5Sopenharmony_ci%data = OpVariable %_ptr_Function__arr_float_uint_1 Function
5503fd4e5da5Sopenharmony_ciOpStore %c %int_0
5504fd4e5da5Sopenharmony_ciOpBranch %27
5505fd4e5da5Sopenharmony_ci%27 = OpLabel
5506fd4e5da5Sopenharmony_ciOpLoopMerge %28 %29 None
5507fd4e5da5Sopenharmony_ciOpBranch %30
5508fd4e5da5Sopenharmony_ci%30 = OpLabel
5509fd4e5da5Sopenharmony_ci%31 = OpLoad %int %c
5510fd4e5da5Sopenharmony_ci%32 = OpSLessThan %bool %31 %int_1
5511fd4e5da5Sopenharmony_ciOpBranchConditional %32 %33 %28
5512fd4e5da5Sopenharmony_ci%33 = OpLabel
5513fd4e5da5Sopenharmony_ciOpBranch %34
5514fd4e5da5Sopenharmony_ci%34 = OpLabel
5515fd4e5da5Sopenharmony_ciOpBranch %35
5516fd4e5da5Sopenharmony_ci%35 = OpLabel
5517fd4e5da5Sopenharmony_ciOpLoopMerge %36 %37 None
5518fd4e5da5Sopenharmony_ciOpBranch %38
5519fd4e5da5Sopenharmony_ci%38 = OpLabel
5520fd4e5da5Sopenharmony_ciOpStore %i %int_0
5521fd4e5da5Sopenharmony_ciOpBranch %39
5522fd4e5da5Sopenharmony_ci%39 = OpLabel
5523fd4e5da5Sopenharmony_ciOpLoopMerge %40 %41 None
5524fd4e5da5Sopenharmony_ciOpBranch %42
5525fd4e5da5Sopenharmony_ci%42 = OpLabel
5526fd4e5da5Sopenharmony_ci%43 = OpLoad %int %i
5527fd4e5da5Sopenharmony_ci%44 = OpSLessThan %bool %43 %int_1
5528fd4e5da5Sopenharmony_ciOpBranchConditional %44 %46 %40
5529fd4e5da5Sopenharmony_ci%46 = OpLabel
5530fd4e5da5Sopenharmony_ci%47 = OpLoad %int %i
5531fd4e5da5Sopenharmony_ci%48 = OpAccessChain %_ptr_Function_float %data %47
5532fd4e5da5Sopenharmony_ciOpStore %48 %float_1
5533fd4e5da5Sopenharmony_ciOpBranch %41
5534fd4e5da5Sopenharmony_ci%41 = OpLabel
5535fd4e5da5Sopenharmony_ci%49 = OpLoad %int %i
5536fd4e5da5Sopenharmony_ci%50 = OpIAdd %int %49 %int_1
5537fd4e5da5Sopenharmony_ciOpStore %i %50
5538fd4e5da5Sopenharmony_ciOpBranch %39
5539fd4e5da5Sopenharmony_ci%40 = OpLabel
5540fd4e5da5Sopenharmony_ciOpBranch %37
5541fd4e5da5Sopenharmony_ci%37 = OpLabel
5542fd4e5da5Sopenharmony_ciOpBranchConditional %false %35 %36
5543fd4e5da5Sopenharmony_ci%36 = OpLabel
5544fd4e5da5Sopenharmony_ciOpBranch %45
5545fd4e5da5Sopenharmony_ci%45 = OpLabel
5546fd4e5da5Sopenharmony_ciOpBranch %29
5547fd4e5da5Sopenharmony_ci%29 = OpLabel
5548fd4e5da5Sopenharmony_ci%51 = OpLoad %int %c
5549fd4e5da5Sopenharmony_ci%52 = OpIAdd %int %51 %int_1
5550fd4e5da5Sopenharmony_ciOpStore %c %52
5551fd4e5da5Sopenharmony_ciOpBranch %27
5552fd4e5da5Sopenharmony_ci%28 = OpLabel
5553fd4e5da5Sopenharmony_ci%53 = OpAccessChain %_ptr_Function_float %data %int_0
5554fd4e5da5Sopenharmony_ci%54 = OpLoad %float %53
5555fd4e5da5Sopenharmony_ci%55 = OpCompositeConstruct %v4float %54 %float_0 %float_0 %float_1
5556fd4e5da5Sopenharmony_ciOpStore %_GLF_color %55
5557fd4e5da5Sopenharmony_ciOpReturn
5558fd4e5da5Sopenharmony_ciOpFunctionEnd
5559fd4e5da5Sopenharmony_ci)";
5560fd4e5da5Sopenharmony_ci
5561fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5562fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(test, test, true, true);
5563fd4e5da5Sopenharmony_ci}
5564fd4e5da5Sopenharmony_ci
5565fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EliminateLoopWithUnreachable) {
5566fd4e5da5Sopenharmony_ci  // #version 430
5567fd4e5da5Sopenharmony_ci  //
5568fd4e5da5Sopenharmony_ci  // layout(std430) buffer U_t
5569fd4e5da5Sopenharmony_ci  // {
5570fd4e5da5Sopenharmony_ci  //   float g_F[10];
5571fd4e5da5Sopenharmony_ci  //   float g_S;
5572fd4e5da5Sopenharmony_ci  // };
5573fd4e5da5Sopenharmony_ci  //
5574fd4e5da5Sopenharmony_ci  // layout(location = 0)out float o;
5575fd4e5da5Sopenharmony_ci  //
5576fd4e5da5Sopenharmony_ci  // void main(void)
5577fd4e5da5Sopenharmony_ci  // {
5578fd4e5da5Sopenharmony_ci  //   // Useless loop
5579fd4e5da5Sopenharmony_ci  //   for (int i = 0; i<10; i++) {
5580fd4e5da5Sopenharmony_ci  //     if (g_F[i] == 0.0)
5581fd4e5da5Sopenharmony_ci  //       break;
5582fd4e5da5Sopenharmony_ci  //     else
5583fd4e5da5Sopenharmony_ci  //       break;
5584fd4e5da5Sopenharmony_ci  //     // Unreachable merge block created here.
5585fd4e5da5Sopenharmony_ci  //     // Need to edit SPIR-V to change to OpUnreachable
5586fd4e5da5Sopenharmony_ci  //   }
5587fd4e5da5Sopenharmony_ci  //   o = g_S;
5588fd4e5da5Sopenharmony_ci  // }
5589fd4e5da5Sopenharmony_ci
5590fd4e5da5Sopenharmony_ci  const std::string before =
5591fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
5592fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5593fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5594fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
5595fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
5596fd4e5da5Sopenharmony_ciOpSource GLSL 430
5597fd4e5da5Sopenharmony_ciOpName %main "main"
5598fd4e5da5Sopenharmony_ciOpName %i "i"
5599fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
5600fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_F"
5601fd4e5da5Sopenharmony_ciOpMemberName %U_t 1 "g_S"
5602fd4e5da5Sopenharmony_ciOpName %_ ""
5603fd4e5da5Sopenharmony_ciOpName %o "o"
5604fd4e5da5Sopenharmony_ciOpDecorate %_arr_float_uint_10 ArrayStride 4
5605fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 0 Offset 0
5606fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 1 Offset 40
5607fd4e5da5Sopenharmony_ciOpDecorate %U_t BufferBlock
5608fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
5609fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
5610fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5611fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
5612fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
5613fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
5614fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
5615fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
5616fd4e5da5Sopenharmony_ci%bool = OpTypeBool
5617fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5618fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
5619fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
5620fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10
5621fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %_arr_float_uint_10 %float
5622fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
5623fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
5624fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
5625fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
5626fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
5627fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
5628fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
5629fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
5630fd4e5da5Sopenharmony_ci%23 = OpLabel
5631fd4e5da5Sopenharmony_ci%i = OpVariable %_ptr_Function_int Function
5632fd4e5da5Sopenharmony_ciOpStore %i %int_0
5633fd4e5da5Sopenharmony_ciOpBranch %24
5634fd4e5da5Sopenharmony_ci%24 = OpLabel
5635fd4e5da5Sopenharmony_ciOpLoopMerge %25 %26 None
5636fd4e5da5Sopenharmony_ciOpBranch %27
5637fd4e5da5Sopenharmony_ci%27 = OpLabel
5638fd4e5da5Sopenharmony_ci%28 = OpLoad %int %i
5639fd4e5da5Sopenharmony_ci%29 = OpSLessThan %bool %28 %int_10
5640fd4e5da5Sopenharmony_ciOpBranchConditional %29 %30 %25
5641fd4e5da5Sopenharmony_ci%30 = OpLabel
5642fd4e5da5Sopenharmony_ci%31 = OpLoad %int %i
5643fd4e5da5Sopenharmony_ci%32 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %31
5644fd4e5da5Sopenharmony_ci%33 = OpLoad %float %32
5645fd4e5da5Sopenharmony_ci%34 = OpFOrdEqual %bool %33 %float_0
5646fd4e5da5Sopenharmony_ciOpSelectionMerge %35 None
5647fd4e5da5Sopenharmony_ciOpBranchConditional %34 %36 %37
5648fd4e5da5Sopenharmony_ci%36 = OpLabel
5649fd4e5da5Sopenharmony_ciOpBranch %25
5650fd4e5da5Sopenharmony_ci%37 = OpLabel
5651fd4e5da5Sopenharmony_ciOpBranch %25
5652fd4e5da5Sopenharmony_ci%35 = OpLabel
5653fd4e5da5Sopenharmony_ciOpUnreachable
5654fd4e5da5Sopenharmony_ci%26 = OpLabel
5655fd4e5da5Sopenharmony_ci%38 = OpLoad %int %i
5656fd4e5da5Sopenharmony_ci%39 = OpIAdd %int %38 %int_1
5657fd4e5da5Sopenharmony_ciOpStore %i %39
5658fd4e5da5Sopenharmony_ciOpBranch %24
5659fd4e5da5Sopenharmony_ci%25 = OpLabel
5660fd4e5da5Sopenharmony_ci%40 = OpAccessChain %_ptr_Uniform_float %_ %int_1
5661fd4e5da5Sopenharmony_ci%41 = OpLoad %float %40
5662fd4e5da5Sopenharmony_ciOpStore %o %41
5663fd4e5da5Sopenharmony_ciOpReturn
5664fd4e5da5Sopenharmony_ciOpFunctionEnd
5665fd4e5da5Sopenharmony_ci)";
5666fd4e5da5Sopenharmony_ci
5667fd4e5da5Sopenharmony_ci  const std::string after =
5668fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
5669fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5670fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5671fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main" %o
5672fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
5673fd4e5da5Sopenharmony_ciOpSource GLSL 430
5674fd4e5da5Sopenharmony_ciOpName %main "main"
5675fd4e5da5Sopenharmony_ciOpName %U_t "U_t"
5676fd4e5da5Sopenharmony_ciOpMemberName %U_t 0 "g_F"
5677fd4e5da5Sopenharmony_ciOpMemberName %U_t 1 "g_S"
5678fd4e5da5Sopenharmony_ciOpName %_ ""
5679fd4e5da5Sopenharmony_ciOpName %o "o"
5680fd4e5da5Sopenharmony_ciOpDecorate %_arr_float_uint_10 ArrayStride 4
5681fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 0 Offset 0
5682fd4e5da5Sopenharmony_ciOpMemberDecorate %U_t 1 Offset 40
5683fd4e5da5Sopenharmony_ciOpDecorate %U_t BufferBlock
5684fd4e5da5Sopenharmony_ciOpDecorate %_ DescriptorSet 0
5685fd4e5da5Sopenharmony_ciOpDecorate %o Location 0
5686fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5687fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
5688fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
5689fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
5690fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
5691fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
5692fd4e5da5Sopenharmony_ci%_arr_float_uint_10 = OpTypeArray %float %uint_10
5693fd4e5da5Sopenharmony_ci%U_t = OpTypeStruct %_arr_float_uint_10 %float
5694fd4e5da5Sopenharmony_ci%_ptr_Uniform_U_t = OpTypePointer Uniform %U_t
5695fd4e5da5Sopenharmony_ci%_ = OpVariable %_ptr_Uniform_U_t Uniform
5696fd4e5da5Sopenharmony_ci%_ptr_Uniform_float = OpTypePointer Uniform %float
5697fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
5698fd4e5da5Sopenharmony_ci%_ptr_Output_float = OpTypePointer Output %float
5699fd4e5da5Sopenharmony_ci%o = OpVariable %_ptr_Output_float Output
5700fd4e5da5Sopenharmony_ci%main = OpFunction %void None %9
5701fd4e5da5Sopenharmony_ci%23 = OpLabel
5702fd4e5da5Sopenharmony_ciOpBranch %24
5703fd4e5da5Sopenharmony_ci%24 = OpLabel
5704fd4e5da5Sopenharmony_ciOpBranch %25
5705fd4e5da5Sopenharmony_ci%25 = OpLabel
5706fd4e5da5Sopenharmony_ci%40 = OpAccessChain %_ptr_Uniform_float %_ %int_1
5707fd4e5da5Sopenharmony_ci%41 = OpLoad %float %40
5708fd4e5da5Sopenharmony_ciOpStore %o %41
5709fd4e5da5Sopenharmony_ciOpReturn
5710fd4e5da5Sopenharmony_ciOpFunctionEnd
5711fd4e5da5Sopenharmony_ci)";
5712fd4e5da5Sopenharmony_ci
5713fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5714fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(before, after, true, true);
5715fd4e5da5Sopenharmony_ci}
5716fd4e5da5Sopenharmony_ci
5717fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DeadHlslCounterBufferGOOGLE) {
5718fd4e5da5Sopenharmony_ci  // We are able to remove "local2" because it is not loaded, but have to keep
5719fd4e5da5Sopenharmony_ci  // the stores to "local1".
5720fd4e5da5Sopenharmony_ci  const std::string test =
5721fd4e5da5Sopenharmony_ci      R"(
5722fd4e5da5Sopenharmony_ci; CHECK-NOT: OpDecorateId
5723fd4e5da5Sopenharmony_ci; CHECK: [[var:%\w+]] = OpVariable
5724fd4e5da5Sopenharmony_ci; CHECK-NOT: OpVariable
5725fd4e5da5Sopenharmony_ci; CHECK: [[ac:%\w+]] = OpAccessChain {{%\w+}} [[var]]
5726fd4e5da5Sopenharmony_ci; CHECK: OpStore [[ac]]
5727fd4e5da5Sopenharmony_ci               OpCapability Shader
5728fd4e5da5Sopenharmony_ci               OpExtension "SPV_GOOGLE_hlsl_functionality1"
5729fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
5730fd4e5da5Sopenharmony_ci               OpEntryPoint GLCompute %1 "main"
5731fd4e5da5Sopenharmony_ci               OpExecutionMode %1 LocalSize 32 1 1
5732fd4e5da5Sopenharmony_ci               OpSource HLSL 600
5733fd4e5da5Sopenharmony_ci               OpDecorate %_runtimearr_v2float ArrayStride 8
5734fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_3 0 Offset 0
5735fd4e5da5Sopenharmony_ci               OpDecorate %_struct_3 BufferBlock
5736fd4e5da5Sopenharmony_ci               OpMemberDecorate %_struct_4 0 Offset 0
5737fd4e5da5Sopenharmony_ci               OpDecorate %_struct_4 BufferBlock
5738fd4e5da5Sopenharmony_ci               OpDecorateId %5 HlslCounterBufferGOOGLE %6
5739fd4e5da5Sopenharmony_ci               OpDecorate %5 DescriptorSet 0
5740fd4e5da5Sopenharmony_ci               OpDecorate %5 Binding 0
5741fd4e5da5Sopenharmony_ci               OpDecorate %6 DescriptorSet 0
5742fd4e5da5Sopenharmony_ci               OpDecorate %6 Binding 1
5743fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
5744fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
5745fd4e5da5Sopenharmony_ci%_runtimearr_v2float = OpTypeRuntimeArray %v2float
5746fd4e5da5Sopenharmony_ci  %_struct_3 = OpTypeStruct %_runtimearr_v2float
5747fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_3 = OpTypePointer Uniform %_struct_3
5748fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
5749fd4e5da5Sopenharmony_ci  %_struct_4 = OpTypeStruct %int
5750fd4e5da5Sopenharmony_ci%_ptr_Uniform__struct_4 = OpTypePointer Uniform %_struct_4
5751fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
5752fd4e5da5Sopenharmony_ci         %13 = OpTypeFunction %void
5753fd4e5da5Sopenharmony_ci         %19 = OpConstantNull %v2float
5754fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
5755fd4e5da5Sopenharmony_ci%_ptr_Uniform_v2float = OpTypePointer Uniform %v2float
5756fd4e5da5Sopenharmony_ci          %5 = OpVariable %_ptr_Uniform__struct_3 Uniform
5757fd4e5da5Sopenharmony_ci          %6 = OpVariable %_ptr_Uniform__struct_4 Uniform
5758fd4e5da5Sopenharmony_ci          %1 = OpFunction %void None %13
5759fd4e5da5Sopenharmony_ci         %22 = OpLabel
5760fd4e5da5Sopenharmony_ci         %23 = OpAccessChain %_ptr_Uniform_v2float %5 %int_0 %int_0
5761fd4e5da5Sopenharmony_ci               OpStore %23 %19
5762fd4e5da5Sopenharmony_ci               OpReturn
5763fd4e5da5Sopenharmony_ci               OpFunctionEnd
5764fd4e5da5Sopenharmony_ci)";
5765fd4e5da5Sopenharmony_ci
5766fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5767fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(test, true);
5768fd4e5da5Sopenharmony_ci}
5769fd4e5da5Sopenharmony_ci
5770fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, Dead) {
5771fd4e5da5Sopenharmony_ci  // We are able to remove "local2" because it is not loaded, but have to keep
5772fd4e5da5Sopenharmony_ci  // the stores to "local1".
5773fd4e5da5Sopenharmony_ci  const std::string test =
5774fd4e5da5Sopenharmony_ci      R"(
5775fd4e5da5Sopenharmony_ci; CHECK: OpCapability
5776fd4e5da5Sopenharmony_ci; CHECK-NOT: OpMemberDecorateStringGOOGLE
5777fd4e5da5Sopenharmony_ci; CHECK: OpFunctionEnd
5778fd4e5da5Sopenharmony_ci           OpCapability Shader
5779fd4e5da5Sopenharmony_ci           OpExtension "SPV_GOOGLE_hlsl_functionality1"
5780fd4e5da5Sopenharmony_ci      %1 = OpExtInstImport "GLSL.std.450"
5781fd4e5da5Sopenharmony_ci           OpMemoryModel Logical GLSL450
5782fd4e5da5Sopenharmony_ci           OpEntryPoint Vertex %VSMain "VSMain"
5783fd4e5da5Sopenharmony_ci           OpSource HLSL 500
5784fd4e5da5Sopenharmony_ci           OpName %VSMain "VSMain"
5785fd4e5da5Sopenharmony_ci           OpName %PSInput "PSInput"
5786fd4e5da5Sopenharmony_ci           OpMemberName %PSInput 0 "Pos"
5787fd4e5da5Sopenharmony_ci           OpMemberName %PSInput 1 "uv"
5788fd4e5da5Sopenharmony_ci           OpMemberDecorateStringGOOGLE %PSInput 0 HlslSemanticGOOGLE "SV_POSITION"
5789fd4e5da5Sopenharmony_ci           OpMemberDecorateStringGOOGLE %PSInput 1 HlslSemanticGOOGLE "TEX_COORD"
5790fd4e5da5Sopenharmony_ci   %void = OpTypeVoid
5791fd4e5da5Sopenharmony_ci      %5 = OpTypeFunction %void
5792fd4e5da5Sopenharmony_ci  %float = OpTypeFloat 32
5793fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
5794fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
5795fd4e5da5Sopenharmony_ci%PSInput = OpTypeStruct %v4float %v2float
5796fd4e5da5Sopenharmony_ci %VSMain = OpFunction %void None %5
5797fd4e5da5Sopenharmony_ci      %9 = OpLabel
5798fd4e5da5Sopenharmony_ci           OpReturn
5799fd4e5da5Sopenharmony_ci           OpFunctionEnd
5800fd4e5da5Sopenharmony_ci)";
5801fd4e5da5Sopenharmony_ci
5802fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5803fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(test, true);
5804fd4e5da5Sopenharmony_ci}
5805fd4e5da5Sopenharmony_ci
5806fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DeadInfiniteLoop) {
5807fd4e5da5Sopenharmony_ci  const std::string test = R"(
5808fd4e5da5Sopenharmony_ci; CHECK: OpSwitch {{%\w+}} {{%\w+}} {{\w+}} {{%\w+}} {{\w+}} [[block:%\w+]]
5809fd4e5da5Sopenharmony_ci; CHECK: [[block]] = OpLabel
5810fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[block:%\w+]]
5811fd4e5da5Sopenharmony_ci; CHECK: [[block]] = OpLabel
5812fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[block:%\w+]]
5813fd4e5da5Sopenharmony_ci; CHECK: [[block]] = OpLabel
5814fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpReturn
5815fd4e5da5Sopenharmony_ci               OpCapability Shader
5816fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
5817fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %2 "main"
5818fd4e5da5Sopenharmony_ci               OpExecutionMode %2 OriginUpperLeft
5819fd4e5da5Sopenharmony_ci          %6 = OpTypeVoid
5820fd4e5da5Sopenharmony_ci          %7 = OpTypeFunction %6
5821fd4e5da5Sopenharmony_ci          %8 = OpTypeFloat 32
5822fd4e5da5Sopenharmony_ci          %9 = OpTypeVector %8 3
5823fd4e5da5Sopenharmony_ci         %10 = OpTypeFunction %9
5824fd4e5da5Sopenharmony_ci         %11 = OpConstant %8 1
5825fd4e5da5Sopenharmony_ci         %12 = OpConstantComposite %9 %11 %11 %11
5826fd4e5da5Sopenharmony_ci         %13 = OpTypeInt 32 1
5827fd4e5da5Sopenharmony_ci         %32 = OpUndef %13
5828fd4e5da5Sopenharmony_ci          %2 = OpFunction %6 None %7
5829fd4e5da5Sopenharmony_ci         %33 = OpLabel
5830fd4e5da5Sopenharmony_ci               OpBranch %34
5831fd4e5da5Sopenharmony_ci         %34 = OpLabel
5832fd4e5da5Sopenharmony_ci               OpLoopMerge %35 %36 None
5833fd4e5da5Sopenharmony_ci               OpBranch %37
5834fd4e5da5Sopenharmony_ci         %37 = OpLabel
5835fd4e5da5Sopenharmony_ci         %38 = OpFunctionCall %9 %39
5836fd4e5da5Sopenharmony_ci               OpSelectionMerge %40 None
5837fd4e5da5Sopenharmony_ci               OpSwitch %32 %40 14 %41 58 %42
5838fd4e5da5Sopenharmony_ci         %42 = OpLabel
5839fd4e5da5Sopenharmony_ci               OpBranch %43
5840fd4e5da5Sopenharmony_ci         %43 = OpLabel
5841fd4e5da5Sopenharmony_ci               OpLoopMerge %44 %45 None
5842fd4e5da5Sopenharmony_ci               OpBranch %45
5843fd4e5da5Sopenharmony_ci         %45 = OpLabel
5844fd4e5da5Sopenharmony_ci               OpBranch %43
5845fd4e5da5Sopenharmony_ci         %44 = OpLabel
5846fd4e5da5Sopenharmony_ci               OpUnreachable
5847fd4e5da5Sopenharmony_ci         %41 = OpLabel
5848fd4e5da5Sopenharmony_ci               OpBranch %36
5849fd4e5da5Sopenharmony_ci         %40 = OpLabel
5850fd4e5da5Sopenharmony_ci               OpBranch %36
5851fd4e5da5Sopenharmony_ci         %36 = OpLabel
5852fd4e5da5Sopenharmony_ci               OpBranch %34
5853fd4e5da5Sopenharmony_ci         %35 = OpLabel
5854fd4e5da5Sopenharmony_ci               OpReturn
5855fd4e5da5Sopenharmony_ci               OpFunctionEnd
5856fd4e5da5Sopenharmony_ci         %39 = OpFunction %9 None %10
5857fd4e5da5Sopenharmony_ci         %46 = OpLabel
5858fd4e5da5Sopenharmony_ci               OpReturnValue %12
5859fd4e5da5Sopenharmony_ci               OpFunctionEnd
5860fd4e5da5Sopenharmony_ci)";
5861fd4e5da5Sopenharmony_ci
5862fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5863fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(test, true);
5864fd4e5da5Sopenharmony_ci}
5865fd4e5da5Sopenharmony_ci
5866fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DeadInfiniteLoopReturnValue) {
5867fd4e5da5Sopenharmony_ci  const std::string test = R"(
5868fd4e5da5Sopenharmony_ci; CHECK: [[vec3:%\w+]] = OpTypeVector
5869fd4e5da5Sopenharmony_ci; CHECK: [[undef:%\w+]] = OpUndef [[vec3]]
5870fd4e5da5Sopenharmony_ci; CHECK: OpSwitch {{%\w+}} {{%\w+}} {{\w+}} {{%\w+}} {{\w+}} [[block:%\w+]]
5871fd4e5da5Sopenharmony_ci; CHECK: [[block]] = OpLabel
5872fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[block:%\w+]]
5873fd4e5da5Sopenharmony_ci; CHECK: [[block]] = OpLabel
5874fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[block:%\w+]]
5875fd4e5da5Sopenharmony_ci; CHECK: [[block]] = OpLabel
5876fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpReturnValue [[undef]]
5877fd4e5da5Sopenharmony_ci               OpCapability Shader
5878fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
5879fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %2 "main"
5880fd4e5da5Sopenharmony_ci               OpExecutionMode %2 OriginUpperLeft
5881fd4e5da5Sopenharmony_ci          %6 = OpTypeVoid
5882fd4e5da5Sopenharmony_ci          %7 = OpTypeFunction %6
5883fd4e5da5Sopenharmony_ci          %8 = OpTypeFloat 32
5884fd4e5da5Sopenharmony_ci          %9 = OpTypeVector %8 3
5885fd4e5da5Sopenharmony_ci         %10 = OpTypeFunction %9
5886fd4e5da5Sopenharmony_ci         %11 = OpConstant %8 1
5887fd4e5da5Sopenharmony_ci         %12 = OpConstantComposite %9 %11 %11 %11
5888fd4e5da5Sopenharmony_ci         %13 = OpTypeInt 32 1
5889fd4e5da5Sopenharmony_ci         %32 = OpUndef %13
5890fd4e5da5Sopenharmony_ci          %2 = OpFunction %6 None %7
5891fd4e5da5Sopenharmony_ci      %entry = OpLabel
5892fd4e5da5Sopenharmony_ci       %call = OpFunctionCall %9 %func
5893fd4e5da5Sopenharmony_ci               OpReturn
5894fd4e5da5Sopenharmony_ci               OpFunctionEnd
5895fd4e5da5Sopenharmony_ci       %func = OpFunction %9 None %10
5896fd4e5da5Sopenharmony_ci         %33 = OpLabel
5897fd4e5da5Sopenharmony_ci               OpBranch %34
5898fd4e5da5Sopenharmony_ci         %34 = OpLabel
5899fd4e5da5Sopenharmony_ci               OpLoopMerge %35 %36 None
5900fd4e5da5Sopenharmony_ci               OpBranch %37
5901fd4e5da5Sopenharmony_ci         %37 = OpLabel
5902fd4e5da5Sopenharmony_ci         %38 = OpFunctionCall %9 %39
5903fd4e5da5Sopenharmony_ci               OpSelectionMerge %40 None
5904fd4e5da5Sopenharmony_ci               OpSwitch %32 %40 14 %41 58 %42
5905fd4e5da5Sopenharmony_ci         %42 = OpLabel
5906fd4e5da5Sopenharmony_ci               OpBranch %43
5907fd4e5da5Sopenharmony_ci         %43 = OpLabel
5908fd4e5da5Sopenharmony_ci               OpLoopMerge %44 %45 None
5909fd4e5da5Sopenharmony_ci               OpBranch %45
5910fd4e5da5Sopenharmony_ci         %45 = OpLabel
5911fd4e5da5Sopenharmony_ci               OpBranch %43
5912fd4e5da5Sopenharmony_ci         %44 = OpLabel
5913fd4e5da5Sopenharmony_ci               OpUnreachable
5914fd4e5da5Sopenharmony_ci         %41 = OpLabel
5915fd4e5da5Sopenharmony_ci               OpBranch %36
5916fd4e5da5Sopenharmony_ci         %40 = OpLabel
5917fd4e5da5Sopenharmony_ci               OpBranch %36
5918fd4e5da5Sopenharmony_ci         %36 = OpLabel
5919fd4e5da5Sopenharmony_ci               OpBranch %34
5920fd4e5da5Sopenharmony_ci         %35 = OpLabel
5921fd4e5da5Sopenharmony_ci               OpReturnValue %12
5922fd4e5da5Sopenharmony_ci               OpFunctionEnd
5923fd4e5da5Sopenharmony_ci         %39 = OpFunction %9 None %10
5924fd4e5da5Sopenharmony_ci         %46 = OpLabel
5925fd4e5da5Sopenharmony_ci               OpReturnValue %12
5926fd4e5da5Sopenharmony_ci               OpFunctionEnd
5927fd4e5da5Sopenharmony_ci)";
5928fd4e5da5Sopenharmony_ci
5929fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5930fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(test, true);
5931fd4e5da5Sopenharmony_ci}
5932fd4e5da5Sopenharmony_ci
5933fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, TestVariablePointer) {
5934fd4e5da5Sopenharmony_ci  const std::string before =
5935fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
5936fd4e5da5Sopenharmony_ciOpCapability VariablePointers
5937fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
5938fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5939fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %2 "main"
5940fd4e5da5Sopenharmony_ciOpExecutionMode %2 LocalSize 1 1 1
5941fd4e5da5Sopenharmony_ciOpSource GLSL 450
5942fd4e5da5Sopenharmony_ciOpMemberDecorate %_struct_3 0 Offset 0
5943fd4e5da5Sopenharmony_ciOpDecorate %_struct_3 Block
5944fd4e5da5Sopenharmony_ciOpDecorate %4 DescriptorSet 0
5945fd4e5da5Sopenharmony_ciOpDecorate %4 Binding 0
5946fd4e5da5Sopenharmony_ciOpDecorate %_ptr_StorageBuffer_int ArrayStride 4
5947fd4e5da5Sopenharmony_ciOpDecorate %_arr_int_int_128 ArrayStride 4
5948fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5949fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
5950fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
5951fd4e5da5Sopenharmony_ci%int_128 = OpConstant %int 128
5952fd4e5da5Sopenharmony_ci%_arr_int_int_128 = OpTypeArray %int %int_128
5953fd4e5da5Sopenharmony_ci%_struct_3 = OpTypeStruct %_arr_int_int_128
5954fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer__struct_3 = OpTypePointer StorageBuffer %_struct_3
5955fd4e5da5Sopenharmony_ci%4 = OpVariable %_ptr_StorageBuffer__struct_3 StorageBuffer
5956fd4e5da5Sopenharmony_ci%bool = OpTypeBool
5957fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool
5958fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
5959fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
5960fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
5961fd4e5da5Sopenharmony_ci%2 = OpFunction %void None %8
5962fd4e5da5Sopenharmony_ci%16 = OpLabel
5963fd4e5da5Sopenharmony_ci%17 = OpAccessChain %_ptr_StorageBuffer_int %4 %int_0 %int_0
5964fd4e5da5Sopenharmony_ciOpBranch %18
5965fd4e5da5Sopenharmony_ci%18 = OpLabel
5966fd4e5da5Sopenharmony_ci%19 = OpPhi %_ptr_StorageBuffer_int %17 %16 %20 %21
5967fd4e5da5Sopenharmony_ciOpLoopMerge %22 %21 None
5968fd4e5da5Sopenharmony_ciOpBranchConditional %true %23 %22
5969fd4e5da5Sopenharmony_ci%23 = OpLabel
5970fd4e5da5Sopenharmony_ciOpStore %19 %int_0
5971fd4e5da5Sopenharmony_ciOpBranch %21
5972fd4e5da5Sopenharmony_ci%21 = OpLabel
5973fd4e5da5Sopenharmony_ci%20 = OpPtrAccessChain %_ptr_StorageBuffer_int %19 %int_1
5974fd4e5da5Sopenharmony_ciOpBranch %18
5975fd4e5da5Sopenharmony_ci%22 = OpLabel
5976fd4e5da5Sopenharmony_ciOpReturn
5977fd4e5da5Sopenharmony_ciOpFunctionEnd
5978fd4e5da5Sopenharmony_ci)";
5979fd4e5da5Sopenharmony_ci
5980fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5981fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(before, before, true, true);
5982fd4e5da5Sopenharmony_ci}
5983fd4e5da5Sopenharmony_ci
5984fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DeadInputInterfaceV13) {
5985fd4e5da5Sopenharmony_ci  const std::string spirv = R"(
5986fd4e5da5Sopenharmony_ci; CHECK: OpEntryPoint GLCompute %main "main"
5987fd4e5da5Sopenharmony_ci; CHECK-NOT: OpVariable
5988fd4e5da5Sopenharmony_ciOpCapability Shader
5989fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
5990fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main" %dead
5991fd4e5da5Sopenharmony_ciOpExecutionMode %main LocalSize 1 1 1
5992fd4e5da5Sopenharmony_ciOpName %main "main"
5993fd4e5da5Sopenharmony_ci%void = OpTypeVoid
5994fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0
5995fd4e5da5Sopenharmony_ci%ptr_input_int = OpTypePointer Input %int
5996fd4e5da5Sopenharmony_ci%dead = OpVariable %ptr_input_int Input
5997fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void
5998fd4e5da5Sopenharmony_ci%main = OpFunction %void None %void_fn
5999fd4e5da5Sopenharmony_ci%entry = OpLabel
6000fd4e5da5Sopenharmony_ciOpReturn
6001fd4e5da5Sopenharmony_ciOpFunctionEnd
6002fd4e5da5Sopenharmony_ci)";
6003fd4e5da5Sopenharmony_ci
6004fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_3);
6005fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
6006fd4e5da5Sopenharmony_ci}
6007fd4e5da5Sopenharmony_ci
6008fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DeadInputInterfaceV14) {
6009fd4e5da5Sopenharmony_ci  const std::string spirv = R"(
6010fd4e5da5Sopenharmony_ci; CHECK: OpEntryPoint GLCompute %main "main"
6011fd4e5da5Sopenharmony_ci; CHECK-NOT: OpVariable
6012fd4e5da5Sopenharmony_ciOpCapability Shader
6013fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
6014fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main" %dead
6015fd4e5da5Sopenharmony_ciOpExecutionMode %main LocalSize 1 1 1
6016fd4e5da5Sopenharmony_ciOpName %main "main"
6017fd4e5da5Sopenharmony_ci%void = OpTypeVoid
6018fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0
6019fd4e5da5Sopenharmony_ci%ptr_input_int = OpTypePointer Input %int
6020fd4e5da5Sopenharmony_ci%dead = OpVariable %ptr_input_int Input
6021fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void
6022fd4e5da5Sopenharmony_ci%main = OpFunction %void None %void_fn
6023fd4e5da5Sopenharmony_ci%entry = OpLabel
6024fd4e5da5Sopenharmony_ciOpReturn
6025fd4e5da5Sopenharmony_ciOpFunctionEnd
6026fd4e5da5Sopenharmony_ci)";
6027fd4e5da5Sopenharmony_ci
6028fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
6029fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
6030fd4e5da5Sopenharmony_ci}
6031fd4e5da5Sopenharmony_ci
6032fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DeadInterfaceV14) {
6033fd4e5da5Sopenharmony_ci  const std::string spirv = R"(
6034fd4e5da5Sopenharmony_ci; CHECK-NOT: OpEntryPoint GLCompute %main "main" %
6035fd4e5da5Sopenharmony_ci; CHECK: OpEntryPoint GLCompute %main "main"
6036fd4e5da5Sopenharmony_ci; CHECK-NOT: OpVariable
6037fd4e5da5Sopenharmony_ciOpCapability Shader
6038fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
6039fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main" %dead
6040fd4e5da5Sopenharmony_ciOpExecutionMode %main LocalSize 1 1 1
6041fd4e5da5Sopenharmony_ciOpName %main "main"
6042fd4e5da5Sopenharmony_ci%void = OpTypeVoid
6043fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0
6044fd4e5da5Sopenharmony_ci%ptr_private_int = OpTypePointer Private %int
6045fd4e5da5Sopenharmony_ci%dead = OpVariable %ptr_private_int Private
6046fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void
6047fd4e5da5Sopenharmony_ci%main = OpFunction %void None %void_fn
6048fd4e5da5Sopenharmony_ci%entry = OpLabel
6049fd4e5da5Sopenharmony_ciOpReturn
6050fd4e5da5Sopenharmony_ciOpFunctionEnd
6051fd4e5da5Sopenharmony_ci)";
6052fd4e5da5Sopenharmony_ci
6053fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
6054fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
6055fd4e5da5Sopenharmony_ci}
6056fd4e5da5Sopenharmony_ci
6057fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DeadInterfacesV14) {
6058fd4e5da5Sopenharmony_ci  const std::string spirv = R"(
6059fd4e5da5Sopenharmony_ci; CHECK: OpEntryPoint GLCompute %main "main" %live1 %live2
6060fd4e5da5Sopenharmony_ci; CHECK-NOT: %dead
6061fd4e5da5Sopenharmony_ciOpCapability Shader
6062fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
6063fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main" %live1 %dead1 %dead2 %live2
6064fd4e5da5Sopenharmony_ciOpExecutionMode %main LocalSize 1 1 1
6065fd4e5da5Sopenharmony_ciOpName %main "main"
6066fd4e5da5Sopenharmony_ciOpName %live1 "live1"
6067fd4e5da5Sopenharmony_ciOpName %live2 "live2"
6068fd4e5da5Sopenharmony_ciOpName %dead1 "dead1"
6069fd4e5da5Sopenharmony_ciOpName %dead2 "dead2"
6070fd4e5da5Sopenharmony_ci%void = OpTypeVoid
6071fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 0
6072fd4e5da5Sopenharmony_ci%int0 = OpConstant %int 0
6073fd4e5da5Sopenharmony_ci%ptr_ssbo_int = OpTypePointer StorageBuffer %int
6074fd4e5da5Sopenharmony_ci%live1 = OpVariable %ptr_ssbo_int StorageBuffer
6075fd4e5da5Sopenharmony_ci%live2 = OpVariable %ptr_ssbo_int StorageBuffer
6076fd4e5da5Sopenharmony_ci%dead1 = OpVariable %ptr_ssbo_int StorageBuffer
6077fd4e5da5Sopenharmony_ci%dead2 = OpVariable %ptr_ssbo_int StorageBuffer
6078fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void
6079fd4e5da5Sopenharmony_ci%main = OpFunction %void None %void_fn
6080fd4e5da5Sopenharmony_ci%entry = OpLabel
6081fd4e5da5Sopenharmony_ciOpStore %live1 %int0
6082fd4e5da5Sopenharmony_ciOpStore %live2 %int0
6083fd4e5da5Sopenharmony_ciOpReturn
6084fd4e5da5Sopenharmony_ciOpFunctionEnd
6085fd4e5da5Sopenharmony_ci)";
6086fd4e5da5Sopenharmony_ci
6087fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
6088fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
6089fd4e5da5Sopenharmony_ci}
6090fd4e5da5Sopenharmony_ci
6091fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, PreserveBindings) {
6092fd4e5da5Sopenharmony_ci  const std::string spirv = R"(
6093fd4e5da5Sopenharmony_ci; CHECK: OpDecorate %unusedSampler DescriptorSet 0
6094fd4e5da5Sopenharmony_ci; CHECK: OpDecorate %unusedSampler Binding 0
6095fd4e5da5Sopenharmony_ciOpCapability Shader
6096fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
6097fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
6098fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
6099fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
6100fd4e5da5Sopenharmony_ciOpSource GLSL 430
6101fd4e5da5Sopenharmony_ciOpName %main "main"
6102fd4e5da5Sopenharmony_ciOpName %unusedSampler "unusedSampler"
6103fd4e5da5Sopenharmony_ciOpDecorate %unusedSampler DescriptorSet 0
6104fd4e5da5Sopenharmony_ciOpDecorate %unusedSampler Binding 0
6105fd4e5da5Sopenharmony_ci%void = OpTypeVoid
6106fd4e5da5Sopenharmony_ci%5 = OpTypeFunction %void
6107fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
6108fd4e5da5Sopenharmony_ci%7 = OpTypeImage %float 2D 0 0 0 1 Unknown
6109fd4e5da5Sopenharmony_ci%8 = OpTypeSampledImage %7
6110fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_8 = OpTypePointer UniformConstant %8
6111fd4e5da5Sopenharmony_ci%unusedSampler = OpVariable %_ptr_UniformConstant_8 UniformConstant
6112fd4e5da5Sopenharmony_ci%main = OpFunction %void None %5
6113fd4e5da5Sopenharmony_ci%10 = OpLabel
6114fd4e5da5Sopenharmony_ciOpReturn
6115fd4e5da5Sopenharmony_ciOpFunctionEnd
6116fd4e5da5Sopenharmony_ci)";
6117fd4e5da5Sopenharmony_ci
6118fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
6119fd4e5da5Sopenharmony_ci
6120fd4e5da5Sopenharmony_ci  OptimizerOptions()->preserve_bindings_ = true;
6121fd4e5da5Sopenharmony_ci
6122fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
6123fd4e5da5Sopenharmony_ci}
6124fd4e5da5Sopenharmony_ci
6125fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, PreserveSpecConstants) {
6126fd4e5da5Sopenharmony_ci  const std::string spirv = R"(
6127fd4e5da5Sopenharmony_ci; CHECK: OpName %specConstant "specConstant"
6128fd4e5da5Sopenharmony_ci; CHECK: %specConstant = OpSpecConstant %int 0
6129fd4e5da5Sopenharmony_ciOpCapability Shader
6130fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
6131fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
6132fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
6133fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
6134fd4e5da5Sopenharmony_ciOpSource GLSL 430
6135fd4e5da5Sopenharmony_ciOpName %main "main"
6136fd4e5da5Sopenharmony_ciOpName %specConstant "specConstant"
6137fd4e5da5Sopenharmony_ciOpDecorate %specConstant SpecId 0
6138fd4e5da5Sopenharmony_ci%void = OpTypeVoid
6139fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
6140fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
6141fd4e5da5Sopenharmony_ci%specConstant = OpSpecConstant %int 0
6142fd4e5da5Sopenharmony_ci%main = OpFunction %void None %3
6143fd4e5da5Sopenharmony_ci%5 = OpLabel
6144fd4e5da5Sopenharmony_ciOpReturn
6145fd4e5da5Sopenharmony_ciOpFunctionEnd
6146fd4e5da5Sopenharmony_ci)";
6147fd4e5da5Sopenharmony_ci
6148fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
6149fd4e5da5Sopenharmony_ci
6150fd4e5da5Sopenharmony_ci  OptimizerOptions()->preserve_spec_constants_ = true;
6151fd4e5da5Sopenharmony_ci
6152fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
6153fd4e5da5Sopenharmony_ci}
6154fd4e5da5Sopenharmony_ci
6155fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, LiveDecorateId) {
6156fd4e5da5Sopenharmony_ci  const std::string spirv = R"(OpCapability Shader
6157fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
6158fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %1 "main" %2
6159fd4e5da5Sopenharmony_ciOpExecutionMode %1 LocalSize 8 1 1
6160fd4e5da5Sopenharmony_ciOpDecorate %2 DescriptorSet 0
6161fd4e5da5Sopenharmony_ciOpDecorate %2 Binding 0
6162fd4e5da5Sopenharmony_ciOpDecorateId %3 UniformId %uint_2
6163fd4e5da5Sopenharmony_ci%void = OpTypeVoid
6164fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
6165fd4e5da5Sopenharmony_ci%uint_2 = OpConstant %uint 2
6166fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
6167fd4e5da5Sopenharmony_ci%2 = OpVariable %_ptr_StorageBuffer_uint StorageBuffer
6168fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
6169fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %8
6170fd4e5da5Sopenharmony_ci%9 = OpLabel
6171fd4e5da5Sopenharmony_ci%3 = OpLoad %uint %2
6172fd4e5da5Sopenharmony_ciOpStore %2 %3
6173fd4e5da5Sopenharmony_ciOpReturn
6174fd4e5da5Sopenharmony_ciOpFunctionEnd
6175fd4e5da5Sopenharmony_ci)";
6176fd4e5da5Sopenharmony_ci
6177fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
6178fd4e5da5Sopenharmony_ci  OptimizerOptions()->preserve_spec_constants_ = true;
6179fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(spirv, spirv, true);
6180fd4e5da5Sopenharmony_ci}
6181fd4e5da5Sopenharmony_ci
6182fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, LiveDecorateIdOnGroup) {
6183fd4e5da5Sopenharmony_ci  const std::string spirv = R"(OpCapability Shader
6184fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
6185fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %1 "main" %2
6186fd4e5da5Sopenharmony_ciOpExecutionMode %1 LocalSize 8 1 1
6187fd4e5da5Sopenharmony_ciOpDecorate %2 DescriptorSet 0
6188fd4e5da5Sopenharmony_ciOpDecorate %2 Binding 0
6189fd4e5da5Sopenharmony_ciOpDecorateId %3 UniformId %uint_2
6190fd4e5da5Sopenharmony_ci%3 = OpDecorationGroup
6191fd4e5da5Sopenharmony_ciOpGroupDecorate %3 %5
6192fd4e5da5Sopenharmony_ci%void = OpTypeVoid
6193fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
6194fd4e5da5Sopenharmony_ci%uint_2 = OpConstant %uint 2
6195fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
6196fd4e5da5Sopenharmony_ci%2 = OpVariable %_ptr_StorageBuffer_uint StorageBuffer
6197fd4e5da5Sopenharmony_ci%9 = OpTypeFunction %void
6198fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %9
6199fd4e5da5Sopenharmony_ci%10 = OpLabel
6200fd4e5da5Sopenharmony_ci%5 = OpLoad %uint %2
6201fd4e5da5Sopenharmony_ciOpStore %2 %5
6202fd4e5da5Sopenharmony_ciOpReturn
6203fd4e5da5Sopenharmony_ciOpFunctionEnd
6204fd4e5da5Sopenharmony_ci)";
6205fd4e5da5Sopenharmony_ci
6206fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_4);
6207fd4e5da5Sopenharmony_ci  OptimizerOptions()->preserve_spec_constants_ = true;
6208fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(spirv, spirv, true);
6209fd4e5da5Sopenharmony_ci}
6210fd4e5da5Sopenharmony_ci
6211fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, NoEliminateForwardPointer) {
6212fd4e5da5Sopenharmony_ci  // clang-format off
6213fd4e5da5Sopenharmony_ci  //
6214fd4e5da5Sopenharmony_ci  //  #version 450
6215fd4e5da5Sopenharmony_ci  //  #extension GL_EXT_buffer_reference : enable
6216fd4e5da5Sopenharmony_ci  //
6217fd4e5da5Sopenharmony_ci  //    // forward reference
6218fd4e5da5Sopenharmony_ci  //    layout(buffer_reference) buffer blockType;
6219fd4e5da5Sopenharmony_ci  //
6220fd4e5da5Sopenharmony_ci  //  layout(buffer_reference, std430, buffer_reference_align = 16) buffer blockType {
6221fd4e5da5Sopenharmony_ci  //    int x;
6222fd4e5da5Sopenharmony_ci  //    blockType next;
6223fd4e5da5Sopenharmony_ci  //  };
6224fd4e5da5Sopenharmony_ci  //
6225fd4e5da5Sopenharmony_ci  //  layout(std430) buffer rootBlock {
6226fd4e5da5Sopenharmony_ci  //    blockType root;
6227fd4e5da5Sopenharmony_ci  //  } r;
6228fd4e5da5Sopenharmony_ci  //
6229fd4e5da5Sopenharmony_ci  //  void main()
6230fd4e5da5Sopenharmony_ci  //  {
6231fd4e5da5Sopenharmony_ci  //    blockType b = r.root;
6232fd4e5da5Sopenharmony_ci  //    b = b.next;
6233fd4e5da5Sopenharmony_ci  //    b.x = 531;
6234fd4e5da5Sopenharmony_ci  //  }
6235fd4e5da5Sopenharmony_ci  //
6236fd4e5da5Sopenharmony_ci  // clang-format on
6237fd4e5da5Sopenharmony_ci
6238fd4e5da5Sopenharmony_ci  const std::string predefs1 =
6239fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
6240fd4e5da5Sopenharmony_ciOpCapability PhysicalStorageBufferAddresses
6241fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_physical_storage_buffer"
6242fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_storage_buffer_storage_class"
6243fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
6244fd4e5da5Sopenharmony_ciOpMemoryModel PhysicalStorageBuffer64 GLSL450
6245fd4e5da5Sopenharmony_ciOpEntryPoint GLCompute %main "main"
6246fd4e5da5Sopenharmony_ciOpExecutionMode %main LocalSize 1 1 1
6247fd4e5da5Sopenharmony_ciOpSource GLSL 450
6248fd4e5da5Sopenharmony_ciOpSourceExtension "GL_EXT_buffer_reference"
6249fd4e5da5Sopenharmony_ci)";
6250fd4e5da5Sopenharmony_ci
6251fd4e5da5Sopenharmony_ci  const std::string names_before =
6252fd4e5da5Sopenharmony_ci      R"(OpName %main "main"
6253fd4e5da5Sopenharmony_ciOpName %blockType "blockType"
6254fd4e5da5Sopenharmony_ciOpMemberName %blockType 0 "x"
6255fd4e5da5Sopenharmony_ciOpMemberName %blockType 1 "next"
6256fd4e5da5Sopenharmony_ciOpName %b "b"
6257fd4e5da5Sopenharmony_ciOpName %rootBlock "rootBlock"
6258fd4e5da5Sopenharmony_ciOpMemberName %rootBlock 0 "root"
6259fd4e5da5Sopenharmony_ciOpName %r "r"
6260fd4e5da5Sopenharmony_ciOpMemberDecorate %blockType 0 Offset 0
6261fd4e5da5Sopenharmony_ciOpMemberDecorate %blockType 1 Offset 8
6262fd4e5da5Sopenharmony_ciOpDecorate %blockType Block
6263fd4e5da5Sopenharmony_ciOpDecorate %b AliasedPointer
6264fd4e5da5Sopenharmony_ciOpMemberDecorate %rootBlock 0 Offset 0
6265fd4e5da5Sopenharmony_ciOpDecorate %rootBlock Block
6266fd4e5da5Sopenharmony_ciOpDecorate %r DescriptorSet 0
6267fd4e5da5Sopenharmony_ciOpDecorate %r Binding 0
6268fd4e5da5Sopenharmony_ci)";
6269fd4e5da5Sopenharmony_ci
6270fd4e5da5Sopenharmony_ci  const std::string names_after =
6271fd4e5da5Sopenharmony_ci      R"(OpName %main "main"
6272fd4e5da5Sopenharmony_ciOpName %blockType "blockType"
6273fd4e5da5Sopenharmony_ciOpMemberName %blockType 0 "x"
6274fd4e5da5Sopenharmony_ciOpMemberName %blockType 1 "next"
6275fd4e5da5Sopenharmony_ciOpName %rootBlock "rootBlock"
6276fd4e5da5Sopenharmony_ciOpMemberName %rootBlock 0 "root"
6277fd4e5da5Sopenharmony_ciOpName %r "r"
6278fd4e5da5Sopenharmony_ciOpMemberDecorate %blockType 0 Offset 0
6279fd4e5da5Sopenharmony_ciOpMemberDecorate %blockType 1 Offset 8
6280fd4e5da5Sopenharmony_ciOpDecorate %blockType Block
6281fd4e5da5Sopenharmony_ciOpMemberDecorate %rootBlock 0 Offset 0
6282fd4e5da5Sopenharmony_ciOpDecorate %rootBlock Block
6283fd4e5da5Sopenharmony_ciOpDecorate %r DescriptorSet 0
6284fd4e5da5Sopenharmony_ciOpDecorate %r Binding 0
6285fd4e5da5Sopenharmony_ci)";
6286fd4e5da5Sopenharmony_ci
6287fd4e5da5Sopenharmony_ci  const std::string predefs2_before =
6288fd4e5da5Sopenharmony_ci      R"(%void = OpTypeVoid
6289fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
6290fd4e5da5Sopenharmony_ciOpTypeForwardPointer %_ptr_PhysicalStorageBuffer_blockType PhysicalStorageBuffer
6291fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
6292fd4e5da5Sopenharmony_ci%blockType = OpTypeStruct %int %_ptr_PhysicalStorageBuffer_blockType
6293fd4e5da5Sopenharmony_ci%_ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %blockType
6294fd4e5da5Sopenharmony_ci%_ptr_Function__ptr_PhysicalStorageBuffer_blockType = OpTypePointer Function %_ptr_PhysicalStorageBuffer_blockType
6295fd4e5da5Sopenharmony_ci%rootBlock = OpTypeStruct %_ptr_PhysicalStorageBuffer_blockType
6296fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer_rootBlock = OpTypePointer StorageBuffer %rootBlock
6297fd4e5da5Sopenharmony_ci%r = OpVariable %_ptr_StorageBuffer_rootBlock StorageBuffer
6298fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
6299fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer StorageBuffer %_ptr_PhysicalStorageBuffer_blockType
6300fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
6301fd4e5da5Sopenharmony_ci%_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %_ptr_PhysicalStorageBuffer_blockType
6302fd4e5da5Sopenharmony_ci%int_531 = OpConstant %int 531
6303fd4e5da5Sopenharmony_ci%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int
6304fd4e5da5Sopenharmony_ci)";
6305fd4e5da5Sopenharmony_ci
6306fd4e5da5Sopenharmony_ci  const std::string predefs2_after =
6307fd4e5da5Sopenharmony_ci      R"(%void = OpTypeVoid
6308fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
6309fd4e5da5Sopenharmony_ciOpTypeForwardPointer %_ptr_PhysicalStorageBuffer_blockType PhysicalStorageBuffer
6310fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
6311fd4e5da5Sopenharmony_ci%blockType = OpTypeStruct %int %_ptr_PhysicalStorageBuffer_blockType
6312fd4e5da5Sopenharmony_ci%_ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %blockType
6313fd4e5da5Sopenharmony_ci%rootBlock = OpTypeStruct %_ptr_PhysicalStorageBuffer_blockType
6314fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer_rootBlock = OpTypePointer StorageBuffer %rootBlock
6315fd4e5da5Sopenharmony_ci%r = OpVariable %_ptr_StorageBuffer_rootBlock StorageBuffer
6316fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
6317fd4e5da5Sopenharmony_ci%_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer StorageBuffer %_ptr_PhysicalStorageBuffer_blockType
6318fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
6319fd4e5da5Sopenharmony_ci%_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %_ptr_PhysicalStorageBuffer_blockType
6320fd4e5da5Sopenharmony_ci%int_531 = OpConstant %int 531
6321fd4e5da5Sopenharmony_ci%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int
6322fd4e5da5Sopenharmony_ci)";
6323fd4e5da5Sopenharmony_ci
6324fd4e5da5Sopenharmony_ci  const std::string func_before =
6325fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %3
6326fd4e5da5Sopenharmony_ci%5 = OpLabel
6327fd4e5da5Sopenharmony_ci%b = OpVariable %_ptr_Function__ptr_PhysicalStorageBuffer_blockType Function
6328fd4e5da5Sopenharmony_ci%16 = OpAccessChain %_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_blockType %r %int_0
6329fd4e5da5Sopenharmony_ci%17 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %16
6330fd4e5da5Sopenharmony_ci%21 = OpAccessChain %_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType %17 %int_1
6331fd4e5da5Sopenharmony_ci%22 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8
6332fd4e5da5Sopenharmony_ciOpStore %b %22
6333fd4e5da5Sopenharmony_ci%26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %22 %int_0
6334fd4e5da5Sopenharmony_ciOpStore %26 %int_531 Aligned 16
6335fd4e5da5Sopenharmony_ciOpReturn
6336fd4e5da5Sopenharmony_ciOpFunctionEnd
6337fd4e5da5Sopenharmony_ci)";
6338fd4e5da5Sopenharmony_ci
6339fd4e5da5Sopenharmony_ci  const std::string func_after =
6340fd4e5da5Sopenharmony_ci      R"(%main = OpFunction %void None %8
6341fd4e5da5Sopenharmony_ci%19 = OpLabel
6342fd4e5da5Sopenharmony_ci%20 = OpAccessChain %_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_blockType %r %int_0
6343fd4e5da5Sopenharmony_ci%21 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %20
6344fd4e5da5Sopenharmony_ci%22 = OpAccessChain %_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType %21 %int_1
6345fd4e5da5Sopenharmony_ci%23 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %22 Aligned 8
6346fd4e5da5Sopenharmony_ci%24 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %23 %int_0
6347fd4e5da5Sopenharmony_ciOpStore %24 %int_531 Aligned 16
6348fd4e5da5Sopenharmony_ciOpReturn
6349fd4e5da5Sopenharmony_ciOpFunctionEnd
6350fd4e5da5Sopenharmony_ci)";
6351fd4e5da5Sopenharmony_ci
6352fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(
6353fd4e5da5Sopenharmony_ci      predefs1 + names_before + predefs2_before + func_before,
6354fd4e5da5Sopenharmony_ci      predefs1 + names_after + predefs2_after + func_after, true, true);
6355fd4e5da5Sopenharmony_ci}
6356fd4e5da5Sopenharmony_ci
6357fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, MultipleFunctionProcessIndependently) {
6358fd4e5da5Sopenharmony_ci  const std::string spirv = R"(
6359fd4e5da5Sopenharmony_ci               OpCapability Shader
6360fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
6361fd4e5da5Sopenharmony_ci               OpEntryPoint GLCompute %entryHistogram "entryHistogram" %gl_GlobalInvocationID %gl_LocalInvocationIndex
6362fd4e5da5Sopenharmony_ci               OpEntryPoint GLCompute %entryAverage "entryAverage" %gl_GlobalInvocationID %gl_LocalInvocationIndex
6363fd4e5da5Sopenharmony_ci               OpExecutionMode %entryHistogram LocalSize 16 16 1
6364fd4e5da5Sopenharmony_ci               OpExecutionMode %entryAverage LocalSize 256 1 1
6365fd4e5da5Sopenharmony_ci               OpSource HLSL 640
6366fd4e5da5Sopenharmony_ci               OpName %type_RWStructuredBuffer_uint "type.RWStructuredBuffer.uint"
6367fd4e5da5Sopenharmony_ci               OpName %uHistogram "uHistogram"
6368fd4e5da5Sopenharmony_ci               OpName %type_ACSBuffer_counter "type.ACSBuffer.counter"
6369fd4e5da5Sopenharmony_ci               OpMemberName %type_ACSBuffer_counter 0 "counter"
6370fd4e5da5Sopenharmony_ci               OpName %counter_var_uHistogram "counter.var.uHistogram"
6371fd4e5da5Sopenharmony_ci               OpName %sharedHistogram "sharedHistogram"
6372fd4e5da5Sopenharmony_ci               OpName %entryHistogram "entryHistogram"
6373fd4e5da5Sopenharmony_ci               OpName %param_var_id "param.var.id"
6374fd4e5da5Sopenharmony_ci               OpName %param_var_idx "param.var.idx"
6375fd4e5da5Sopenharmony_ci               OpName %entryAverage "entryAverage"
6376fd4e5da5Sopenharmony_ci               OpName %param_var_id_0 "param.var.id"
6377fd4e5da5Sopenharmony_ci               OpName %param_var_idx_0 "param.var.idx"
6378fd4e5da5Sopenharmony_ci               OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
6379fd4e5da5Sopenharmony_ci               OpDecorate %gl_LocalInvocationIndex BuiltIn LocalInvocationIndex
6380fd4e5da5Sopenharmony_ci               OpDecorate %uHistogram DescriptorSet 0
6381fd4e5da5Sopenharmony_ci               OpDecorate %uHistogram Binding 0
6382fd4e5da5Sopenharmony_ci               OpDecorate %counter_var_uHistogram DescriptorSet 0
6383fd4e5da5Sopenharmony_ci               OpDecorate %counter_var_uHistogram Binding 1
6384fd4e5da5Sopenharmony_ci               OpDecorate %_runtimearr_uint ArrayStride 4
6385fd4e5da5Sopenharmony_ci               OpMemberDecorate %type_RWStructuredBuffer_uint 0 Offset 0
6386fd4e5da5Sopenharmony_ci               OpDecorate %type_RWStructuredBuffer_uint BufferBlock
6387fd4e5da5Sopenharmony_ci               OpMemberDecorate %type_ACSBuffer_counter 0 Offset 0
6388fd4e5da5Sopenharmony_ci               OpDecorate %type_ACSBuffer_counter BufferBlock
6389fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
6390fd4e5da5Sopenharmony_ci     %uint_0 = OpConstant %uint 0
6391fd4e5da5Sopenharmony_ci     %uint_1 = OpConstant %uint 1
6392fd4e5da5Sopenharmony_ci     %uint_2 = OpConstant %uint 2
6393fd4e5da5Sopenharmony_ci     %uint_4 = OpConstant %uint 4
6394fd4e5da5Sopenharmony_ci     %uint_8 = OpConstant %uint 8
6395fd4e5da5Sopenharmony_ci    %uint_16 = OpConstant %uint 16
6396fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
6397fd4e5da5Sopenharmony_ci    %uint_64 = OpConstant %uint 64
6398fd4e5da5Sopenharmony_ci   %uint_128 = OpConstant %uint 128
6399fd4e5da5Sopenharmony_ci   %uint_256 = OpConstant %uint 256
6400fd4e5da5Sopenharmony_ci   %uint_512 = OpConstant %uint 512
6401fd4e5da5Sopenharmony_ci   %uint_254 = OpConstant %uint 254
6402fd4e5da5Sopenharmony_ci   %uint_255 = OpConstant %uint 255
6403fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
6404fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
6405fd4e5da5Sopenharmony_ci%_runtimearr_uint = OpTypeRuntimeArray %uint
6406fd4e5da5Sopenharmony_ci%type_RWStructuredBuffer_uint = OpTypeStruct %_runtimearr_uint
6407fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_RWStructuredBuffer_uint = OpTypePointer Uniform %type_RWStructuredBuffer_uint
6408fd4e5da5Sopenharmony_ci%type_ACSBuffer_counter = OpTypeStruct %int
6409fd4e5da5Sopenharmony_ci%_ptr_Uniform_type_ACSBuffer_counter = OpTypePointer Uniform %type_ACSBuffer_counter
6410fd4e5da5Sopenharmony_ci%_arr_uint_uint_256 = OpTypeArray %uint %uint_256
6411fd4e5da5Sopenharmony_ci%_ptr_Workgroup__arr_uint_uint_256 = OpTypePointer Workgroup %_arr_uint_uint_256
6412fd4e5da5Sopenharmony_ci     %v3uint = OpTypeVector %uint 3
6413fd4e5da5Sopenharmony_ci%_ptr_Input_v3uint = OpTypePointer Input %v3uint
6414fd4e5da5Sopenharmony_ci%_ptr_Input_uint = OpTypePointer Input %uint
6415fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
6416fd4e5da5Sopenharmony_ci         %49 = OpTypeFunction %void
6417fd4e5da5Sopenharmony_ci%_ptr_Function_v3uint = OpTypePointer Function %v3uint
6418fd4e5da5Sopenharmony_ci%_ptr_Function_uint = OpTypePointer Function %uint
6419fd4e5da5Sopenharmony_ci         %52 = OpTypeFunction %void %_ptr_Function_v3uint %_ptr_Function_uint
6420fd4e5da5Sopenharmony_ci%_ptr_Workgroup_uint = OpTypePointer Workgroup %uint
6421fd4e5da5Sopenharmony_ci   %uint_264 = OpConstant %uint 264
6422fd4e5da5Sopenharmony_ci       %bool = OpTypeBool
6423fd4e5da5Sopenharmony_ci%_ptr_Uniform_uint = OpTypePointer Uniform %uint
6424fd4e5da5Sopenharmony_ci %uHistogram = OpVariable %_ptr_Uniform_type_RWStructuredBuffer_uint Uniform
6425fd4e5da5Sopenharmony_ci%counter_var_uHistogram = OpVariable %_ptr_Uniform_type_ACSBuffer_counter Uniform
6426fd4e5da5Sopenharmony_ci%sharedHistogram = OpVariable %_ptr_Workgroup__arr_uint_uint_256 Workgroup
6427fd4e5da5Sopenharmony_ci%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
6428fd4e5da5Sopenharmony_ci%gl_LocalInvocationIndex = OpVariable %_ptr_Input_uint Input
6429fd4e5da5Sopenharmony_ci%entryHistogram = OpFunction %void None %49
6430fd4e5da5Sopenharmony_ci         %57 = OpLabel
6431fd4e5da5Sopenharmony_ci%param_var_id = OpVariable %_ptr_Function_v3uint Function
6432fd4e5da5Sopenharmony_ci%param_var_idx = OpVariable %_ptr_Function_uint Function
6433fd4e5da5Sopenharmony_ci         %58 = OpLoad %v3uint %gl_GlobalInvocationID
6434fd4e5da5Sopenharmony_ci         %59 = OpLoad %uint %gl_LocalInvocationIndex
6435fd4e5da5Sopenharmony_ci         %79 = OpAccessChain %_ptr_Workgroup_uint %sharedHistogram %int_0
6436fd4e5da5Sopenharmony_ci         %80 = OpAtomicIAdd %uint %79 %uint_1 %uint_0 %uint_1
6437fd4e5da5Sopenharmony_ci               OpReturn
6438fd4e5da5Sopenharmony_ci               OpFunctionEnd
6439fd4e5da5Sopenharmony_ci%entryAverage = OpFunction %void None %49
6440fd4e5da5Sopenharmony_ci         %63 = OpLabel
6441fd4e5da5Sopenharmony_ci%param_var_id_0 = OpVariable %_ptr_Function_v3uint Function
6442fd4e5da5Sopenharmony_ci%param_var_idx_0 = OpVariable %_ptr_Function_uint Function
6443fd4e5da5Sopenharmony_ci         %64 = OpLoad %v3uint %gl_GlobalInvocationID
6444fd4e5da5Sopenharmony_ci         %65 = OpLoad %uint %gl_LocalInvocationIndex
6445fd4e5da5Sopenharmony_ci               OpStore %param_var_idx_0 %65
6446fd4e5da5Sopenharmony_ci         %83 = OpAccessChain %_ptr_Workgroup_uint %sharedHistogram %65
6447fd4e5da5Sopenharmony_ci               OpStore %83 %uint_0
6448fd4e5da5Sopenharmony_ci
6449fd4e5da5Sopenharmony_ci; CHECK:      [[ieq:%\w+]] = OpIEqual
6450fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpSelectionMerge [[merge:%\w+]]
6451fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranchConditional [[ieq]] [[not_elim:%\w+]] [[merge]]
6452fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[not_elim]] = OpLabel
6453fd4e5da5Sopenharmony_ci; CHECK:      [[merge]] = OpLabel
6454fd4e5da5Sopenharmony_ci
6455fd4e5da5Sopenharmony_ci               OpControlBarrier %uint_2 %uint_2 %uint_264
6456fd4e5da5Sopenharmony_ci         %85 = OpIEqual %bool %65 %uint_0
6457fd4e5da5Sopenharmony_ci               OpSelectionMerge %89 None
6458fd4e5da5Sopenharmony_ci               OpBranchConditional %85 %86 %89
6459fd4e5da5Sopenharmony_ci         %86 = OpLabel
6460fd4e5da5Sopenharmony_ci         %88 = OpAccessChain %_ptr_Workgroup_uint %sharedHistogram %65
6461fd4e5da5Sopenharmony_ci               OpStore %88 %uint_1
6462fd4e5da5Sopenharmony_ci               OpBranch %89
6463fd4e5da5Sopenharmony_ci         %89 = OpLabel
6464fd4e5da5Sopenharmony_ci               OpControlBarrier %uint_2 %uint_2 %uint_264
6465fd4e5da5Sopenharmony_ci         %91 = OpAccessChain %_ptr_Workgroup_uint %sharedHistogram %65
6466fd4e5da5Sopenharmony_ci         %92 = OpLoad %uint %91
6467fd4e5da5Sopenharmony_ci         %94 = OpAccessChain %_ptr_Uniform_uint %uHistogram %int_0 %65
6468fd4e5da5Sopenharmony_ci               OpStore %94 %92
6469fd4e5da5Sopenharmony_ci               OpReturn
6470fd4e5da5Sopenharmony_ci               OpFunctionEnd
6471fd4e5da5Sopenharmony_ci)";
6472fd4e5da5Sopenharmony_ci
6473fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_UNIVERSAL_1_3);
6474fd4e5da5Sopenharmony_ci
6475fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(spirv, true);
6476fd4e5da5Sopenharmony_ci}
6477fd4e5da5Sopenharmony_ci
6478fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DebugInfoKeepInFunctionElimStoreVar) {
6479fd4e5da5Sopenharmony_ci  // Verify that dead local variable tc and store eliminated but all
6480fd4e5da5Sopenharmony_ci  // in-function debuginfo kept.
6481fd4e5da5Sopenharmony_ci  //
6482fd4e5da5Sopenharmony_ci  // The SPIR-V has been inlined and local single store eliminated
6483fd4e5da5Sopenharmony_ci  //
6484fd4e5da5Sopenharmony_ci  // Texture2D g_tColor;
6485fd4e5da5Sopenharmony_ci  // SamplerState g_sAniso;
6486fd4e5da5Sopenharmony_ci  //
6487fd4e5da5Sopenharmony_ci  // struct PS_INPUT {
6488fd4e5da5Sopenharmony_ci  //   float2 vTextureCoords : TEXCOORD2;
6489fd4e5da5Sopenharmony_ci  // };
6490fd4e5da5Sopenharmony_ci  //
6491fd4e5da5Sopenharmony_ci  // struct PS_OUTPUT {
6492fd4e5da5Sopenharmony_ci  //   float4 vColor : SV_Target0;
6493fd4e5da5Sopenharmony_ci  // };
6494fd4e5da5Sopenharmony_ci  //
6495fd4e5da5Sopenharmony_ci  // PS_OUTPUT MainPs(PS_INPUT i) {
6496fd4e5da5Sopenharmony_ci  //   PS_OUTPUT ps_output;
6497fd4e5da5Sopenharmony_ci  //   float2 tc = i.vTextureCoords.xy;
6498fd4e5da5Sopenharmony_ci  //   ps_output.vColor = g_tColor.Sample(g_sAniso, tc);
6499fd4e5da5Sopenharmony_ci  //   return ps_output;
6500fd4e5da5Sopenharmony_ci  // }
6501fd4e5da5Sopenharmony_ci
6502fd4e5da5Sopenharmony_ci  const std::string text = R"(
6503fd4e5da5Sopenharmony_ci               OpCapability Shader
6504fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "OpenCL.DebugInfo.100"
6505fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
6506fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %g_sAniso %in_var_TEXCOORD2 %out_var_SV_Target0
6507fd4e5da5Sopenharmony_ci               OpExecutionMode %MainPs OriginUpperLeft
6508fd4e5da5Sopenharmony_ci          %7 = OpString "foo.frag"
6509fd4e5da5Sopenharmony_ci          %8 = OpString "PS_OUTPUT"
6510fd4e5da5Sopenharmony_ci          %9 = OpString "float"
6511fd4e5da5Sopenharmony_ci         %10 = OpString "vColor"
6512fd4e5da5Sopenharmony_ci         %11 = OpString "PS_INPUT"
6513fd4e5da5Sopenharmony_ci         %12 = OpString "vTextureCoords"
6514fd4e5da5Sopenharmony_ci         %13 = OpString "@type.2d.image"
6515fd4e5da5Sopenharmony_ci         %14 = OpString "type.2d.image"
6516fd4e5da5Sopenharmony_ci         %15 = OpString "Texture2D.TemplateParam"
6517fd4e5da5Sopenharmony_ci         %16 = OpString "src.MainPs"
6518fd4e5da5Sopenharmony_ci         %17 = OpString "tc"
6519fd4e5da5Sopenharmony_ci         %18 = OpString "ps_output"
6520fd4e5da5Sopenharmony_ci         %19 = OpString "i"
6521fd4e5da5Sopenharmony_ci         %20 = OpString "@type.sampler"
6522fd4e5da5Sopenharmony_ci         %21 = OpString "type.sampler"
6523fd4e5da5Sopenharmony_ci         %22 = OpString "g_sAniso"
6524fd4e5da5Sopenharmony_ci         %23 = OpString "g_tColor"
6525fd4e5da5Sopenharmony_ci               OpName %type_2d_image "type.2d.image"
6526fd4e5da5Sopenharmony_ci               OpName %g_tColor "g_tColor"
6527fd4e5da5Sopenharmony_ci               OpName %type_sampler "type.sampler"
6528fd4e5da5Sopenharmony_ci               OpName %g_sAniso "g_sAniso"
6529fd4e5da5Sopenharmony_ci               OpName %in_var_TEXCOORD2 "in.var.TEXCOORD2"
6530fd4e5da5Sopenharmony_ci               OpName %out_var_SV_Target0 "out.var.SV_Target0"
6531fd4e5da5Sopenharmony_ci               OpName %MainPs "MainPs"
6532fd4e5da5Sopenharmony_ci               OpName %PS_INPUT "PS_INPUT"
6533fd4e5da5Sopenharmony_ci               OpMemberName %PS_INPUT 0 "vTextureCoords"
6534fd4e5da5Sopenharmony_ci               OpName %param_var_i "param.var.i"
6535fd4e5da5Sopenharmony_ci               OpName %PS_OUTPUT "PS_OUTPUT"
6536fd4e5da5Sopenharmony_ci               OpMemberName %PS_OUTPUT 0 "vColor"
6537fd4e5da5Sopenharmony_ci               OpName %type_sampled_image "type.sampled.image"
6538fd4e5da5Sopenharmony_ci               OpDecorate %in_var_TEXCOORD2 Location 0
6539fd4e5da5Sopenharmony_ci               OpDecorate %out_var_SV_Target0 Location 0
6540fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor DescriptorSet 0
6541fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor Binding 0
6542fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso DescriptorSet 0
6543fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso Binding 1
6544fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
6545fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
6546fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
6547fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
6548fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
6549fd4e5da5Sopenharmony_ci%type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
6550fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
6551fd4e5da5Sopenharmony_ci%type_sampler = OpTypeSampler
6552fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %type_sampler
6553fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
6554fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
6555fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
6556fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
6557fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
6558fd4e5da5Sopenharmony_ci   %uint_128 = OpConstant %uint 128
6559fd4e5da5Sopenharmony_ci     %uint_0 = OpConstant %uint 0
6560fd4e5da5Sopenharmony_ci    %uint_64 = OpConstant %uint 64
6561fd4e5da5Sopenharmony_ci         %45 = OpTypeFunction %void
6562fd4e5da5Sopenharmony_ci   %PS_INPUT = OpTypeStruct %v2float
6563fd4e5da5Sopenharmony_ci%_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
6564fd4e5da5Sopenharmony_ci  %PS_OUTPUT = OpTypeStruct %v4float
6565fd4e5da5Sopenharmony_ci         %47 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
6566fd4e5da5Sopenharmony_ci%_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
6567fd4e5da5Sopenharmony_ci%_ptr_Function_v2float = OpTypePointer Function %v2float
6568fd4e5da5Sopenharmony_ci%type_sampled_image = OpTypeSampledImage %type_2d_image
6569fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
6570fd4e5da5Sopenharmony_ci   %g_tColor = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
6571fd4e5da5Sopenharmony_ci   %g_sAniso = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
6572fd4e5da5Sopenharmony_ci%in_var_TEXCOORD2 = OpVariable %_ptr_Input_v2float Input
6573fd4e5da5Sopenharmony_ci%out_var_SV_Target0 = OpVariable %_ptr_Output_v4float Output
6574fd4e5da5Sopenharmony_ci         %51 = OpExtInst %void %1 DebugInfoNone
6575fd4e5da5Sopenharmony_ci         %52 = OpExtInst %void %1 DebugExpression
6576fd4e5da5Sopenharmony_ci         %53 = OpExtInst %void %1 DebugOperation Deref
6577fd4e5da5Sopenharmony_ci         %54 = OpExtInst %void %1 DebugExpression %53
6578fd4e5da5Sopenharmony_ci         %55 = OpExtInst %void %1 DebugSource %7
6579fd4e5da5Sopenharmony_ci         %56 = OpExtInst %void %1 DebugCompilationUnit 1 4 %55 HLSL
6580fd4e5da5Sopenharmony_ci         %57 = OpExtInst %void %1 DebugTypeComposite %8 Structure %55 10 1 %56 %8 %uint_128 FlagIsProtected|FlagIsPrivate %58
6581fd4e5da5Sopenharmony_ci         %59 = OpExtInst %void %1 DebugTypeBasic %9 %uint_32 Float
6582fd4e5da5Sopenharmony_ci         %60 = OpExtInst %void %1 DebugTypeVector %59 4
6583fd4e5da5Sopenharmony_ci         %58 = OpExtInst %void %1 DebugTypeMember %10 %60 %55 12 5 %57 %uint_0 %uint_128 FlagIsProtected|FlagIsPrivate
6584fd4e5da5Sopenharmony_ci         %61 = OpExtInst %void %1 DebugTypeComposite %11 Structure %55 5 1 %56 %11 %uint_64 FlagIsProtected|FlagIsPrivate %62
6585fd4e5da5Sopenharmony_ci         %63 = OpExtInst %void %1 DebugTypeVector %59 2
6586fd4e5da5Sopenharmony_ci         %62 = OpExtInst %void %1 DebugTypeMember %12 %63 %55 7 5 %61 %uint_0 %uint_64 FlagIsProtected|FlagIsPrivate
6587fd4e5da5Sopenharmony_ci         %64 = OpExtInst %void %1 DebugTypeComposite %13 Class %55 0 0 %56 %14 %51 FlagIsProtected|FlagIsPrivate
6588fd4e5da5Sopenharmony_ci         %65 = OpExtInst %void %1 DebugTypeTemplateParameter %15 %59 %51 %55 0 0
6589fd4e5da5Sopenharmony_ci         %66 = OpExtInst %void %1 DebugTypeTemplate %64 %65
6590fd4e5da5Sopenharmony_ci         %67 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %57 %61
6591fd4e5da5Sopenharmony_ci         %68 = OpExtInst %void %1 DebugFunction %16 %67 %55 15 1 %56 %16 FlagIsProtected|FlagIsPrivate 16 %51
6592fd4e5da5Sopenharmony_ci         %69 = OpExtInst %void %1 DebugLexicalBlock %55 16 1 %68
6593fd4e5da5Sopenharmony_ci         %70 = OpExtInst %void %1 DebugLocalVariable %17 %63 %55 19 12 %69 FlagIsLocal
6594fd4e5da5Sopenharmony_ci         %71 = OpExtInst %void %1 DebugLocalVariable %18 %57 %55 17 15 %69 FlagIsLocal
6595fd4e5da5Sopenharmony_ci         %72 = OpExtInst %void %1 DebugLocalVariable %19 %61 %55 15 29 %68 FlagIsLocal 1
6596fd4e5da5Sopenharmony_ci         %73 = OpExtInst %void %1 DebugTypeComposite %20 Structure %55 0 0 %56 %21 %51 FlagIsProtected|FlagIsPrivate
6597fd4e5da5Sopenharmony_ci         %74 = OpExtInst %void %1 DebugGlobalVariable %22 %73 %55 3 14 %56 %22 %g_sAniso FlagIsDefinition
6598fd4e5da5Sopenharmony_ci         %75 = OpExtInst %void %1 DebugGlobalVariable %23 %64 %55 1 11 %56 %23 %g_tColor FlagIsDefinition
6599fd4e5da5Sopenharmony_ci     %MainPs = OpFunction %void None %45
6600fd4e5da5Sopenharmony_ci         %76 = OpLabel
6601fd4e5da5Sopenharmony_ci        %107 = OpExtInst %void %1 DebugScope %69
6602fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugScope %69
6603fd4e5da5Sopenharmony_ci         %78 = OpVariable %_ptr_Function_PS_OUTPUT Function
6604fd4e5da5Sopenharmony_ci         %79 = OpVariable %_ptr_Function_v2float Function
6605fd4e5da5Sopenharmony_ci        %108 = OpExtInst %void %1 DebugNoScope
6606fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugNoScope
6607fd4e5da5Sopenharmony_ci         %81 = OpVariable %_ptr_Function_PS_OUTPUT Function
6608fd4e5da5Sopenharmony_ci%param_var_i = OpVariable %_ptr_Function_PS_INPUT Function
6609fd4e5da5Sopenharmony_ci         %82 = OpLoad %v2float %in_var_TEXCOORD2
6610fd4e5da5Sopenharmony_ci         %83 = OpCompositeConstruct %PS_INPUT %82
6611fd4e5da5Sopenharmony_ci               OpStore %param_var_i %83
6612fd4e5da5Sopenharmony_ci        %109 = OpExtInst %void %1 DebugScope %68
6613fd4e5da5Sopenharmony_ci         %85 = OpExtInst %void %1 DebugDeclare %72 %param_var_i %52
6614fd4e5da5Sopenharmony_ci        %110 = OpExtInst %void %1 DebugScope %69
6615fd4e5da5Sopenharmony_ci         %87 = OpExtInst %void %1 DebugDeclare %71 %78 %52
6616fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugScope %68
6617fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugDeclare %72 %param_var_i %52
6618fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugScope %69
6619fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugDeclare %71 %78 %52
6620fd4e5da5Sopenharmony_ci               OpLine %7 19 17
6621fd4e5da5Sopenharmony_ci         %88 = OpAccessChain %_ptr_Function_v2float %param_var_i %int_0
6622fd4e5da5Sopenharmony_ci         %89 = OpLoad %v2float %88
6623fd4e5da5Sopenharmony_ci               OpLine %7 19 12
6624fd4e5da5Sopenharmony_ci               OpStore %79 %89
6625fd4e5da5Sopenharmony_ci;CHECK-NOT:    OpStore %79 %89
6626fd4e5da5Sopenharmony_ci               OpLine %7 19 12
6627fd4e5da5Sopenharmony_ci        %106 = OpExtInst %void %1 DebugValue %70 %89 %52
6628fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugValue %70 %89 %52
6629fd4e5da5Sopenharmony_ci               OpLine %7 20 26
6630fd4e5da5Sopenharmony_ci         %91 = OpLoad %type_2d_image %g_tColor
6631fd4e5da5Sopenharmony_ci               OpLine %7 20 46
6632fd4e5da5Sopenharmony_ci         %92 = OpLoad %type_sampler %g_sAniso
6633fd4e5da5Sopenharmony_ci               OpLine %7 20 26
6634fd4e5da5Sopenharmony_ci         %94 = OpSampledImage %type_sampled_image %91 %92
6635fd4e5da5Sopenharmony_ci         %95 = OpImageSampleImplicitLod %v4float %94 %89 None
6636fd4e5da5Sopenharmony_ci               OpLine %7 20 5
6637fd4e5da5Sopenharmony_ci         %96 = OpAccessChain %_ptr_Function_v4float %78 %int_0
6638fd4e5da5Sopenharmony_ci               OpStore %96 %95
6639fd4e5da5Sopenharmony_ci               OpLine %7 21 12
6640fd4e5da5Sopenharmony_ci         %97 = OpLoad %PS_OUTPUT %78
6641fd4e5da5Sopenharmony_ci               OpLine %7 21 5
6642fd4e5da5Sopenharmony_ci               OpStore %81 %97
6643fd4e5da5Sopenharmony_ci        %111 = OpExtInst %void %1 DebugNoScope
6644fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugNoScope
6645fd4e5da5Sopenharmony_ci        %100 = OpCompositeExtract %v4float %97 0
6646fd4e5da5Sopenharmony_ci               OpStore %out_var_SV_Target0 %100
6647fd4e5da5Sopenharmony_ci               OpReturn
6648fd4e5da5Sopenharmony_ci               OpFunctionEnd
6649fd4e5da5Sopenharmony_ci)";
6650fd4e5da5Sopenharmony_ci
6651fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
6652fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
6653fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
6654fd4e5da5Sopenharmony_ci}
6655fd4e5da5Sopenharmony_ci
6656fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, ShaderDebugInfoKeepInFunctionElimStoreVar) {
6657fd4e5da5Sopenharmony_ci  // Verify that dead local variable tc and store eliminated but all
6658fd4e5da5Sopenharmony_ci  // in-function NonSemantic Shader debuginfo kept.
6659fd4e5da5Sopenharmony_ci
6660fd4e5da5Sopenharmony_ci  const std::string text = R"(
6661fd4e5da5Sopenharmony_ci               OpCapability Shader
6662fd4e5da5Sopenharmony_ci               OpExtension "SPV_KHR_non_semantic_info"
6663fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
6664fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
6665fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %g_sAniso %in_var_TEXCOORD2 %out_var_SV_Target0
6666fd4e5da5Sopenharmony_ci               OpExecutionMode %MainPs OriginUpperLeft
6667fd4e5da5Sopenharmony_ci          %7 = OpString "foo.frag"
6668fd4e5da5Sopenharmony_ci          %8 = OpString "PS_OUTPUT"
6669fd4e5da5Sopenharmony_ci          %9 = OpString "float"
6670fd4e5da5Sopenharmony_ci         %10 = OpString "vColor"
6671fd4e5da5Sopenharmony_ci         %11 = OpString "PS_INPUT"
6672fd4e5da5Sopenharmony_ci         %12 = OpString "vTextureCoords"
6673fd4e5da5Sopenharmony_ci         %13 = OpString "@type.2d.image"
6674fd4e5da5Sopenharmony_ci         %14 = OpString "type.2d.image"
6675fd4e5da5Sopenharmony_ci         %15 = OpString "Texture2D.TemplateParam"
6676fd4e5da5Sopenharmony_ci         %16 = OpString "src.MainPs"
6677fd4e5da5Sopenharmony_ci         %17 = OpString "tc"
6678fd4e5da5Sopenharmony_ci         %18 = OpString "ps_output"
6679fd4e5da5Sopenharmony_ci         %19 = OpString "i"
6680fd4e5da5Sopenharmony_ci         %20 = OpString "@type.sampler"
6681fd4e5da5Sopenharmony_ci         %21 = OpString "type.sampler"
6682fd4e5da5Sopenharmony_ci         %22 = OpString "g_sAniso"
6683fd4e5da5Sopenharmony_ci         %23 = OpString "g_tColor"
6684fd4e5da5Sopenharmony_ci               OpName %type_2d_image "type.2d.image"
6685fd4e5da5Sopenharmony_ci               OpName %g_tColor "g_tColor"
6686fd4e5da5Sopenharmony_ci               OpName %type_sampler "type.sampler"
6687fd4e5da5Sopenharmony_ci               OpName %g_sAniso "g_sAniso"
6688fd4e5da5Sopenharmony_ci               OpName %in_var_TEXCOORD2 "in.var.TEXCOORD2"
6689fd4e5da5Sopenharmony_ci               OpName %out_var_SV_Target0 "out.var.SV_Target0"
6690fd4e5da5Sopenharmony_ci               OpName %MainPs "MainPs"
6691fd4e5da5Sopenharmony_ci               OpName %PS_INPUT "PS_INPUT"
6692fd4e5da5Sopenharmony_ci               OpMemberName %PS_INPUT 0 "vTextureCoords"
6693fd4e5da5Sopenharmony_ci               OpName %param_var_i "param.var.i"
6694fd4e5da5Sopenharmony_ci               OpName %PS_OUTPUT "PS_OUTPUT"
6695fd4e5da5Sopenharmony_ci               OpMemberName %PS_OUTPUT 0 "vColor"
6696fd4e5da5Sopenharmony_ci               OpName %type_sampled_image "type.sampled.image"
6697fd4e5da5Sopenharmony_ci               OpDecorate %in_var_TEXCOORD2 Location 0
6698fd4e5da5Sopenharmony_ci               OpDecorate %out_var_SV_Target0 Location 0
6699fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor DescriptorSet 0
6700fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor Binding 0
6701fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso DescriptorSet 0
6702fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso Binding 1
6703fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
6704fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
6705fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
6706fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
6707fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
6708fd4e5da5Sopenharmony_ci%type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
6709fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
6710fd4e5da5Sopenharmony_ci%type_sampler = OpTypeSampler
6711fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %type_sampler
6712fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
6713fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
6714fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
6715fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
6716fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
6717fd4e5da5Sopenharmony_ci   %uint_128 = OpConstant %uint 128
6718fd4e5da5Sopenharmony_ci     %uint_0 = OpConstant %uint 0
6719fd4e5da5Sopenharmony_ci     %uint_1 = OpConstant %uint 1
6720fd4e5da5Sopenharmony_ci     %uint_2 = OpConstant %uint 2
6721fd4e5da5Sopenharmony_ci     %uint_3 = OpConstant %uint 3
6722fd4e5da5Sopenharmony_ci     %uint_4 = OpConstant %uint 4
6723fd4e5da5Sopenharmony_ci     %uint_5 = OpConstant %uint 5
6724fd4e5da5Sopenharmony_ci     %uint_7 = OpConstant %uint 7
6725fd4e5da5Sopenharmony_ci     %uint_8 = OpConstant %uint 8
6726fd4e5da5Sopenharmony_ci    %uint_10 = OpConstant %uint 10
6727fd4e5da5Sopenharmony_ci    %uint_11 = OpConstant %uint 11
6728fd4e5da5Sopenharmony_ci    %uint_12 = OpConstant %uint 12
6729fd4e5da5Sopenharmony_ci    %uint_14 = OpConstant %uint 14
6730fd4e5da5Sopenharmony_ci    %uint_15 = OpConstant %uint 15
6731fd4e5da5Sopenharmony_ci    %uint_16 = OpConstant %uint 16
6732fd4e5da5Sopenharmony_ci    %uint_17 = OpConstant %uint 17
6733fd4e5da5Sopenharmony_ci    %uint_19 = OpConstant %uint 19
6734fd4e5da5Sopenharmony_ci    %uint_20 = OpConstant %uint 20
6735fd4e5da5Sopenharmony_ci    %uint_21 = OpConstant %uint 21
6736fd4e5da5Sopenharmony_ci    %uint_25 = OpConstant %uint 25
6737fd4e5da5Sopenharmony_ci    %uint_29 = OpConstant %uint 29
6738fd4e5da5Sopenharmony_ci    %uint_30 = OpConstant %uint 30
6739fd4e5da5Sopenharmony_ci    %uint_35 = OpConstant %uint 35
6740fd4e5da5Sopenharmony_ci    %uint_41 = OpConstant %uint 41
6741fd4e5da5Sopenharmony_ci    %uint_48 = OpConstant %uint 48
6742fd4e5da5Sopenharmony_ci    %uint_53 = OpConstant %uint 53
6743fd4e5da5Sopenharmony_ci    %uint_64 = OpConstant %uint 64
6744fd4e5da5Sopenharmony_ci         %45 = OpTypeFunction %void
6745fd4e5da5Sopenharmony_ci   %PS_INPUT = OpTypeStruct %v2float
6746fd4e5da5Sopenharmony_ci%_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
6747fd4e5da5Sopenharmony_ci  %PS_OUTPUT = OpTypeStruct %v4float
6748fd4e5da5Sopenharmony_ci         %47 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
6749fd4e5da5Sopenharmony_ci%_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
6750fd4e5da5Sopenharmony_ci%_ptr_Function_v2float = OpTypePointer Function %v2float
6751fd4e5da5Sopenharmony_ci%type_sampled_image = OpTypeSampledImage %type_2d_image
6752fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
6753fd4e5da5Sopenharmony_ci   %g_tColor = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
6754fd4e5da5Sopenharmony_ci   %g_sAniso = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
6755fd4e5da5Sopenharmony_ci%in_var_TEXCOORD2 = OpVariable %_ptr_Input_v2float Input
6756fd4e5da5Sopenharmony_ci%out_var_SV_Target0 = OpVariable %_ptr_Output_v4float Output
6757fd4e5da5Sopenharmony_ci         %51 = OpExtInst %void %1 DebugInfoNone
6758fd4e5da5Sopenharmony_ci         %52 = OpExtInst %void %1 DebugExpression
6759fd4e5da5Sopenharmony_ci         %53 = OpExtInst %void %1 DebugOperation %uint_0
6760fd4e5da5Sopenharmony_ci         %54 = OpExtInst %void %1 DebugExpression %53
6761fd4e5da5Sopenharmony_ci         %55 = OpExtInst %void %1 DebugSource %7
6762fd4e5da5Sopenharmony_ci         %56 = OpExtInst %void %1 DebugCompilationUnit %uint_1 %uint_4 %55 %uint_5
6763fd4e5da5Sopenharmony_ci         %59 = OpExtInst %void %1 DebugTypeBasic %9 %uint_32 %uint_3 %uint_0
6764fd4e5da5Sopenharmony_ci         %60 = OpExtInst %void %1 DebugTypeVector %59 %uint_4
6765fd4e5da5Sopenharmony_ci         %58 = OpExtInst %void %1 DebugTypeMember %10 %60 %55 %uint_12 %uint_5 %uint_0 %uint_128 %uint_3
6766fd4e5da5Sopenharmony_ci         %57 = OpExtInst %void %1 DebugTypeComposite %8 %uint_1 %55 %uint_10 %uint_1 %56 %8 %uint_128 %uint_3 %58
6767fd4e5da5Sopenharmony_ci         %63 = OpExtInst %void %1 DebugTypeVector %59 %uint_2
6768fd4e5da5Sopenharmony_ci         %62 = OpExtInst %void %1 DebugTypeMember %12 %63 %55 %uint_7 %uint_5 %uint_0 %uint_64 %uint_3
6769fd4e5da5Sopenharmony_ci         %61 = OpExtInst %void %1 DebugTypeComposite %11 %uint_1 %55 %uint_5 %uint_1 %56 %11 %uint_64 %uint_3 %62
6770fd4e5da5Sopenharmony_ci         %64 = OpExtInst %void %1 DebugTypeComposite %13 %uint_0 %55 %uint_0 %uint_0 %56 %14 %51 %uint_3
6771fd4e5da5Sopenharmony_ci         %67 = OpExtInst %void %1 DebugTypeFunction %uint_3 %57 %61
6772fd4e5da5Sopenharmony_ci         %68 = OpExtInst %void %1 DebugFunction %16 %67 %55 %uint_15 %uint_1 %56 %16 %uint_3 %uint_16
6773fd4e5da5Sopenharmony_ci         %69 = OpExtInst %void %1 DebugLexicalBlock %55 %uint_16 %uint_1 %68
6774fd4e5da5Sopenharmony_ci         %70 = OpExtInst %void %1 DebugLocalVariable %17 %63 %55 %uint_19 %uint_12 %69 %uint_4
6775fd4e5da5Sopenharmony_ci         %71 = OpExtInst %void %1 DebugLocalVariable %18 %57 %55 %uint_17 %uint_15 %69 %uint_4
6776fd4e5da5Sopenharmony_ci         %72 = OpExtInst %void %1 DebugLocalVariable %19 %61 %55 %uint_15 %uint_29 %68 %uint_4 %uint_1
6777fd4e5da5Sopenharmony_ci         %73 = OpExtInst %void %1 DebugTypeComposite %20 %uint_1 %55 %uint_0 %uint_0 %56 %21 %51 %uint_3
6778fd4e5da5Sopenharmony_ci         %74 = OpExtInst %void %1 DebugGlobalVariable %22 %73 %55 %uint_3 %uint_14 %56 %22 %g_sAniso %uint_8
6779fd4e5da5Sopenharmony_ci         %75 = OpExtInst %void %1 DebugGlobalVariable %23 %64 %55 %uint_1 %uint_11 %56 %23 %g_tColor %uint_8
6780fd4e5da5Sopenharmony_ci     %MainPs = OpFunction %void None %45
6781fd4e5da5Sopenharmony_ci         %76 = OpLabel
6782fd4e5da5Sopenharmony_ci         %78 = OpVariable %_ptr_Function_PS_OUTPUT Function
6783fd4e5da5Sopenharmony_ci         %79 = OpVariable %_ptr_Function_v2float Function
6784fd4e5da5Sopenharmony_ci         %81 = OpVariable %_ptr_Function_PS_OUTPUT Function
6785fd4e5da5Sopenharmony_ci%param_var_i = OpVariable %_ptr_Function_PS_INPUT Function
6786fd4e5da5Sopenharmony_ci         %82 = OpLoad %v2float %in_var_TEXCOORD2
6787fd4e5da5Sopenharmony_ci         %83 = OpCompositeConstruct %PS_INPUT %82
6788fd4e5da5Sopenharmony_ci               OpStore %param_var_i %83
6789fd4e5da5Sopenharmony_ci        %112 = OpExtInst %void %1 DebugFunctionDefinition %68 %MainPs
6790fd4e5da5Sopenharmony_ci        %109 = OpExtInst %void %1 DebugScope %68
6791fd4e5da5Sopenharmony_ci         %85 = OpExtInst %void %1 DebugDeclare %72 %param_var_i %52
6792fd4e5da5Sopenharmony_ci        %110 = OpExtInst %void %1 DebugScope %69
6793fd4e5da5Sopenharmony_ci         %87 = OpExtInst %void %1 DebugDeclare %71 %78 %52
6794fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugFunctionDefinition %68 %MainPs
6795fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugScope %68
6796fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugDeclare %72 %param_var_i %52
6797fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugScope %69
6798fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugDeclare %71 %78 %52
6799fd4e5da5Sopenharmony_ci        %300 = OpExtInst %void %1 DebugLine %55 %uint_19 %uint_19 %uint_17 %uint_30
6800fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugLine %55 %uint_19 %uint_19 %uint_17 %uint_30
6801fd4e5da5Sopenharmony_ci         %88 = OpAccessChain %_ptr_Function_v2float %param_var_i %int_0
6802fd4e5da5Sopenharmony_ci         %89 = OpLoad %v2float %88
6803fd4e5da5Sopenharmony_ci        %301 = OpExtInst %void %1 DebugLine %55 %uint_19 %uint_19 %uint_12 %uint_35
6804fd4e5da5Sopenharmony_ci               OpStore %79 %89
6805fd4e5da5Sopenharmony_ci;CHECK-NOT:    OpStore %79 %89
6806fd4e5da5Sopenharmony_ci        %302 = OpExtInst %void %1 DebugLine %55 %uint_19 %uint_19 %uint_12 %uint_35
6807fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugLine %55 %uint_19 %uint_19 %uint_12 %uint_35
6808fd4e5da5Sopenharmony_ci        %106 = OpExtInst %void %1 DebugValue %70 %89 %52
6809fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugValue %70 %89 %52
6810fd4e5da5Sopenharmony_ci        %303 = OpExtInst %void %1 DebugLine %55 %uint_20 %uint_20 %uint_25 %uint_32
6811fd4e5da5Sopenharmony_ci         %91 = OpLoad %type_2d_image %g_tColor
6812fd4e5da5Sopenharmony_ci        %304 = OpExtInst %void %1 DebugLine %55 %uint_20 %uint_20 %uint_41 %uint_48
6813fd4e5da5Sopenharmony_ci         %92 = OpLoad %type_sampler %g_sAniso
6814fd4e5da5Sopenharmony_ci        %305 = OpExtInst %void %1 DebugLine %55 %uint_20 %uint_20 %uint_25 %uint_53
6815fd4e5da5Sopenharmony_ci         %94 = OpSampledImage %type_sampled_image %91 %92
6816fd4e5da5Sopenharmony_ci         %95 = OpImageSampleImplicitLod %v4float %94 %89 None
6817fd4e5da5Sopenharmony_ci        %306 = OpExtInst %void %1 DebugLine %55 %uint_20 %uint_20 %uint_5 %uint_53
6818fd4e5da5Sopenharmony_ci         %96 = OpAccessChain %_ptr_Function_v4float %78 %int_0
6819fd4e5da5Sopenharmony_ci               OpStore %96 %95
6820fd4e5da5Sopenharmony_ci        %307 = OpExtInst %void %1 DebugLine %55 %uint_21 %uint_21 %uint_12 %uint_20
6821fd4e5da5Sopenharmony_ci         %97 = OpLoad %PS_OUTPUT %78
6822fd4e5da5Sopenharmony_ci        %308 = OpExtInst %void %1 DebugLine %55 %uint_21 %uint_21 %uint_5 %uint_20
6823fd4e5da5Sopenharmony_ci               OpStore %81 %97
6824fd4e5da5Sopenharmony_ci        %309 = OpExtInst %void %1 DebugNoLine
6825fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugNoLine
6826fd4e5da5Sopenharmony_ci        %111 = OpExtInst %void %1 DebugNoScope
6827fd4e5da5Sopenharmony_ci;CHECK: {{%\w+}} = OpExtInst %void %1 DebugNoScope
6828fd4e5da5Sopenharmony_ci        %100 = OpCompositeExtract %v4float %97 0
6829fd4e5da5Sopenharmony_ci               OpStore %out_var_SV_Target0 %100
6830fd4e5da5Sopenharmony_ci               OpReturn
6831fd4e5da5Sopenharmony_ci               OpFunctionEnd
6832fd4e5da5Sopenharmony_ci)";
6833fd4e5da5Sopenharmony_ci
6834fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
6835fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
6836fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
6837fd4e5da5Sopenharmony_ci}
6838fd4e5da5Sopenharmony_ci
6839fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, ShaderDebugInfoGlobalDCE) {
6840fd4e5da5Sopenharmony_ci  // Verify that DebugGlobalVariable for eliminated private variable has
6841fd4e5da5Sopenharmony_ci  // variable operand replaced with DebugInfoNone.
6842fd4e5da5Sopenharmony_ci
6843fd4e5da5Sopenharmony_ci  const std::string text = R"(OpCapability Shader
6844fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_non_semantic_info"
6845fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
6846fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
6847fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %MainPs "MainPs" %out_var_SV_Target0 %a
6848fd4e5da5Sopenharmony_ciOpExecutionMode %MainPs OriginUpperLeft
6849fd4e5da5Sopenharmony_ci%5 = OpString "source2.hlsl"
6850fd4e5da5Sopenharmony_ci%24 = OpString "float"
6851fd4e5da5Sopenharmony_ci%29 = OpString "vColor"
6852fd4e5da5Sopenharmony_ci%33 = OpString "PS_OUTPUT"
6853fd4e5da5Sopenharmony_ci%37 = OpString "MainPs"
6854fd4e5da5Sopenharmony_ci%38 = OpString ""
6855fd4e5da5Sopenharmony_ci%42 = OpString "ps_output"
6856fd4e5da5Sopenharmony_ci%46 = OpString "a"
6857fd4e5da5Sopenharmony_ciOpName %a "a"
6858fd4e5da5Sopenharmony_ciOpName %out_var_SV_Target0 "out.var.SV_Target0"
6859fd4e5da5Sopenharmony_ciOpName %MainPs "MainPs"
6860fd4e5da5Sopenharmony_ciOpName %PS_OUTPUT "PS_OUTPUT"
6861fd4e5da5Sopenharmony_ciOpMemberName %PS_OUTPUT 0 "vColor"
6862fd4e5da5Sopenharmony_ciOpDecorate %out_var_SV_Target0 Location 0
6863fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
6864fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
6865fd4e5da5Sopenharmony_ci%8 = OpConstantNull %v4float
6866fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
6867fd4e5da5Sopenharmony_ci%10 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
6868fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
6869fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
6870fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
6871fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
6872fd4e5da5Sopenharmony_ci%_ptr_Private_v4float = OpTypePointer Private %v4float
6873fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
6874fd4e5da5Sopenharmony_ci%void = OpTypeVoid
6875fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
6876fd4e5da5Sopenharmony_ci%uint_4 = OpConstant %uint 4
6877fd4e5da5Sopenharmony_ci%uint_5 = OpConstant %uint 5
6878fd4e5da5Sopenharmony_ci%uint_3 = OpConstant %uint 3
6879fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
6880fd4e5da5Sopenharmony_ci%uint_128 = OpConstant %uint 128
6881fd4e5da5Sopenharmony_ci%uint_12 = OpConstant %uint 12
6882fd4e5da5Sopenharmony_ci%uint_8 = OpConstant %uint 8
6883fd4e5da5Sopenharmony_ci%uint_9 = OpConstant %uint 9
6884fd4e5da5Sopenharmony_ci%uint_10 = OpConstant %uint 10
6885fd4e5da5Sopenharmony_ci%uint_15 = OpConstant %uint 15
6886fd4e5da5Sopenharmony_ci%48 = OpTypeFunction %void
6887fd4e5da5Sopenharmony_ci%PS_OUTPUT = OpTypeStruct %v4float
6888fd4e5da5Sopenharmony_ci%54 = OpTypeFunction %PS_OUTPUT
6889fd4e5da5Sopenharmony_ci%_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
6890fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
6891fd4e5da5Sopenharmony_ci%a = OpVariable %_ptr_Private_v4float Private
6892fd4e5da5Sopenharmony_ci;CHECK-NOT: %a = OpVariable %_ptr_Private_v4float Private
6893fd4e5da5Sopenharmony_ci%out_var_SV_Target0 = OpVariable %_ptr_Output_v4float Output
6894fd4e5da5Sopenharmony_ci;CHECK: [[dbg_none:%\w+]] = OpExtInst %void %1 DebugInfoNone
6895fd4e5da5Sopenharmony_ci%18 = OpExtInst %void %1 DebugExpression
6896fd4e5da5Sopenharmony_ci%19 = OpExtInst %void %1 DebugSource %5
6897fd4e5da5Sopenharmony_ci%20 = OpExtInst %void %1 DebugCompilationUnit %uint_1 %uint_4 %19 %uint_5
6898fd4e5da5Sopenharmony_ci%25 = OpExtInst %void %1 DebugTypeBasic %24 %uint_32 %uint_3 %uint_0
6899fd4e5da5Sopenharmony_ci%28 = OpExtInst %void %1 DebugTypeVector %25 %uint_4
6900fd4e5da5Sopenharmony_ci%31 = OpExtInst %void %1 DebugTypeMember %29 %28 %19 %uint_5 %uint_12 %uint_0 %uint_128 %uint_3
6901fd4e5da5Sopenharmony_ci%34 = OpExtInst %void %1 DebugTypeComposite %33 %uint_1 %19 %uint_3 %uint_8 %20 %33 %uint_128 %uint_3 %31
6902fd4e5da5Sopenharmony_ci%36 = OpExtInst %void %1 DebugTypeFunction %uint_3 %34
6903fd4e5da5Sopenharmony_ci%39 = OpExtInst %void %1 DebugFunction %37 %36 %19 %uint_8 %uint_1 %20 %38 %uint_3 %uint_9
6904fd4e5da5Sopenharmony_ci%41 = OpExtInst %void %1 DebugLexicalBlock %19 %uint_9 %uint_1 %39
6905fd4e5da5Sopenharmony_ci%43 = OpExtInst %void %1 DebugLocalVariable %42 %34 %19 %uint_10 %uint_15 %41 %uint_4
6906fd4e5da5Sopenharmony_ci%47 = OpExtInst %void %1 DebugGlobalVariable %46 %28 %19 %uint_1 %uint_15 %20 %46 %a %uint_8
6907fd4e5da5Sopenharmony_ci;CHECK: %47 = OpExtInst %void %1 DebugGlobalVariable %46 %28 %19 %uint_1 %uint_15 %20 %46 [[dbg_none]] %uint_8
6908fd4e5da5Sopenharmony_ci%MainPs = OpFunction %void None %48
6909fd4e5da5Sopenharmony_ci%49 = OpLabel
6910fd4e5da5Sopenharmony_ci%65 = OpVariable %_ptr_Function_PS_OUTPUT Function
6911fd4e5da5Sopenharmony_ci%66 = OpVariable %_ptr_Function_PS_OUTPUT Function
6912fd4e5da5Sopenharmony_ciOpStore %a %8
6913fd4e5da5Sopenharmony_ci%72 = OpExtInst %void %1 DebugScope %41
6914fd4e5da5Sopenharmony_ci%69 = OpExtInst %void %1 DebugDeclare %43 %65 %18
6915fd4e5da5Sopenharmony_ciOpLine %5 11 5
6916fd4e5da5Sopenharmony_ci%70 = OpAccessChain %_ptr_Function_v4float %65 %int_0
6917fd4e5da5Sopenharmony_ciOpStore %70 %10
6918fd4e5da5Sopenharmony_ciOpLine %5 12 12
6919fd4e5da5Sopenharmony_ci%71 = OpLoad %PS_OUTPUT %65
6920fd4e5da5Sopenharmony_ciOpLine %5 12 5
6921fd4e5da5Sopenharmony_ciOpStore %66 %71
6922fd4e5da5Sopenharmony_ci%73 = OpExtInst %void %1 DebugNoLine
6923fd4e5da5Sopenharmony_ci%74 = OpExtInst %void %1 DebugNoScope
6924fd4e5da5Sopenharmony_ci%51 = OpLoad %PS_OUTPUT %66
6925fd4e5da5Sopenharmony_ci%53 = OpCompositeExtract %v4float %51 0
6926fd4e5da5Sopenharmony_ciOpStore %out_var_SV_Target0 %53
6927fd4e5da5Sopenharmony_ciOpLine %5 13 1
6928fd4e5da5Sopenharmony_ciOpReturn
6929fd4e5da5Sopenharmony_ciOpFunctionEnd
6930fd4e5da5Sopenharmony_ci)";
6931fd4e5da5Sopenharmony_ci
6932fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
6933fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
6934fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
6935fd4e5da5Sopenharmony_ci}
6936fd4e5da5Sopenharmony_ci
6937fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DebugInfoDeclareKeepsStore) {
6938fd4e5da5Sopenharmony_ci  // Verify that local variable tc and its store are kept by DebugDeclare.
6939fd4e5da5Sopenharmony_ci  //
6940fd4e5da5Sopenharmony_ci  // Same shader source as DebugInfoInFunctionKeepStoreVarElim. The SPIR-V
6941fd4e5da5Sopenharmony_ci  // has just been inlined.
6942fd4e5da5Sopenharmony_ci
6943fd4e5da5Sopenharmony_ci  const std::string text = R"(
6944fd4e5da5Sopenharmony_ci               OpCapability Shader
6945fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "OpenCL.DebugInfo.100"
6946fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
6947fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %g_sAniso %in_var_TEXCOORD2 %out_var_SV_Target0
6948fd4e5da5Sopenharmony_ci               OpExecutionMode %MainPs OriginUpperLeft
6949fd4e5da5Sopenharmony_ci         %20 = OpString "foo.frag"
6950fd4e5da5Sopenharmony_ci         %24 = OpString "PS_OUTPUT"
6951fd4e5da5Sopenharmony_ci         %28 = OpString "float"
6952fd4e5da5Sopenharmony_ci         %31 = OpString "vColor"
6953fd4e5da5Sopenharmony_ci         %33 = OpString "PS_INPUT"
6954fd4e5da5Sopenharmony_ci         %38 = OpString "vTextureCoords"
6955fd4e5da5Sopenharmony_ci         %40 = OpString "@type.2d.image"
6956fd4e5da5Sopenharmony_ci         %41 = OpString "type.2d.image"
6957fd4e5da5Sopenharmony_ci         %43 = OpString "Texture2D.TemplateParam"
6958fd4e5da5Sopenharmony_ci         %47 = OpString "src.MainPs"
6959fd4e5da5Sopenharmony_ci         %51 = OpString "tc"
6960fd4e5da5Sopenharmony_ci         %53 = OpString "ps_output"
6961fd4e5da5Sopenharmony_ci         %56 = OpString "i"
6962fd4e5da5Sopenharmony_ci         %58 = OpString "@type.sampler"
6963fd4e5da5Sopenharmony_ci         %59 = OpString "type.sampler"
6964fd4e5da5Sopenharmony_ci         %61 = OpString "g_sAniso"
6965fd4e5da5Sopenharmony_ci         %63 = OpString "g_tColor"
6966fd4e5da5Sopenharmony_ci               OpName %type_2d_image "type.2d.image"
6967fd4e5da5Sopenharmony_ci               OpName %g_tColor "g_tColor"
6968fd4e5da5Sopenharmony_ci               OpName %type_sampler "type.sampler"
6969fd4e5da5Sopenharmony_ci               OpName %g_sAniso "g_sAniso"
6970fd4e5da5Sopenharmony_ci               OpName %in_var_TEXCOORD2 "in.var.TEXCOORD2"
6971fd4e5da5Sopenharmony_ci               OpName %out_var_SV_Target0 "out.var.SV_Target0"
6972fd4e5da5Sopenharmony_ci               OpName %MainPs "MainPs"
6973fd4e5da5Sopenharmony_ci               OpName %PS_INPUT "PS_INPUT"
6974fd4e5da5Sopenharmony_ci               OpMemberName %PS_INPUT 0 "vTextureCoords"
6975fd4e5da5Sopenharmony_ci               OpName %param_var_i "param.var.i"
6976fd4e5da5Sopenharmony_ci               OpName %PS_OUTPUT "PS_OUTPUT"
6977fd4e5da5Sopenharmony_ci               OpMemberName %PS_OUTPUT 0 "vColor"
6978fd4e5da5Sopenharmony_ci               OpName %type_sampled_image "type.sampled.image"
6979fd4e5da5Sopenharmony_ci               OpDecorate %in_var_TEXCOORD2 Location 0
6980fd4e5da5Sopenharmony_ci               OpDecorate %out_var_SV_Target0 Location 0
6981fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor DescriptorSet 0
6982fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor Binding 0
6983fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso DescriptorSet 0
6984fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso Binding 1
6985fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
6986fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
6987fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
6988fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
6989fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
6990fd4e5da5Sopenharmony_ci%type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
6991fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
6992fd4e5da5Sopenharmony_ci%type_sampler = OpTypeSampler
6993fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %type_sampler
6994fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
6995fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
6996fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
6997fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
6998fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
6999fd4e5da5Sopenharmony_ci   %uint_128 = OpConstant %uint 128
7000fd4e5da5Sopenharmony_ci     %uint_0 = OpConstant %uint 0
7001fd4e5da5Sopenharmony_ci    %uint_64 = OpConstant %uint 64
7002fd4e5da5Sopenharmony_ci         %65 = OpTypeFunction %void
7003fd4e5da5Sopenharmony_ci   %PS_INPUT = OpTypeStruct %v2float
7004fd4e5da5Sopenharmony_ci%_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
7005fd4e5da5Sopenharmony_ci  %PS_OUTPUT = OpTypeStruct %v4float
7006fd4e5da5Sopenharmony_ci         %75 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
7007fd4e5da5Sopenharmony_ci%_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
7008fd4e5da5Sopenharmony_ci%_ptr_Function_v2float = OpTypePointer Function %v2float
7009fd4e5da5Sopenharmony_ci%type_sampled_image = OpTypeSampledImage %type_2d_image
7010fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
7011fd4e5da5Sopenharmony_ci   %g_tColor = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
7012fd4e5da5Sopenharmony_ci   %g_sAniso = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
7013fd4e5da5Sopenharmony_ci%in_var_TEXCOORD2 = OpVariable %_ptr_Input_v2float Input
7014fd4e5da5Sopenharmony_ci%out_var_SV_Target0 = OpVariable %_ptr_Output_v4float Output
7015fd4e5da5Sopenharmony_ci         %39 = OpExtInst %void %1 DebugInfoNone
7016fd4e5da5Sopenharmony_ci         %55 = OpExtInst %void %1 DebugExpression
7017fd4e5da5Sopenharmony_ci         %22 = OpExtInst %void %1 DebugSource %20
7018fd4e5da5Sopenharmony_ci         %23 = OpExtInst %void %1 DebugCompilationUnit 1 4 %22 HLSL
7019fd4e5da5Sopenharmony_ci         %26 = OpExtInst %void %1 DebugTypeComposite %24 Structure %22 10 1 %23 %24 %uint_128 FlagIsProtected|FlagIsPrivate %27
7020fd4e5da5Sopenharmony_ci         %29 = OpExtInst %void %1 DebugTypeBasic %28 %uint_32 Float
7021fd4e5da5Sopenharmony_ci         %30 = OpExtInst %void %1 DebugTypeVector %29 4
7022fd4e5da5Sopenharmony_ci         %27 = OpExtInst %void %1 DebugTypeMember %31 %30 %22 12 5 %26 %uint_0 %uint_128 FlagIsProtected|FlagIsPrivate
7023fd4e5da5Sopenharmony_ci         %35 = OpExtInst %void %1 DebugTypeComposite %33 Structure %22 5 1 %23 %33 %uint_64 FlagIsProtected|FlagIsPrivate %36
7024fd4e5da5Sopenharmony_ci         %37 = OpExtInst %void %1 DebugTypeVector %29 2
7025fd4e5da5Sopenharmony_ci         %36 = OpExtInst %void %1 DebugTypeMember %38 %37 %22 7 5 %35 %uint_0 %uint_64 FlagIsProtected|FlagIsPrivate
7026fd4e5da5Sopenharmony_ci         %42 = OpExtInst %void %1 DebugTypeComposite %40 Class %22 0 0 %23 %41 %39 FlagIsProtected|FlagIsPrivate
7027fd4e5da5Sopenharmony_ci         %44 = OpExtInst %void %1 DebugTypeTemplateParameter %43 %29 %39 %22 0 0
7028fd4e5da5Sopenharmony_ci         %45 = OpExtInst %void %1 DebugTypeTemplate %42 %44
7029fd4e5da5Sopenharmony_ci         %46 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %26 %35
7030fd4e5da5Sopenharmony_ci         %48 = OpExtInst %void %1 DebugFunction %47 %46 %22 15 1 %23 %47 FlagIsProtected|FlagIsPrivate 16 %39
7031fd4e5da5Sopenharmony_ci         %50 = OpExtInst %void %1 DebugLexicalBlock %22 16 1 %48
7032fd4e5da5Sopenharmony_ci         %52 = OpExtInst %void %1 DebugLocalVariable %51 %37 %22 19 12 %50 FlagIsLocal
7033fd4e5da5Sopenharmony_ci         %54 = OpExtInst %void %1 DebugLocalVariable %53 %26 %22 17 15 %50 FlagIsLocal
7034fd4e5da5Sopenharmony_ci         %57 = OpExtInst %void %1 DebugLocalVariable %56 %35 %22 15 29 %48 FlagIsLocal 1
7035fd4e5da5Sopenharmony_ci         %60 = OpExtInst %void %1 DebugTypeComposite %58 Structure %22 0 0 %23 %59 %39 FlagIsProtected|FlagIsPrivate
7036fd4e5da5Sopenharmony_ci         %62 = OpExtInst %void %1 DebugGlobalVariable %61 %60 %22 3 14 %23 %61 %g_sAniso FlagIsDefinition
7037fd4e5da5Sopenharmony_ci         %64 = OpExtInst %void %1 DebugGlobalVariable %63 %42 %22 1 11 %23 %63 %g_tColor FlagIsDefinition
7038fd4e5da5Sopenharmony_ci     %MainPs = OpFunction %void None %65
7039fd4e5da5Sopenharmony_ci         %66 = OpLabel
7040fd4e5da5Sopenharmony_ci        %114 = OpExtInst %void %1 DebugScope %50
7041fd4e5da5Sopenharmony_ci         %98 = OpVariable %_ptr_Function_PS_OUTPUT Function
7042fd4e5da5Sopenharmony_ci         %99 = OpVariable %_ptr_Function_v2float Function
7043fd4e5da5Sopenharmony_ci        %115 = OpExtInst %void %1 DebugNoScope
7044fd4e5da5Sopenharmony_ci        %100 = OpVariable %_ptr_Function_PS_OUTPUT Function
7045fd4e5da5Sopenharmony_ci%param_var_i = OpVariable %_ptr_Function_PS_INPUT Function
7046fd4e5da5Sopenharmony_ci         %70 = OpLoad %v2float %in_var_TEXCOORD2
7047fd4e5da5Sopenharmony_ci         %71 = OpCompositeConstruct %PS_INPUT %70
7048fd4e5da5Sopenharmony_ci               OpStore %param_var_i %71
7049fd4e5da5Sopenharmony_ci        %116 = OpExtInst %void %1 DebugScope %48
7050fd4e5da5Sopenharmony_ci        %102 = OpExtInst %void %1 DebugDeclare %57 %param_var_i %55
7051fd4e5da5Sopenharmony_ci        %117 = OpExtInst %void %1 DebugScope %50
7052fd4e5da5Sopenharmony_ci        %103 = OpExtInst %void %1 DebugDeclare %54 %98 %55
7053fd4e5da5Sopenharmony_ci               OpLine %20 19 17
7054fd4e5da5Sopenharmony_ci        %104 = OpAccessChain %_ptr_Function_v2float %param_var_i %int_0
7055fd4e5da5Sopenharmony_ci        %105 = OpLoad %v2float %104
7056fd4e5da5Sopenharmony_ci               OpLine %20 19 12
7057fd4e5da5Sopenharmony_ci               OpStore %99 %105
7058fd4e5da5Sopenharmony_ci;CHECK:        OpStore %99 %105
7059fd4e5da5Sopenharmony_ci        %106 = OpExtInst %void %1 DebugDeclare %52 %99 %55
7060fd4e5da5Sopenharmony_ci               OpLine %20 20 26
7061fd4e5da5Sopenharmony_ci        %107 = OpLoad %type_2d_image %g_tColor
7062fd4e5da5Sopenharmony_ci               OpLine %20 20 46
7063fd4e5da5Sopenharmony_ci        %108 = OpLoad %type_sampler %g_sAniso
7064fd4e5da5Sopenharmony_ci               OpLine %20 20 26
7065fd4e5da5Sopenharmony_ci        %110 = OpSampledImage %type_sampled_image %107 %108
7066fd4e5da5Sopenharmony_ci        %111 = OpImageSampleImplicitLod %v4float %110 %105 None
7067fd4e5da5Sopenharmony_ci               OpLine %20 20 5
7068fd4e5da5Sopenharmony_ci        %112 = OpAccessChain %_ptr_Function_v4float %98 %int_0
7069fd4e5da5Sopenharmony_ci               OpStore %112 %111
7070fd4e5da5Sopenharmony_ci               OpLine %20 21 12
7071fd4e5da5Sopenharmony_ci        %113 = OpLoad %PS_OUTPUT %98
7072fd4e5da5Sopenharmony_ci               OpLine %20 21 5
7073fd4e5da5Sopenharmony_ci               OpStore %100 %113
7074fd4e5da5Sopenharmony_ci        %118 = OpExtInst %void %1 DebugNoScope
7075fd4e5da5Sopenharmony_ci         %73 = OpLoad %PS_OUTPUT %100
7076fd4e5da5Sopenharmony_ci         %74 = OpCompositeExtract %v4float %73 0
7077fd4e5da5Sopenharmony_ci               OpStore %out_var_SV_Target0 %74
7078fd4e5da5Sopenharmony_ci               OpReturn
7079fd4e5da5Sopenharmony_ci               OpFunctionEnd
7080fd4e5da5Sopenharmony_ci)";
7081fd4e5da5Sopenharmony_ci
7082fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
7083fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7084fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
7085fd4e5da5Sopenharmony_ci}
7086fd4e5da5Sopenharmony_ci
7087fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DebugInfoValueDerefKeepsStore) {
7088fd4e5da5Sopenharmony_ci  // Verify that local variable tc and its store are kept by DebugValue with
7089fd4e5da5Sopenharmony_ci  // Deref.
7090fd4e5da5Sopenharmony_ci  //
7091fd4e5da5Sopenharmony_ci  // Same shader source as DebugInfoInFunctionKeepStoreVarElim. The SPIR-V
7092fd4e5da5Sopenharmony_ci  // has just been inlined and edited to replace the DebugDeclare with the
7093fd4e5da5Sopenharmony_ci  // DebugValue/Deref.
7094fd4e5da5Sopenharmony_ci
7095fd4e5da5Sopenharmony_ci  const std::string text = R"(
7096fd4e5da5Sopenharmony_ci               OpCapability Shader
7097fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "OpenCL.DebugInfo.100"
7098fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
7099fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %g_sAniso %in_var_TEXCOORD2 %out_var_SV_Target0
7100fd4e5da5Sopenharmony_ci               OpExecutionMode %MainPs OriginUpperLeft
7101fd4e5da5Sopenharmony_ci          %7 = OpString "foo.frag"
7102fd4e5da5Sopenharmony_ci          %8 = OpString "PS_OUTPUT"
7103fd4e5da5Sopenharmony_ci          %9 = OpString "float"
7104fd4e5da5Sopenharmony_ci         %10 = OpString "vColor"
7105fd4e5da5Sopenharmony_ci         %11 = OpString "PS_INPUT"
7106fd4e5da5Sopenharmony_ci         %12 = OpString "vTextureCoords"
7107fd4e5da5Sopenharmony_ci         %13 = OpString "@type.2d.image"
7108fd4e5da5Sopenharmony_ci         %14 = OpString "type.2d.image"
7109fd4e5da5Sopenharmony_ci         %15 = OpString "Texture2D.TemplateParam"
7110fd4e5da5Sopenharmony_ci         %16 = OpString "src.MainPs"
7111fd4e5da5Sopenharmony_ci         %17 = OpString "tc"
7112fd4e5da5Sopenharmony_ci         %18 = OpString "ps_output"
7113fd4e5da5Sopenharmony_ci         %19 = OpString "i"
7114fd4e5da5Sopenharmony_ci         %20 = OpString "@type.sampler"
7115fd4e5da5Sopenharmony_ci         %21 = OpString "type.sampler"
7116fd4e5da5Sopenharmony_ci         %22 = OpString "g_sAniso"
7117fd4e5da5Sopenharmony_ci         %23 = OpString "g_tColor"
7118fd4e5da5Sopenharmony_ci               OpName %type_2d_image "type.2d.image"
7119fd4e5da5Sopenharmony_ci               OpName %g_tColor "g_tColor"
7120fd4e5da5Sopenharmony_ci               OpName %type_sampler "type.sampler"
7121fd4e5da5Sopenharmony_ci               OpName %g_sAniso "g_sAniso"
7122fd4e5da5Sopenharmony_ci               OpName %in_var_TEXCOORD2 "in.var.TEXCOORD2"
7123fd4e5da5Sopenharmony_ci               OpName %out_var_SV_Target0 "out.var.SV_Target0"
7124fd4e5da5Sopenharmony_ci               OpName %MainPs "MainPs"
7125fd4e5da5Sopenharmony_ci               OpName %PS_INPUT "PS_INPUT"
7126fd4e5da5Sopenharmony_ci               OpMemberName %PS_INPUT 0 "vTextureCoords"
7127fd4e5da5Sopenharmony_ci               OpName %param_var_i "param.var.i"
7128fd4e5da5Sopenharmony_ci               OpName %PS_OUTPUT "PS_OUTPUT"
7129fd4e5da5Sopenharmony_ci               OpMemberName %PS_OUTPUT 0 "vColor"
7130fd4e5da5Sopenharmony_ci               OpName %type_sampled_image "type.sampled.image"
7131fd4e5da5Sopenharmony_ci               OpDecorate %in_var_TEXCOORD2 Location 0
7132fd4e5da5Sopenharmony_ci               OpDecorate %out_var_SV_Target0 Location 0
7133fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor DescriptorSet 0
7134fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor Binding 0
7135fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso DescriptorSet 0
7136fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso Binding 1
7137fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
7138fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
7139fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
7140fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
7141fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
7142fd4e5da5Sopenharmony_ci%type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
7143fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
7144fd4e5da5Sopenharmony_ci%type_sampler = OpTypeSampler
7145fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %type_sampler
7146fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
7147fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
7148fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
7149fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
7150fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
7151fd4e5da5Sopenharmony_ci   %uint_128 = OpConstant %uint 128
7152fd4e5da5Sopenharmony_ci     %uint_0 = OpConstant %uint 0
7153fd4e5da5Sopenharmony_ci    %uint_64 = OpConstant %uint 64
7154fd4e5da5Sopenharmony_ci         %45 = OpTypeFunction %void
7155fd4e5da5Sopenharmony_ci   %PS_INPUT = OpTypeStruct %v2float
7156fd4e5da5Sopenharmony_ci%_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
7157fd4e5da5Sopenharmony_ci  %PS_OUTPUT = OpTypeStruct %v4float
7158fd4e5da5Sopenharmony_ci         %47 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
7159fd4e5da5Sopenharmony_ci%_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
7160fd4e5da5Sopenharmony_ci%_ptr_Function_v2float = OpTypePointer Function %v2float
7161fd4e5da5Sopenharmony_ci%type_sampled_image = OpTypeSampledImage %type_2d_image
7162fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
7163fd4e5da5Sopenharmony_ci   %g_tColor = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
7164fd4e5da5Sopenharmony_ci   %g_sAniso = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
7165fd4e5da5Sopenharmony_ci%in_var_TEXCOORD2 = OpVariable %_ptr_Input_v2float Input
7166fd4e5da5Sopenharmony_ci%out_var_SV_Target0 = OpVariable %_ptr_Output_v4float Output
7167fd4e5da5Sopenharmony_ci         %51 = OpExtInst %void %1 DebugInfoNone
7168fd4e5da5Sopenharmony_ci         %52 = OpExtInst %void %1 DebugExpression
7169fd4e5da5Sopenharmony_ci         %53 = OpExtInst %void %1 DebugOperation Deref
7170fd4e5da5Sopenharmony_ci         %54 = OpExtInst %void %1 DebugExpression %53
7171fd4e5da5Sopenharmony_ci         %55 = OpExtInst %void %1 DebugSource %7
7172fd4e5da5Sopenharmony_ci         %56 = OpExtInst %void %1 DebugCompilationUnit 1 4 %55 HLSL
7173fd4e5da5Sopenharmony_ci         %57 = OpExtInst %void %1 DebugTypeComposite %8 Structure %55 10 1 %56 %8 %uint_128 FlagIsProtected|FlagIsPrivate %58
7174fd4e5da5Sopenharmony_ci         %59 = OpExtInst %void %1 DebugTypeBasic %9 %uint_32 Float
7175fd4e5da5Sopenharmony_ci         %60 = OpExtInst %void %1 DebugTypeVector %59 4
7176fd4e5da5Sopenharmony_ci         %58 = OpExtInst %void %1 DebugTypeMember %10 %60 %55 12 5 %57 %uint_0 %uint_128 FlagIsProtected|FlagIsPrivate
7177fd4e5da5Sopenharmony_ci         %61 = OpExtInst %void %1 DebugTypeComposite %11 Structure %55 5 1 %56 %11 %uint_64 FlagIsProtected|FlagIsPrivate %62
7178fd4e5da5Sopenharmony_ci         %63 = OpExtInst %void %1 DebugTypeVector %59 2
7179fd4e5da5Sopenharmony_ci         %62 = OpExtInst %void %1 DebugTypeMember %12 %63 %55 7 5 %61 %uint_0 %uint_64 FlagIsProtected|FlagIsPrivate
7180fd4e5da5Sopenharmony_ci         %64 = OpExtInst %void %1 DebugTypeComposite %13 Class %55 0 0 %56 %14 %51 FlagIsProtected|FlagIsPrivate
7181fd4e5da5Sopenharmony_ci         %65 = OpExtInst %void %1 DebugTypeTemplateParameter %15 %59 %51 %55 0 0
7182fd4e5da5Sopenharmony_ci         %66 = OpExtInst %void %1 DebugTypeTemplate %64 %65
7183fd4e5da5Sopenharmony_ci         %67 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %57 %61
7184fd4e5da5Sopenharmony_ci         %68 = OpExtInst %void %1 DebugFunction %16 %67 %55 15 1 %56 %16 FlagIsProtected|FlagIsPrivate 16 %51
7185fd4e5da5Sopenharmony_ci         %69 = OpExtInst %void %1 DebugLexicalBlock %55 16 1 %68
7186fd4e5da5Sopenharmony_ci         %70 = OpExtInst %void %1 DebugLocalVariable %17 %63 %55 19 12 %69 FlagIsLocal
7187fd4e5da5Sopenharmony_ci         %71 = OpExtInst %void %1 DebugLocalVariable %18 %57 %55 17 15 %69 FlagIsLocal
7188fd4e5da5Sopenharmony_ci         %72 = OpExtInst %void %1 DebugLocalVariable %19 %61 %55 15 29 %68 FlagIsLocal 1
7189fd4e5da5Sopenharmony_ci         %73 = OpExtInst %void %1 DebugTypeComposite %20 Structure %55 0 0 %56 %21 %51 FlagIsProtected|FlagIsPrivate
7190fd4e5da5Sopenharmony_ci         %74 = OpExtInst %void %1 DebugGlobalVariable %22 %73 %55 3 14 %56 %22 %g_sAniso FlagIsDefinition
7191fd4e5da5Sopenharmony_ci         %75 = OpExtInst %void %1 DebugGlobalVariable %23 %64 %55 1 11 %56 %23 %g_tColor FlagIsDefinition
7192fd4e5da5Sopenharmony_ci     %MainPs = OpFunction %void None %45
7193fd4e5da5Sopenharmony_ci         %76 = OpLabel
7194fd4e5da5Sopenharmony_ci        %101 = OpExtInst %void %1 DebugScope %69
7195fd4e5da5Sopenharmony_ci         %78 = OpVariable %_ptr_Function_PS_OUTPUT Function
7196fd4e5da5Sopenharmony_ci         %79 = OpVariable %_ptr_Function_v2float Function
7197fd4e5da5Sopenharmony_ci        %102 = OpExtInst %void %1 DebugNoScope
7198fd4e5da5Sopenharmony_ci         %81 = OpVariable %_ptr_Function_PS_OUTPUT Function
7199fd4e5da5Sopenharmony_ci%param_var_i = OpVariable %_ptr_Function_PS_INPUT Function
7200fd4e5da5Sopenharmony_ci         %82 = OpLoad %v2float %in_var_TEXCOORD2
7201fd4e5da5Sopenharmony_ci         %83 = OpCompositeConstruct %PS_INPUT %82
7202fd4e5da5Sopenharmony_ci               OpStore %param_var_i %83
7203fd4e5da5Sopenharmony_ci        %103 = OpExtInst %void %1 DebugScope %68
7204fd4e5da5Sopenharmony_ci         %85 = OpExtInst %void %1 DebugDeclare %72 %param_var_i %52
7205fd4e5da5Sopenharmony_ci        %104 = OpExtInst %void %1 DebugScope %69
7206fd4e5da5Sopenharmony_ci         %87 = OpExtInst %void %1 DebugDeclare %71 %78 %52
7207fd4e5da5Sopenharmony_ci               OpLine %7 19 17
7208fd4e5da5Sopenharmony_ci         %88 = OpAccessChain %_ptr_Function_v2float %param_var_i %int_0
7209fd4e5da5Sopenharmony_ci         %89 = OpLoad %v2float %88
7210fd4e5da5Sopenharmony_ci               OpLine %7 19 12
7211fd4e5da5Sopenharmony_ci               OpStore %79 %89
7212fd4e5da5Sopenharmony_ci;CHECK:        OpStore %79 %89
7213fd4e5da5Sopenharmony_ci         %90 = OpExtInst %void %1 DebugValue %70 %79 %54
7214fd4e5da5Sopenharmony_ci               OpLine %7 20 26
7215fd4e5da5Sopenharmony_ci         %91 = OpLoad %type_2d_image %g_tColor
7216fd4e5da5Sopenharmony_ci               OpLine %7 20 46
7217fd4e5da5Sopenharmony_ci         %92 = OpLoad %type_sampler %g_sAniso
7218fd4e5da5Sopenharmony_ci               OpLine %7 20 26
7219fd4e5da5Sopenharmony_ci         %94 = OpSampledImage %type_sampled_image %91 %92
7220fd4e5da5Sopenharmony_ci         %95 = OpImageSampleImplicitLod %v4float %94 %89 None
7221fd4e5da5Sopenharmony_ci               OpLine %7 20 5
7222fd4e5da5Sopenharmony_ci         %96 = OpAccessChain %_ptr_Function_v4float %78 %int_0
7223fd4e5da5Sopenharmony_ci               OpStore %96 %95
7224fd4e5da5Sopenharmony_ci               OpLine %7 21 12
7225fd4e5da5Sopenharmony_ci         %97 = OpLoad %PS_OUTPUT %78
7226fd4e5da5Sopenharmony_ci               OpLine %7 21 5
7227fd4e5da5Sopenharmony_ci               OpStore %81 %97
7228fd4e5da5Sopenharmony_ci        %105 = OpExtInst %void %1 DebugNoScope
7229fd4e5da5Sopenharmony_ci         %99 = OpLoad %PS_OUTPUT %81
7230fd4e5da5Sopenharmony_ci        %100 = OpCompositeExtract %v4float %99 0
7231fd4e5da5Sopenharmony_ci               OpStore %out_var_SV_Target0 %100
7232fd4e5da5Sopenharmony_ci               OpReturn
7233fd4e5da5Sopenharmony_ci               OpFunctionEnd
7234fd4e5da5Sopenharmony_ci)";
7235fd4e5da5Sopenharmony_ci
7236fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
7237fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7238fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
7239fd4e5da5Sopenharmony_ci}
7240fd4e5da5Sopenharmony_ci
7241fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, DebugInfoElimUnusedTextureKeepGlobalVariable) {
7242fd4e5da5Sopenharmony_ci  // Verify that unused texture g_tColor2 is eliminated but its
7243fd4e5da5Sopenharmony_ci  // DebugGlobalVariable is retained but with DebugInfoNone for its Variable.
7244fd4e5da5Sopenharmony_ci  //
7245fd4e5da5Sopenharmony_ci  // Same shader source as DebugInfoInFunctionKeepStoreVarElim but with unused
7246fd4e5da5Sopenharmony_ci  // g_tColor2 added.
7247fd4e5da5Sopenharmony_ci
7248fd4e5da5Sopenharmony_ci  const std::string text = R"(
7249fd4e5da5Sopenharmony_ci               OpCapability Shader
7250fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "OpenCL.DebugInfo.100"
7251fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
7252fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %MainPs "MainPs" %g_tColor %g_tColor2 %g_sAniso %in_var_TEXCOORD2 %out_var_SV_Target0
7253fd4e5da5Sopenharmony_ci               OpExecutionMode %MainPs OriginUpperLeft
7254fd4e5da5Sopenharmony_ci         %21 = OpString "foo6.frag"
7255fd4e5da5Sopenharmony_ci         %25 = OpString "PS_OUTPUT"
7256fd4e5da5Sopenharmony_ci         %29 = OpString "float"
7257fd4e5da5Sopenharmony_ci         %32 = OpString "vColor"
7258fd4e5da5Sopenharmony_ci         %34 = OpString "PS_INPUT"
7259fd4e5da5Sopenharmony_ci         %39 = OpString "vTextureCoords"
7260fd4e5da5Sopenharmony_ci         %41 = OpString "@type.2d.image"
7261fd4e5da5Sopenharmony_ci         %42 = OpString "type.2d.image"
7262fd4e5da5Sopenharmony_ci         %44 = OpString "Texture2D.TemplateParam"
7263fd4e5da5Sopenharmony_ci         %48 = OpString "src.MainPs"
7264fd4e5da5Sopenharmony_ci         %52 = OpString "tc"
7265fd4e5da5Sopenharmony_ci         %54 = OpString "ps_output"
7266fd4e5da5Sopenharmony_ci         %57 = OpString "i"
7267fd4e5da5Sopenharmony_ci         %59 = OpString "@type.sampler"
7268fd4e5da5Sopenharmony_ci         %60 = OpString "type.sampler"
7269fd4e5da5Sopenharmony_ci         %62 = OpString "g_sAniso"
7270fd4e5da5Sopenharmony_ci         %64 = OpString "g_tColor2"
7271fd4e5da5Sopenharmony_ci         %66 = OpString "g_tColor"
7272fd4e5da5Sopenharmony_ci               OpName %type_2d_image "type.2d.image"
7273fd4e5da5Sopenharmony_ci               OpName %g_tColor "g_tColor"
7274fd4e5da5Sopenharmony_ci               OpName %g_tColor2 "g_tColor2"
7275fd4e5da5Sopenharmony_ci               OpName %type_sampler "type.sampler"
7276fd4e5da5Sopenharmony_ci               OpName %g_sAniso "g_sAniso"
7277fd4e5da5Sopenharmony_ci               OpName %in_var_TEXCOORD2 "in.var.TEXCOORD2"
7278fd4e5da5Sopenharmony_ci               OpName %out_var_SV_Target0 "out.var.SV_Target0"
7279fd4e5da5Sopenharmony_ci               OpName %MainPs "MainPs"
7280fd4e5da5Sopenharmony_ci               OpName %PS_INPUT "PS_INPUT"
7281fd4e5da5Sopenharmony_ci               OpMemberName %PS_INPUT 0 "vTextureCoords"
7282fd4e5da5Sopenharmony_ci               OpName %param_var_i "param.var.i"
7283fd4e5da5Sopenharmony_ci               OpName %PS_OUTPUT "PS_OUTPUT"
7284fd4e5da5Sopenharmony_ci               OpMemberName %PS_OUTPUT 0 "vColor"
7285fd4e5da5Sopenharmony_ci               OpName %type_sampled_image "type.sampled.image"
7286fd4e5da5Sopenharmony_ci               OpDecorate %in_var_TEXCOORD2 Location 0
7287fd4e5da5Sopenharmony_ci               OpDecorate %out_var_SV_Target0 Location 0
7288fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor DescriptorSet 0
7289fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor Binding 0
7290fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor2 DescriptorSet 0
7291fd4e5da5Sopenharmony_ci               OpDecorate %g_tColor2 Binding 1
7292fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso DescriptorSet 0
7293fd4e5da5Sopenharmony_ci               OpDecorate %g_sAniso Binding 2
7294fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
7295fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
7296fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
7297fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
7298fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
7299fd4e5da5Sopenharmony_ci%type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
7300fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
7301fd4e5da5Sopenharmony_ci%type_sampler = OpTypeSampler
7302fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %type_sampler
7303fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
7304fd4e5da5Sopenharmony_ci%_ptr_Input_v2float = OpTypePointer Input %v2float
7305fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
7306fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
7307fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
7308fd4e5da5Sopenharmony_ci   %uint_128 = OpConstant %uint 128
7309fd4e5da5Sopenharmony_ci     %uint_0 = OpConstant %uint 0
7310fd4e5da5Sopenharmony_ci    %uint_64 = OpConstant %uint 64
7311fd4e5da5Sopenharmony_ci         %68 = OpTypeFunction %void
7312fd4e5da5Sopenharmony_ci   %PS_INPUT = OpTypeStruct %v2float
7313fd4e5da5Sopenharmony_ci%_ptr_Function_PS_INPUT = OpTypePointer Function %PS_INPUT
7314fd4e5da5Sopenharmony_ci  %PS_OUTPUT = OpTypeStruct %v4float
7315fd4e5da5Sopenharmony_ci         %78 = OpTypeFunction %PS_OUTPUT %_ptr_Function_PS_INPUT
7316fd4e5da5Sopenharmony_ci%_ptr_Function_PS_OUTPUT = OpTypePointer Function %PS_OUTPUT
7317fd4e5da5Sopenharmony_ci%_ptr_Function_v2float = OpTypePointer Function %v2float
7318fd4e5da5Sopenharmony_ci%type_sampled_image = OpTypeSampledImage %type_2d_image
7319fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
7320fd4e5da5Sopenharmony_ci   %g_tColor = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
7321fd4e5da5Sopenharmony_ci  %g_tColor2 = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
7322fd4e5da5Sopenharmony_ci;CHECK-NOT: %g_tColor2 = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
7323fd4e5da5Sopenharmony_ci   %g_sAniso = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
7324fd4e5da5Sopenharmony_ci%in_var_TEXCOORD2 = OpVariable %_ptr_Input_v2float Input
7325fd4e5da5Sopenharmony_ci%out_var_SV_Target0 = OpVariable %_ptr_Output_v4float Output
7326fd4e5da5Sopenharmony_ci         %40 = OpExtInst %void %1 DebugInfoNone
7327fd4e5da5Sopenharmony_ci         %56 = OpExtInst %void %1 DebugExpression
7328fd4e5da5Sopenharmony_ci         %23 = OpExtInst %void %1 DebugSource %21
7329fd4e5da5Sopenharmony_ci         %24 = OpExtInst %void %1 DebugCompilationUnit 1 4 %23 HLSL
7330fd4e5da5Sopenharmony_ci         %27 = OpExtInst %void %1 DebugTypeComposite %25 Structure %23 11 1 %24 %25 %uint_128 FlagIsProtected|FlagIsPrivate %28
7331fd4e5da5Sopenharmony_ci         %30 = OpExtInst %void %1 DebugTypeBasic %29 %uint_32 Float
7332fd4e5da5Sopenharmony_ci         %31 = OpExtInst %void %1 DebugTypeVector %30 4
7333fd4e5da5Sopenharmony_ci         %28 = OpExtInst %void %1 DebugTypeMember %32 %31 %23 13 5 %27 %uint_0 %uint_128 FlagIsProtected|FlagIsPrivate
7334fd4e5da5Sopenharmony_ci         %36 = OpExtInst %void %1 DebugTypeComposite %34 Structure %23 6 1 %24 %34 %uint_64 FlagIsProtected|FlagIsPrivate %37
7335fd4e5da5Sopenharmony_ci         %38 = OpExtInst %void %1 DebugTypeVector %30 2
7336fd4e5da5Sopenharmony_ci         %37 = OpExtInst %void %1 DebugTypeMember %39 %38 %23 8 5 %36 %uint_0 %uint_64 FlagIsProtected|FlagIsPrivate
7337fd4e5da5Sopenharmony_ci         %43 = OpExtInst %void %1 DebugTypeComposite %41 Class %23 0 0 %24 %42 %40 FlagIsProtected|FlagIsPrivate
7338fd4e5da5Sopenharmony_ci         %45 = OpExtInst %void %1 DebugTypeTemplateParameter %44 %30 %40 %23 0 0
7339fd4e5da5Sopenharmony_ci         %46 = OpExtInst %void %1 DebugTypeTemplate %43 %45
7340fd4e5da5Sopenharmony_ci         %47 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %27 %36
7341fd4e5da5Sopenharmony_ci         %49 = OpExtInst %void %1 DebugFunction %48 %47 %23 16 1 %24 %48 FlagIsProtected|FlagIsPrivate 17 %40
7342fd4e5da5Sopenharmony_ci         %51 = OpExtInst %void %1 DebugLexicalBlock %23 17 1 %49
7343fd4e5da5Sopenharmony_ci         %53 = OpExtInst %void %1 DebugLocalVariable %52 %38 %23 20 12 %51 FlagIsLocal
7344fd4e5da5Sopenharmony_ci         %55 = OpExtInst %void %1 DebugLocalVariable %54 %27 %23 18 15 %51 FlagIsLocal
7345fd4e5da5Sopenharmony_ci         %58 = OpExtInst %void %1 DebugLocalVariable %57 %36 %23 16 29 %49 FlagIsLocal 1
7346fd4e5da5Sopenharmony_ci         %61 = OpExtInst %void %1 DebugTypeComposite %59 Structure %23 0 0 %24 %60 %40 FlagIsProtected|FlagIsPrivate
7347fd4e5da5Sopenharmony_ci         %63 = OpExtInst %void %1 DebugGlobalVariable %62 %61 %23 4 14 %24 %62 %g_sAniso FlagIsDefinition
7348fd4e5da5Sopenharmony_ci         %65 = OpExtInst %void %1 DebugGlobalVariable %64 %43 %23 2 11 %24 %64 %g_tColor2 FlagIsDefinition
7349fd4e5da5Sopenharmony_ci;CHECK-NOT: %65 = OpExtInst %void %1 DebugGlobalVariable %64 %43 %23 2 11 %24 %64 %g_tColor2 FlagIsDefinition
7350fd4e5da5Sopenharmony_ci;CHECK:     %65 = OpExtInst %void %1 DebugGlobalVariable %64 %43 %23 2 11 %24 %64 %40 FlagIsDefinition
7351fd4e5da5Sopenharmony_ci         %67 = OpExtInst %void %1 DebugGlobalVariable %66 %43 %23 1 11 %24 %66 %g_tColor FlagIsDefinition
7352fd4e5da5Sopenharmony_ci     %MainPs = OpFunction %void None %68
7353fd4e5da5Sopenharmony_ci         %69 = OpLabel
7354fd4e5da5Sopenharmony_ci        %117 = OpExtInst %void %1 DebugScope %51
7355fd4e5da5Sopenharmony_ci        %101 = OpVariable %_ptr_Function_PS_OUTPUT Function
7356fd4e5da5Sopenharmony_ci        %102 = OpVariable %_ptr_Function_v2float Function
7357fd4e5da5Sopenharmony_ci        %118 = OpExtInst %void %1 DebugNoScope
7358fd4e5da5Sopenharmony_ci        %103 = OpVariable %_ptr_Function_PS_OUTPUT Function
7359fd4e5da5Sopenharmony_ci%param_var_i = OpVariable %_ptr_Function_PS_INPUT Function
7360fd4e5da5Sopenharmony_ci         %73 = OpLoad %v2float %in_var_TEXCOORD2
7361fd4e5da5Sopenharmony_ci         %74 = OpCompositeConstruct %PS_INPUT %73
7362fd4e5da5Sopenharmony_ci               OpStore %param_var_i %74
7363fd4e5da5Sopenharmony_ci        %119 = OpExtInst %void %1 DebugScope %49
7364fd4e5da5Sopenharmony_ci        %105 = OpExtInst %void %1 DebugDeclare %58 %param_var_i %56
7365fd4e5da5Sopenharmony_ci        %120 = OpExtInst %void %1 DebugScope %51
7366fd4e5da5Sopenharmony_ci        %106 = OpExtInst %void %1 DebugDeclare %55 %101 %56
7367fd4e5da5Sopenharmony_ci               OpLine %21 20 17
7368fd4e5da5Sopenharmony_ci        %107 = OpAccessChain %_ptr_Function_v2float %param_var_i %int_0
7369fd4e5da5Sopenharmony_ci        %108 = OpLoad %v2float %107
7370fd4e5da5Sopenharmony_ci               OpLine %21 20 12
7371fd4e5da5Sopenharmony_ci               OpStore %102 %108
7372fd4e5da5Sopenharmony_ci        %109 = OpExtInst %void %1 DebugDeclare %53 %102 %56
7373fd4e5da5Sopenharmony_ci               OpLine %21 21 26
7374fd4e5da5Sopenharmony_ci        %110 = OpLoad %type_2d_image %g_tColor
7375fd4e5da5Sopenharmony_ci               OpLine %21 21 46
7376fd4e5da5Sopenharmony_ci        %111 = OpLoad %type_sampler %g_sAniso
7377fd4e5da5Sopenharmony_ci               OpLine %21 21 57
7378fd4e5da5Sopenharmony_ci        %112 = OpLoad %v2float %102
7379fd4e5da5Sopenharmony_ci               OpLine %21 21 26
7380fd4e5da5Sopenharmony_ci        %113 = OpSampledImage %type_sampled_image %110 %111
7381fd4e5da5Sopenharmony_ci        %114 = OpImageSampleImplicitLod %v4float %113 %112 None
7382fd4e5da5Sopenharmony_ci               OpLine %21 21 5
7383fd4e5da5Sopenharmony_ci        %115 = OpAccessChain %_ptr_Function_v4float %101 %int_0
7384fd4e5da5Sopenharmony_ci               OpStore %115 %114
7385fd4e5da5Sopenharmony_ci               OpLine %21 22 12
7386fd4e5da5Sopenharmony_ci        %116 = OpLoad %PS_OUTPUT %101
7387fd4e5da5Sopenharmony_ci               OpLine %21 22 5
7388fd4e5da5Sopenharmony_ci               OpStore %103 %116
7389fd4e5da5Sopenharmony_ci        %121 = OpExtInst %void %1 DebugNoScope
7390fd4e5da5Sopenharmony_ci         %76 = OpLoad %PS_OUTPUT %103
7391fd4e5da5Sopenharmony_ci         %77 = OpCompositeExtract %v4float %76 0
7392fd4e5da5Sopenharmony_ci               OpStore %out_var_SV_Target0 %77
7393fd4e5da5Sopenharmony_ci               OpReturn
7394fd4e5da5Sopenharmony_ci               OpFunctionEnd
7395fd4e5da5Sopenharmony_ci)";
7396fd4e5da5Sopenharmony_ci
7397fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
7398fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7399fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
7400fd4e5da5Sopenharmony_ci}
7401fd4e5da5Sopenharmony_ci
7402fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, KeepDebugScopeParent) {
7403fd4e5da5Sopenharmony_ci  // Verify that local variable tc and its store are kept by DebugDeclare.
7404fd4e5da5Sopenharmony_ci  //
7405fd4e5da5Sopenharmony_ci  // Same shader source as DebugInfoInFunctionKeepStoreVarElim. The SPIR-V
7406fd4e5da5Sopenharmony_ci  // has just been inlined.
7407fd4e5da5Sopenharmony_ci
7408fd4e5da5Sopenharmony_ci  const std::string text = R"(
7409fd4e5da5Sopenharmony_ci               OpCapability Shader
7410fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "OpenCL.DebugInfo.100"
7411fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
7412fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %main "main" %out_var_SV_TARGET0
7413fd4e5da5Sopenharmony_ci               OpExecutionMode %main OriginUpperLeft
7414fd4e5da5Sopenharmony_ci         %11 = OpString "float"
7415fd4e5da5Sopenharmony_ci         %16 = OpString "t.hlsl"
7416fd4e5da5Sopenharmony_ci         %19 = OpString "src.main"
7417fd4e5da5Sopenharmony_ci               OpName %out_var_SV_TARGET0 "out.var.SV_TARGET0"
7418fd4e5da5Sopenharmony_ci               OpName %main "main"
7419fd4e5da5Sopenharmony_ci               OpDecorate %out_var_SV_TARGET0 Location 0
7420fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
7421fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
7422fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
7423fd4e5da5Sopenharmony_ci          %7 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
7424fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
7425fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
7426fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
7427fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
7428fd4e5da5Sopenharmony_ci         %23 = OpTypeFunction %void
7429fd4e5da5Sopenharmony_ci         %26 = OpTypeFunction %v4float
7430fd4e5da5Sopenharmony_ci%out_var_SV_TARGET0 = OpVariable %_ptr_Output_v4float Output
7431fd4e5da5Sopenharmony_ci%_ptr_Function_v4float = OpTypePointer Function %v4float
7432fd4e5da5Sopenharmony_ci         %33 = OpExtInst %void %1 DebugInfoNone
7433fd4e5da5Sopenharmony_ci         %13 = OpExtInst %void %1 DebugTypeBasic %11 %uint_32 Float
7434fd4e5da5Sopenharmony_ci         %14 = OpExtInst %void %1 DebugTypeVector %13 4
7435fd4e5da5Sopenharmony_ci         %15 = OpExtInst %void %1 DebugTypeFunction FlagIsProtected|FlagIsPrivate %14
7436fd4e5da5Sopenharmony_ci         %17 = OpExtInst %void %1 DebugSource %16
7437fd4e5da5Sopenharmony_ci         %18 = OpExtInst %void %1 DebugCompilationUnit 1 4 %17 HLSL
7438fd4e5da5Sopenharmony_ci         %20 = OpExtInst %void %1 DebugFunction %19 %15 %17 1 1 %18 %19 FlagIsProtected|FlagIsPrivate 2 %33
7439fd4e5da5Sopenharmony_ci         %22 = OpExtInst %void %1 DebugLexicalBlock %17 2 1 %20
7440fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %23
7441fd4e5da5Sopenharmony_ci         %24 = OpLabel
7442fd4e5da5Sopenharmony_ci         %31 = OpVariable %_ptr_Function_v4float Function
7443fd4e5da5Sopenharmony_ci; CHECK: [[block:%\w+]] = OpExtInst %void %1 DebugLexicalBlock
7444fd4e5da5Sopenharmony_ci; CHECK: DebugScope [[block]]
7445fd4e5da5Sopenharmony_ci         %34 = OpExtInst %void %1 DebugScope %22
7446fd4e5da5Sopenharmony_ci               OpLine %16 3 5
7447fd4e5da5Sopenharmony_ci               OpStore %31 %7
7448fd4e5da5Sopenharmony_ci               OpStore %out_var_SV_TARGET0 %7
7449fd4e5da5Sopenharmony_ci         %35 = OpExtInst %void %1 DebugNoScope
7450fd4e5da5Sopenharmony_ci               OpReturn
7451fd4e5da5Sopenharmony_ci               OpFunctionEnd
7452fd4e5da5Sopenharmony_ci)";
7453fd4e5da5Sopenharmony_ci
7454fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7455fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
7456fd4e5da5Sopenharmony_ci}
7457fd4e5da5Sopenharmony_ci
7458fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, KeepExportFunctions) {
7459fd4e5da5Sopenharmony_ci  // All functions are reachable.  In particular, ExportedFunc and Constant are
7460fd4e5da5Sopenharmony_ci  // reachable because ExportedFunc is exported.  Nothing should be removed.
7461fd4e5da5Sopenharmony_ci  const std::vector<const char*> text = {
7462fd4e5da5Sopenharmony_ci      // clang-format off
7463fd4e5da5Sopenharmony_ci               "OpCapability Shader",
7464fd4e5da5Sopenharmony_ci               "OpCapability Linkage",
7465fd4e5da5Sopenharmony_ci               "OpMemoryModel Logical GLSL450",
7466fd4e5da5Sopenharmony_ci               "OpEntryPoint Fragment %main \"main\"",
7467fd4e5da5Sopenharmony_ci               "OpName %main \"main\"",
7468fd4e5da5Sopenharmony_ci               "OpName %ExportedFunc \"ExportedFunc\"",
7469fd4e5da5Sopenharmony_ci               "OpName %Live \"Live\"",
7470fd4e5da5Sopenharmony_ci               "OpDecorate %ExportedFunc LinkageAttributes \"ExportedFunc\" Export",
7471fd4e5da5Sopenharmony_ci       "%void = OpTypeVoid",
7472fd4e5da5Sopenharmony_ci          "%7 = OpTypeFunction %void",
7473fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %7",
7474fd4e5da5Sopenharmony_ci         "%15 = OpLabel",
7475fd4e5da5Sopenharmony_ci               "OpReturn",
7476fd4e5da5Sopenharmony_ci               "OpFunctionEnd",
7477fd4e5da5Sopenharmony_ci"%ExportedFunc = OpFunction %void None %7",
7478fd4e5da5Sopenharmony_ci         "%19 = OpLabel",
7479fd4e5da5Sopenharmony_ci         "%16 = OpFunctionCall %void %Live",
7480fd4e5da5Sopenharmony_ci               "OpReturn",
7481fd4e5da5Sopenharmony_ci               "OpFunctionEnd",
7482fd4e5da5Sopenharmony_ci  "%Live = OpFunction %void None %7",
7483fd4e5da5Sopenharmony_ci         "%20 = OpLabel",
7484fd4e5da5Sopenharmony_ci               "OpReturn",
7485fd4e5da5Sopenharmony_ci               "OpFunctionEnd"
7486fd4e5da5Sopenharmony_ci      // clang-format on
7487fd4e5da5Sopenharmony_ci  };
7488fd4e5da5Sopenharmony_ci
7489fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7490fd4e5da5Sopenharmony_ci  std::string assembly = JoinAllInsts(text);
7491fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<AggressiveDCEPass>(
7492fd4e5da5Sopenharmony_ci      assembly, /* skip_nop = */ true, /* do_validation = */ false);
7493fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
7494fd4e5da5Sopenharmony_ci  EXPECT_EQ(assembly, std::get<0>(result));
7495fd4e5da5Sopenharmony_ci}
7496fd4e5da5Sopenharmony_ci
7497fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, KeepPrivateVarInExportFunctions) {
7498fd4e5da5Sopenharmony_ci  // The loads and stores from the private variable should not be removed
7499fd4e5da5Sopenharmony_ci  // because the functions are exported and could be called.
7500fd4e5da5Sopenharmony_ci  const std::string text = R"(OpCapability Shader
7501fd4e5da5Sopenharmony_ciOpCapability Linkage
7502fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
7503fd4e5da5Sopenharmony_ciOpSource HLSL 630
7504fd4e5da5Sopenharmony_ciOpName %privateVar "privateVar"
7505fd4e5da5Sopenharmony_ciOpName %ReadPrivate "ReadPrivate"
7506fd4e5da5Sopenharmony_ciOpName %WritePrivate "WritePrivate"
7507fd4e5da5Sopenharmony_ciOpName %value "value"
7508fd4e5da5Sopenharmony_ciOpDecorate %ReadPrivate LinkageAttributes "ReadPrivate" Export
7509fd4e5da5Sopenharmony_ciOpDecorate %WritePrivate LinkageAttributes "WritePrivate" Export
7510fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
7511fd4e5da5Sopenharmony_ci%_ptr_Private_int = OpTypePointer Private %int
7512fd4e5da5Sopenharmony_ci%6 = OpTypeFunction %int
7513fd4e5da5Sopenharmony_ci%void = OpTypeVoid
7514fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
7515fd4e5da5Sopenharmony_ci%10 = OpTypeFunction %void %_ptr_Function_int
7516fd4e5da5Sopenharmony_ci%privateVar = OpVariable %_ptr_Private_int Private
7517fd4e5da5Sopenharmony_ci%ReadPrivate = OpFunction %int None %6
7518fd4e5da5Sopenharmony_ci%12 = OpLabel
7519fd4e5da5Sopenharmony_ci%8 = OpLoad %int %privateVar
7520fd4e5da5Sopenharmony_ciOpReturnValue %8
7521fd4e5da5Sopenharmony_ciOpFunctionEnd
7522fd4e5da5Sopenharmony_ci%WritePrivate = OpFunction %void None %10
7523fd4e5da5Sopenharmony_ci%value = OpFunctionParameter %_ptr_Function_int
7524fd4e5da5Sopenharmony_ci%13 = OpLabel
7525fd4e5da5Sopenharmony_ci%14 = OpLoad %int %value
7526fd4e5da5Sopenharmony_ciOpStore %privateVar %14
7527fd4e5da5Sopenharmony_ciOpReturn
7528fd4e5da5Sopenharmony_ciOpFunctionEnd
7529fd4e5da5Sopenharmony_ci)";
7530fd4e5da5Sopenharmony_ci
7531fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7532fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<AggressiveDCEPass>(
7533fd4e5da5Sopenharmony_ci      text, /* skip_nop = */ true, /* do_validation = */ false);
7534fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
7535fd4e5da5Sopenharmony_ci  EXPECT_EQ(text, std::get<0>(result));
7536fd4e5da5Sopenharmony_ci}
7537fd4e5da5Sopenharmony_ci
7538fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, KeepLableNames) {
7539fd4e5da5Sopenharmony_ci  const std::string text = R"(OpCapability Shader
7540fd4e5da5Sopenharmony_ciOpCapability Linkage
7541fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
7542fd4e5da5Sopenharmony_ciOpSource HLSL 630
7543fd4e5da5Sopenharmony_ciOpName %WritePrivate "WritePrivate"
7544fd4e5da5Sopenharmony_ciOpName %entry "entry"
7545fd4e5da5Sopenharmony_ciOpName %target "target"
7546fd4e5da5Sopenharmony_ciOpDecorate %WritePrivate LinkageAttributes "WritePrivate" Export
7547fd4e5da5Sopenharmony_ci%void = OpTypeVoid
7548fd4e5da5Sopenharmony_ci%3 = OpTypeFunction %void
7549fd4e5da5Sopenharmony_ci%WritePrivate = OpFunction %void None %3
7550fd4e5da5Sopenharmony_ci%entry = OpLabel
7551fd4e5da5Sopenharmony_ciOpBranch %target
7552fd4e5da5Sopenharmony_ci%target = OpLabel
7553fd4e5da5Sopenharmony_ciOpReturn
7554fd4e5da5Sopenharmony_ciOpFunctionEnd
7555fd4e5da5Sopenharmony_ci)";
7556fd4e5da5Sopenharmony_ci
7557fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7558fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<AggressiveDCEPass>(
7559fd4e5da5Sopenharmony_ci      text, /* skip_nop = */ true, /* do_validation = */ false);
7560fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
7561fd4e5da5Sopenharmony_ci  EXPECT_EQ(text, std::get<0>(result));
7562fd4e5da5Sopenharmony_ci}
7563fd4e5da5Sopenharmony_ci
7564fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, PreserveInterface) {
7565fd4e5da5Sopenharmony_ci  // Set preserve_interface to true. Verify that unused uniform
7566fd4e5da5Sopenharmony_ci  // constant in entry point interface is not eliminated.
7567fd4e5da5Sopenharmony_ci  const std::string text = R"(OpCapability RayTracingKHR
7568fd4e5da5Sopenharmony_ciOpExtension "SPV_KHR_ray_tracing"
7569fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
7570fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
7571fd4e5da5Sopenharmony_ciOpEntryPoint RayGenerationNV %2 "main" %3 %4
7572fd4e5da5Sopenharmony_ciOpDecorate %3 Location 0
7573fd4e5da5Sopenharmony_ciOpDecorate %4 DescriptorSet 2
7574fd4e5da5Sopenharmony_ciOpDecorate %4 Binding 0
7575fd4e5da5Sopenharmony_ci%void = OpTypeVoid
7576fd4e5da5Sopenharmony_ci%6 = OpTypeFunction %void
7577fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
7578fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
7579fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
7580fd4e5da5Sopenharmony_ci%_ptr_CallableDataNV_float = OpTypePointer CallableDataNV %float
7581fd4e5da5Sopenharmony_ci%3 = OpVariable %_ptr_CallableDataNV_float CallableDataNV
7582fd4e5da5Sopenharmony_ci%13 = OpTypeAccelerationStructureKHR
7583fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_13 = OpTypePointer UniformConstant %13
7584fd4e5da5Sopenharmony_ci%4 = OpVariable %_ptr_UniformConstant_13 UniformConstant
7585fd4e5da5Sopenharmony_ci%2 = OpFunction %void None %6
7586fd4e5da5Sopenharmony_ci%15 = OpLabel
7587fd4e5da5Sopenharmony_ciOpExecuteCallableKHR %uint_0 %3
7588fd4e5da5Sopenharmony_ciOpReturn
7589fd4e5da5Sopenharmony_ciOpFunctionEnd
7590fd4e5da5Sopenharmony_ci)";
7591fd4e5da5Sopenharmony_ci
7592fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
7593fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7594fd4e5da5Sopenharmony_ci  auto result = SinglePassRunAndDisassemble<AggressiveDCEPass>(
7595fd4e5da5Sopenharmony_ci      text, /* skip_nop = */ true, /* do_validation = */ false,
7596fd4e5da5Sopenharmony_ci      /* preserve_interface */ true);
7597fd4e5da5Sopenharmony_ci  EXPECT_EQ(Pass::Status::SuccessWithoutChange, std::get<1>(result));
7598fd4e5da5Sopenharmony_ci  EXPECT_EQ(text, std::get<0>(result));
7599fd4e5da5Sopenharmony_ci}
7600fd4e5da5Sopenharmony_ci
7601fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, EmptyContinueWithConditionalBranch) {
7602fd4e5da5Sopenharmony_ci  const std::string text = R"(OpCapability Shader
7603fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
7604fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
7605fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %2 "main"
7606fd4e5da5Sopenharmony_ciOpExecutionMode %2 OriginUpperLeft
7607fd4e5da5Sopenharmony_ci%void = OpTypeVoid
7608fd4e5da5Sopenharmony_ci%4 = OpTypeFunction %void
7609fd4e5da5Sopenharmony_ci%bool = OpTypeBool
7610fd4e5da5Sopenharmony_ci%false = OpConstantFalse %bool
7611fd4e5da5Sopenharmony_ci%2 = OpFunction %void None %4
7612fd4e5da5Sopenharmony_ci%9 = OpLabel
7613fd4e5da5Sopenharmony_ciOpBranch %10
7614fd4e5da5Sopenharmony_ci%10 = OpLabel
7615fd4e5da5Sopenharmony_ciOpLoopMerge %11 %12 None
7616fd4e5da5Sopenharmony_ciOpBranch %13
7617fd4e5da5Sopenharmony_ci%13 = OpLabel
7618fd4e5da5Sopenharmony_ciOpKill
7619fd4e5da5Sopenharmony_ci%12 = OpLabel
7620fd4e5da5Sopenharmony_ciOpBranchConditional %false %10 %10
7621fd4e5da5Sopenharmony_ci%11 = OpLabel
7622fd4e5da5Sopenharmony_ciOpUnreachable
7623fd4e5da5Sopenharmony_ciOpFunctionEnd
7624fd4e5da5Sopenharmony_ci)";
7625fd4e5da5Sopenharmony_ci
7626fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
7627fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7628fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(text, text, false);
7629fd4e5da5Sopenharmony_ci}
7630fd4e5da5Sopenharmony_ci
7631fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, FunctionBecomesUnreachableAfterDCE) {
7632fd4e5da5Sopenharmony_ci  const std::string text = R"(
7633fd4e5da5Sopenharmony_ci               OpCapability Shader
7634fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
7635fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
7636fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %2 "main"
7637fd4e5da5Sopenharmony_ci               OpExecutionMode %2 OriginUpperLeft
7638fd4e5da5Sopenharmony_ci               OpSource ESSL 320
7639fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
7640fd4e5da5Sopenharmony_ci          %4 = OpTypeFunction %void
7641fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
7642fd4e5da5Sopenharmony_ci%_ptr_Function_int = OpTypePointer Function %int
7643fd4e5da5Sopenharmony_ci          %7 = OpTypeFunction %int
7644fd4e5da5Sopenharmony_ci     %int_n1 = OpConstant %int -1
7645fd4e5da5Sopenharmony_ci          %2 = OpFunction %void None %4
7646fd4e5da5Sopenharmony_ci          %9 = OpLabel
7647fd4e5da5Sopenharmony_ci               OpKill
7648fd4e5da5Sopenharmony_ci         %10 = OpLabel
7649fd4e5da5Sopenharmony_ci         %11 = OpFunctionCall %int %12
7650fd4e5da5Sopenharmony_ci               OpReturn
7651fd4e5da5Sopenharmony_ci               OpFunctionEnd
7652fd4e5da5Sopenharmony_ci; CHECK: {{%\w+}} = OpFunction %int DontInline|Pure
7653fd4e5da5Sopenharmony_ci         %12 = OpFunction %int DontInline|Pure %7
7654fd4e5da5Sopenharmony_ci; CHECK-NEXT: {{%\w+}} = OpLabel
7655fd4e5da5Sopenharmony_ci         %13 = OpLabel
7656fd4e5da5Sopenharmony_ci         %14 = OpVariable %_ptr_Function_int Function
7657fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[header:%\w+]]
7658fd4e5da5Sopenharmony_ci               OpBranch %15
7659fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[header]] = OpLabel
7660fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpBranch [[merge:%\w+]]
7661fd4e5da5Sopenharmony_ci         %15 = OpLabel
7662fd4e5da5Sopenharmony_ci               OpLoopMerge %16 %17 None
7663fd4e5da5Sopenharmony_ci               OpBranch %18
7664fd4e5da5Sopenharmony_ci         %18 = OpLabel
7665fd4e5da5Sopenharmony_ci         %19 = OpLoad %int %14
7666fd4e5da5Sopenharmony_ci               OpBranch %17
7667fd4e5da5Sopenharmony_ci         %17 = OpLabel
7668fd4e5da5Sopenharmony_ci               OpBranch %15
7669fd4e5da5Sopenharmony_ci; CHECK-NEXT: [[merge]] = OpLabel
7670fd4e5da5Sopenharmony_ci         %16 = OpLabel
7671fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpReturnValue %int_n1
7672fd4e5da5Sopenharmony_ci               OpReturnValue %int_n1
7673fd4e5da5Sopenharmony_ci; CHECK-NEXT: OpFunctionEnd
7674fd4e5da5Sopenharmony_ci               OpFunctionEnd
7675fd4e5da5Sopenharmony_ci)";
7676fd4e5da5Sopenharmony_ci
7677fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
7678fd4e5da5Sopenharmony_ci}
7679fd4e5da5Sopenharmony_ci
7680fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, KeepTopLevelDebugInfo) {
7681fd4e5da5Sopenharmony_ci  // Don't eliminate DebugCompilationUnit, DebugSourceContinued, and
7682fd4e5da5Sopenharmony_ci  // DebugEntryPoint
7683fd4e5da5Sopenharmony_ci  const std::string text = R"(
7684fd4e5da5Sopenharmony_ci               OpCapability Shader
7685fd4e5da5Sopenharmony_ci               OpExtension "SPV_KHR_non_semantic_info"
7686fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
7687fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
7688fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %MainPs "MainPs" %out_var_SV_Target0
7689fd4e5da5Sopenharmony_ci               OpExecutionMode %MainPs OriginUpperLeft
7690fd4e5da5Sopenharmony_ci          %4 = OpString "foo2.frag"
7691fd4e5da5Sopenharmony_ci          %5 = OpString "
7692fd4e5da5Sopenharmony_cistruct PS_OUTPUT
7693fd4e5da5Sopenharmony_ci{
7694fd4e5da5Sopenharmony_ci    float4 vColor : SV_Target0 ;
7695fd4e5da5Sopenharmony_ci} ;
7696fd4e5da5Sopenharmony_ci
7697fd4e5da5Sopenharmony_ci"
7698fd4e5da5Sopenharmony_ci          %6 = OpString "
7699fd4e5da5Sopenharmony_ciPS_OUTPUT MainPs ( )
7700fd4e5da5Sopenharmony_ci{
7701fd4e5da5Sopenharmony_ci    PS_OUTPUT ps_output ;
7702fd4e5da5Sopenharmony_ci    ps_output . vColor = float4( 1.0, 0.0, 0.0, 0.0 );
7703fd4e5da5Sopenharmony_ci    return ps_output ;
7704fd4e5da5Sopenharmony_ci}
7705fd4e5da5Sopenharmony_ci
7706fd4e5da5Sopenharmony_ci"
7707fd4e5da5Sopenharmony_ci          %7 = OpString "float"
7708fd4e5da5Sopenharmony_ci          %8 = OpString "vColor"
7709fd4e5da5Sopenharmony_ci          %9 = OpString "PS_OUTPUT"
7710fd4e5da5Sopenharmony_ci         %10 = OpString "MainPs"
7711fd4e5da5Sopenharmony_ci         %11 = OpString ""
7712fd4e5da5Sopenharmony_ci         %12 = OpString "ps_output"
7713fd4e5da5Sopenharmony_ci         %13 = OpString "97a939fb"
7714fd4e5da5Sopenharmony_ci         %14 = OpString " foo2.frag -E MainPs -T ps_6_1 -spirv -fspv-target-env=vulkan1.2 -fspv-debug=vulkan-with-source -fcgl -Fo foo2.frag.nopt.spv -Qembed_debug"
7715fd4e5da5Sopenharmony_ci               OpName %out_var_SV_Target0 "out.var.SV_Target0"
7716fd4e5da5Sopenharmony_ci               OpName %MainPs "MainPs"
7717fd4e5da5Sopenharmony_ci               OpDecorate %out_var_SV_Target0 Location 0
7718fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
7719fd4e5da5Sopenharmony_ci    %float_1 = OpConstant %float 1
7720fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
7721fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
7722fd4e5da5Sopenharmony_ci         %23 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_0
7723fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
7724fd4e5da5Sopenharmony_ci      %int_0 = OpConstant %int 0
7725fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
7726fd4e5da5Sopenharmony_ci    %uint_32 = OpConstant %uint 32
7727fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
7728fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
7729fd4e5da5Sopenharmony_ci     %uint_1 = OpConstant %uint 1
7730fd4e5da5Sopenharmony_ci     %uint_4 = OpConstant %uint 4
7731fd4e5da5Sopenharmony_ci     %uint_5 = OpConstant %uint 5
7732fd4e5da5Sopenharmony_ci     %uint_3 = OpConstant %uint 3
7733fd4e5da5Sopenharmony_ci     %uint_0 = OpConstant %uint 0
7734fd4e5da5Sopenharmony_ci   %uint_128 = OpConstant %uint 128
7735fd4e5da5Sopenharmony_ci    %uint_12 = OpConstant %uint 12
7736fd4e5da5Sopenharmony_ci     %uint_2 = OpConstant %uint 2
7737fd4e5da5Sopenharmony_ci     %uint_8 = OpConstant %uint 8
7738fd4e5da5Sopenharmony_ci     %uint_7 = OpConstant %uint 7
7739fd4e5da5Sopenharmony_ci     %uint_9 = OpConstant %uint 9
7740fd4e5da5Sopenharmony_ci    %uint_15 = OpConstant %uint 15
7741fd4e5da5Sopenharmony_ci         %42 = OpTypeFunction %void
7742fd4e5da5Sopenharmony_ci    %uint_10 = OpConstant %uint 10
7743fd4e5da5Sopenharmony_ci    %uint_53 = OpConstant %uint 53
7744fd4e5da5Sopenharmony_ci%out_var_SV_Target0 = OpVariable %_ptr_Output_v4float Output
7745fd4e5da5Sopenharmony_ci         %49 = OpExtInst %void %1 DebugExpression
7746fd4e5da5Sopenharmony_ci         %50 = OpExtInst %void %1 DebugSource %4 %5
7747fd4e5da5Sopenharmony_ci         %51 = OpExtInst %void %1 DebugSourceContinued %6
7748fd4e5da5Sopenharmony_ci; CHECK:     %51 = OpExtInst %void %1 DebugSourceContinued %6
7749fd4e5da5Sopenharmony_ci         %52 = OpExtInst %void %1 DebugCompilationUnit %uint_1 %uint_4 %50 %uint_5
7750fd4e5da5Sopenharmony_ci; CHECK:     %52 = OpExtInst %void %1 DebugCompilationUnit %uint_1 %uint_4 %50 %uint_5
7751fd4e5da5Sopenharmony_ci         %53 = OpExtInst %void %1 DebugTypeBasic %7 %uint_32 %uint_3 %uint_0
7752fd4e5da5Sopenharmony_ci         %54 = OpExtInst %void %1 DebugTypeVector %53 %uint_4
7753fd4e5da5Sopenharmony_ci         %55 = OpExtInst %void %1 DebugTypeMember %8 %54 %50 %uint_4 %uint_12 %uint_0 %uint_128 %uint_3
7754fd4e5da5Sopenharmony_ci         %56 = OpExtInst %void %1 DebugTypeComposite %9 %uint_1 %50 %uint_2 %uint_8 %52 %9 %uint_128 %uint_3 %55
7755fd4e5da5Sopenharmony_ci         %57 = OpExtInst %void %1 DebugTypeFunction %uint_3 %56
7756fd4e5da5Sopenharmony_ci         %58 = OpExtInst %void %1 DebugFunction %10 %57 %50 %uint_7 %uint_1 %52 %11 %uint_3 %uint_8
7757fd4e5da5Sopenharmony_ci         %59 = OpExtInst %void %1 DebugLexicalBlock %50 %uint_8 %uint_1 %58
7758fd4e5da5Sopenharmony_ci         %60 = OpExtInst %void %1 DebugLocalVariable %12 %56 %50 %uint_9 %uint_15 %59 %uint_4
7759fd4e5da5Sopenharmony_ci         %61 = OpExtInst %void %1 DebugEntryPoint %58 %52 %13 %14
7760fd4e5da5Sopenharmony_ci; CHECK:     %61 = OpExtInst %void %1 DebugEntryPoint %58 %52 %13 %14
7761fd4e5da5Sopenharmony_ci     %MainPs = OpFunction %void None %42
7762fd4e5da5Sopenharmony_ci         %62 = OpLabel
7763fd4e5da5Sopenharmony_ci         %63 = OpExtInst %void %1 DebugFunctionDefinition %58 %MainPs
7764fd4e5da5Sopenharmony_ci        %112 = OpExtInst %void %1 DebugScope %59
7765fd4e5da5Sopenharmony_ci        %111 = OpExtInst %void %1 DebugLine %50 %uint_10 %uint_10 %uint_5 %uint_53
7766fd4e5da5Sopenharmony_ci        %110 = OpExtInst %void %1 DebugValue %60 %23 %49 %int_0
7767fd4e5da5Sopenharmony_ci        %113 = OpExtInst %void %1 DebugNoLine
7768fd4e5da5Sopenharmony_ci        %114 = OpExtInst %void %1 DebugNoScope
7769fd4e5da5Sopenharmony_ci               OpStore %out_var_SV_Target0 %23
7770fd4e5da5Sopenharmony_ci         %66 = OpExtInst %void %1 DebugLine %50 %uint_12 %uint_12 %uint_1 %uint_1
7771fd4e5da5Sopenharmony_ci               OpReturn
7772fd4e5da5Sopenharmony_ci               OpFunctionEnd
7773fd4e5da5Sopenharmony_ci)";
7774fd4e5da5Sopenharmony_ci
7775fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
7776fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7777fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
7778fd4e5da5Sopenharmony_ci}
7779fd4e5da5Sopenharmony_ci
7780fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, RemoveOutputTrue) {
7781fd4e5da5Sopenharmony_ci  // Remove dead n_out output variable from module
7782fd4e5da5Sopenharmony_ci  const std::string text = R"(
7783fd4e5da5Sopenharmony_ci               OpCapability Shader
7784fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
7785fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
7786fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %c_out %c_in %n_out
7787fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Vertex %main "main" %c_out %c_in
7788fd4e5da5Sopenharmony_ci               OpSource GLSL 450
7789fd4e5da5Sopenharmony_ci               OpName %main "main"
7790fd4e5da5Sopenharmony_ci               OpName %c_out "c_out"
7791fd4e5da5Sopenharmony_ci               OpName %c_in "c_in"
7792fd4e5da5Sopenharmony_ci               OpName %n_out "n_out"
7793fd4e5da5Sopenharmony_ci               OpDecorate %c_out Location 0
7794fd4e5da5Sopenharmony_ci               OpDecorate %c_in Location 0
7795fd4e5da5Sopenharmony_ci               OpDecorate %n_out Location 1
7796fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
7797fd4e5da5Sopenharmony_ci          %3 = OpTypeFunction %void
7798fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
7799fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
7800fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
7801fd4e5da5Sopenharmony_ci      %c_out = OpVariable %_ptr_Output_v4float Output
7802fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
7803fd4e5da5Sopenharmony_ci       %c_in = OpVariable %_ptr_Input_v4float Input
7804fd4e5da5Sopenharmony_ci    %v3float = OpTypeVector %float 3
7805fd4e5da5Sopenharmony_ci%_ptr_Output_v3float = OpTypePointer Output %v3float
7806fd4e5da5Sopenharmony_ci      %n_out = OpVariable %_ptr_Output_v3float Output
7807fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %3
7808fd4e5da5Sopenharmony_ci          %5 = OpLabel
7809fd4e5da5Sopenharmony_ci         %12 = OpLoad %v4float %c_in
7810fd4e5da5Sopenharmony_ci               OpStore %c_out %12
7811fd4e5da5Sopenharmony_ci               OpReturn
7812fd4e5da5Sopenharmony_ci               OpFunctionEnd
7813fd4e5da5Sopenharmony_ci)";
7814fd4e5da5Sopenharmony_ci
7815fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_3);
7816fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7817fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true, false, true);
7818fd4e5da5Sopenharmony_ci}
7819fd4e5da5Sopenharmony_ci
7820fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, RemoveOutputFalse) {
7821fd4e5da5Sopenharmony_ci  // Remove dead n_out output variable from module
7822fd4e5da5Sopenharmony_ci  const std::string text = R"(
7823fd4e5da5Sopenharmony_ci               OpCapability Shader
7824fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
7825fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
7826fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %main "main" %c_out %c_in %n_out
7827fd4e5da5Sopenharmony_ci;CHECK: OpEntryPoint Vertex %main "main" %c_out %c_in %n_out
7828fd4e5da5Sopenharmony_ci               OpSource GLSL 450
7829fd4e5da5Sopenharmony_ci               OpName %main "main"
7830fd4e5da5Sopenharmony_ci               OpName %c_out "c_out"
7831fd4e5da5Sopenharmony_ci               OpName %c_in "c_in"
7832fd4e5da5Sopenharmony_ci               OpName %n_out "n_out"
7833fd4e5da5Sopenharmony_ci               OpDecorate %c_out Location 0
7834fd4e5da5Sopenharmony_ci               OpDecorate %c_in Location 0
7835fd4e5da5Sopenharmony_ci               OpDecorate %n_out Location 1
7836fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
7837fd4e5da5Sopenharmony_ci          %3 = OpTypeFunction %void
7838fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
7839fd4e5da5Sopenharmony_ci    %v4float = OpTypeVector %float 4
7840fd4e5da5Sopenharmony_ci%_ptr_Output_v4float = OpTypePointer Output %v4float
7841fd4e5da5Sopenharmony_ci      %c_out = OpVariable %_ptr_Output_v4float Output
7842fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
7843fd4e5da5Sopenharmony_ci       %c_in = OpVariable %_ptr_Input_v4float Input
7844fd4e5da5Sopenharmony_ci    %v3float = OpTypeVector %float 3
7845fd4e5da5Sopenharmony_ci%_ptr_Output_v3float = OpTypePointer Output %v3float
7846fd4e5da5Sopenharmony_ci      %n_out = OpVariable %_ptr_Output_v3float Output
7847fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %3
7848fd4e5da5Sopenharmony_ci          %5 = OpLabel
7849fd4e5da5Sopenharmony_ci         %12 = OpLoad %v4float %c_in
7850fd4e5da5Sopenharmony_ci               OpStore %c_out %12
7851fd4e5da5Sopenharmony_ci               OpReturn
7852fd4e5da5Sopenharmony_ci               OpFunctionEnd
7853fd4e5da5Sopenharmony_ci)";
7854fd4e5da5Sopenharmony_ci
7855fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_3);
7856fd4e5da5Sopenharmony_ci  SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
7857fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true, false, false);
7858fd4e5da5Sopenharmony_ci}
7859fd4e5da5Sopenharmony_ci
7860fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, RemoveWhenUsingPrintfExtension) {
7861fd4e5da5Sopenharmony_ci  // Remove dead n_out output variable from module
7862fd4e5da5Sopenharmony_ci  const std::string text = R"(
7863fd4e5da5Sopenharmony_ci; CHECK: OpExtInstImport "NonSemantic.DebugPrintf"
7864fd4e5da5Sopenharmony_ci; CHECK-NOT: OpVariable
7865fd4e5da5Sopenharmony_ci               OpCapability Shader
7866fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "NonSemantic.DebugPrintf"
7867fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
7868fd4e5da5Sopenharmony_ci               OpEntryPoint GLCompute %main "main"
7869fd4e5da5Sopenharmony_ci               OpExecutionMode %main LocalSize 8 8 1
7870fd4e5da5Sopenharmony_ci               OpSource HLSL 660
7871fd4e5da5Sopenharmony_ci               OpName %main "main"
7872fd4e5da5Sopenharmony_ci       %uint = OpTypeInt 32 0
7873fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
7874fd4e5da5Sopenharmony_ci          %5 = OpTypeFunction %void
7875fd4e5da5Sopenharmony_ci%_ptr_Function_uint = OpTypePointer Function %uint
7876fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %5
7877fd4e5da5Sopenharmony_ci          %7 = OpLabel
7878fd4e5da5Sopenharmony_ci          %8 = OpVariable %_ptr_Function_uint Function
7879fd4e5da5Sopenharmony_ci               OpReturn
7880fd4e5da5Sopenharmony_ci               OpFunctionEnd
7881fd4e5da5Sopenharmony_ci)";
7882fd4e5da5Sopenharmony_ci
7883fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_3);
7884fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
7885fd4e5da5Sopenharmony_ci}
7886fd4e5da5Sopenharmony_ci
7887fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, FunctionReturnPointer) {
7888fd4e5da5Sopenharmony_ci  // Run DCE when a function returning a pointer to a reference is present
7889fd4e5da5Sopenharmony_ci
7890fd4e5da5Sopenharmony_ci  const std::string text = R"(
7891fd4e5da5Sopenharmony_ci               OpCapability Shader
7892fd4e5da5Sopenharmony_ci               OpCapability PhysicalStorageBufferAddresses
7893fd4e5da5Sopenharmony_ci          %1 = OpExtInstImport "GLSL.std.450"
7894fd4e5da5Sopenharmony_ci               OpMemoryModel PhysicalStorageBuffer64 GLSL450
7895fd4e5da5Sopenharmony_ci               OpEntryPoint Vertex %2 "main" %3 %4
7896fd4e5da5Sopenharmony_ci               OpSource GLSL 450
7897fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_EXT_buffer_reference"
7898fd4e5da5Sopenharmony_ci               OpSourceExtension "GL_EXT_scalar_block_layout"
7899fd4e5da5Sopenharmony_ci               OpName %4 "color"
7900fd4e5da5Sopenharmony_ci               OpMemberDecorate %5 0 Offset 0
7901fd4e5da5Sopenharmony_ci               OpDecorate %5 Block
7902fd4e5da5Sopenharmony_ci               OpMemberDecorate %7 0 Offset 0
7903fd4e5da5Sopenharmony_ci               OpDecorate %7 Block
7904fd4e5da5Sopenharmony_ci               OpDecorate %8 AliasedPointer
7905fd4e5da5Sopenharmony_ci               OpDecorate %4 Location 0
7906fd4e5da5Sopenharmony_ci          %9 = OpTypeVoid
7907fd4e5da5Sopenharmony_ci         %10 = OpTypeFunction %9
7908fd4e5da5Sopenharmony_ci               OpTypeForwardPointer %11 PhysicalStorageBuffer
7909fd4e5da5Sopenharmony_ci         %12 = OpTypeInt 32 0
7910fd4e5da5Sopenharmony_ci          %5 = OpTypeStruct %12
7911fd4e5da5Sopenharmony_ci         %11 = OpTypePointer PhysicalStorageBuffer %5
7912fd4e5da5Sopenharmony_ci;CHECK:         [[pt:%\w+]] = OpTypePointer PhysicalStorageBuffer {{%\w+}}
7913fd4e5da5Sopenharmony_ci         %13 = OpTypeFunction %11
7914fd4e5da5Sopenharmony_ci;CHECK:  [[pt_fn:%\w+]] = OpTypeFunction [[pt]]
7915fd4e5da5Sopenharmony_ci          %7 = OpTypeStruct %11
7916fd4e5da5Sopenharmony_ci         %14 = OpTypePointer PushConstant %7
7917fd4e5da5Sopenharmony_ci          %3 = OpVariable %14 PushConstant
7918fd4e5da5Sopenharmony_ci         %15 = OpTypeInt 32 1
7919fd4e5da5Sopenharmony_ci         %16 = OpConstant %15 0
7920fd4e5da5Sopenharmony_ci         %17 = OpTypePointer PushConstant %11
7921fd4e5da5Sopenharmony_ci         %18 = OpTypePointer Function %11
7922fd4e5da5Sopenharmony_ci         %19 = OpTypeFloat 32
7923fd4e5da5Sopenharmony_ci         %20 = OpTypeVector %19 4
7924fd4e5da5Sopenharmony_ci         %21 = OpTypePointer Output %20
7925fd4e5da5Sopenharmony_ci          %4 = OpVariable %21 Output
7926fd4e5da5Sopenharmony_ci         %22 = OpConstant %19 1
7927fd4e5da5Sopenharmony_ci         %23 = OpConstant %19 0
7928fd4e5da5Sopenharmony_ci         %24 = OpConstantComposite %20 %22 %23 %22 %22
7929fd4e5da5Sopenharmony_ci          %6 = OpFunction %11 None %13
7930fd4e5da5Sopenharmony_ci;CHECK:   [[fn:%\w+]] = OpFunction [[pt]] None [[pt_fn]]
7931fd4e5da5Sopenharmony_ci         %27 = OpLabel
7932fd4e5da5Sopenharmony_ci         %28 = OpAccessChain %17 %3 %16
7933fd4e5da5Sopenharmony_ci         %29 = OpLoad %11 %28
7934fd4e5da5Sopenharmony_ci               OpReturnValue %29
7935fd4e5da5Sopenharmony_ci               OpFunctionEnd
7936fd4e5da5Sopenharmony_ci          %2 = OpFunction %9 None %10
7937fd4e5da5Sopenharmony_ci         %25 = OpLabel
7938fd4e5da5Sopenharmony_ci          %8 = OpVariable %18 Function
7939fd4e5da5Sopenharmony_ci         %26 = OpFunctionCall %11 %6
7940fd4e5da5Sopenharmony_ci;CHECK:  {{%\w+}} = OpFunctionCall [[pt]] [[fn]]
7941fd4e5da5Sopenharmony_ci               OpStore %8 %26
7942fd4e5da5Sopenharmony_ci               OpStore %4 %24
7943fd4e5da5Sopenharmony_ci               OpReturn
7944fd4e5da5Sopenharmony_ci               OpFunctionEnd
7945fd4e5da5Sopenharmony_ci)";
7946fd4e5da5Sopenharmony_ci
7947fd4e5da5Sopenharmony_ci  // For physical storage buffer support
7948fd4e5da5Sopenharmony_ci  SetTargetEnv(SPV_ENV_VULKAN_1_2);
7949fd4e5da5Sopenharmony_ci  SinglePassRunAndMatch<AggressiveDCEPass>(text, true);
7950fd4e5da5Sopenharmony_ci}
7951fd4e5da5Sopenharmony_ci
7952fd4e5da5Sopenharmony_ciTEST_F(AggressiveDCETest, KeepBeginEndInvocationInterlock) {
7953fd4e5da5Sopenharmony_ci  // OpBeginInvocationInterlockEXT and OpEndInvocationInterlockEXT delimit a
7954fd4e5da5Sopenharmony_ci  // critical section. As such, they should be treated as if they have side
7955fd4e5da5Sopenharmony_ci  // effects and should not be removed.
7956fd4e5da5Sopenharmony_ci  const std::string test =
7957fd4e5da5Sopenharmony_ci      R"(OpCapability Shader
7958fd4e5da5Sopenharmony_ciOpCapability FragmentShaderSampleInterlockEXT
7959fd4e5da5Sopenharmony_ciOpExtension "SPV_EXT_fragment_shader_interlock"
7960fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
7961fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %1 "main" %gl_FragCoord
7962fd4e5da5Sopenharmony_ciOpExecutionMode %1 OriginUpperLeft
7963fd4e5da5Sopenharmony_ciOpExecutionMode %1 SampleInterlockOrderedEXT
7964fd4e5da5Sopenharmony_ciOpDecorate %gl_FragCoord BuiltIn FragCoord
7965fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
7966fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
7967fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
7968fd4e5da5Sopenharmony_ci%_ptr_Input_v4float = OpTypePointer Input %v4float
7969fd4e5da5Sopenharmony_ci%void = OpTypeVoid
7970fd4e5da5Sopenharmony_ci%8 = OpTypeFunction %void
7971fd4e5da5Sopenharmony_ci%bool = OpTypeBool
7972fd4e5da5Sopenharmony_ci%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
7973fd4e5da5Sopenharmony_ci%1 = OpFunction %void None %8
7974fd4e5da5Sopenharmony_ci%10 = OpLabel
7975fd4e5da5Sopenharmony_ci%11 = OpLoad %v4float %gl_FragCoord
7976fd4e5da5Sopenharmony_ci%12 = OpCompositeExtract %float %11 0
7977fd4e5da5Sopenharmony_ci%13 = OpFOrdGreaterThan %bool %12 %float_0
7978fd4e5da5Sopenharmony_ciOpSelectionMerge %14 None
7979fd4e5da5Sopenharmony_ciOpBranchConditional %13 %15 %16
7980fd4e5da5Sopenharmony_ci%15 = OpLabel
7981fd4e5da5Sopenharmony_ciOpBeginInvocationInterlockEXT
7982fd4e5da5Sopenharmony_ciOpBranch %14
7983fd4e5da5Sopenharmony_ci%16 = OpLabel
7984fd4e5da5Sopenharmony_ciOpBeginInvocationInterlockEXT
7985fd4e5da5Sopenharmony_ciOpBranch %14
7986fd4e5da5Sopenharmony_ci%14 = OpLabel
7987fd4e5da5Sopenharmony_ciOpEndInvocationInterlockEXT
7988fd4e5da5Sopenharmony_ciOpReturn
7989fd4e5da5Sopenharmony_ciOpFunctionEnd
7990fd4e5da5Sopenharmony_ci)";
7991fd4e5da5Sopenharmony_ci
7992fd4e5da5Sopenharmony_ci  SinglePassRunAndCheck<AggressiveDCEPass>(test, test, true, true);
7993fd4e5da5Sopenharmony_ci}
7994fd4e5da5Sopenharmony_ci
7995fd4e5da5Sopenharmony_ci}  // namespace
7996fd4e5da5Sopenharmony_ci}  // namespace opt
7997fd4e5da5Sopenharmony_ci}  // namespace spvtools
7998