1fd4e5da5Sopenharmony_ci// Copyright (c) 2016 Google Inc.
2fd4e5da5Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
3fd4e5da5Sopenharmony_ci// you may not use this file except in compliance with the License.
4fd4e5da5Sopenharmony_ci// You may obtain a copy of the License at
5fd4e5da5Sopenharmony_ci//
6fd4e5da5Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
7fd4e5da5Sopenharmony_ci//
8fd4e5da5Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
9fd4e5da5Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
10fd4e5da5Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11fd4e5da5Sopenharmony_ci// See the License for the specific language governing permissions and
12fd4e5da5Sopenharmony_ci// limitations under the License.
13fd4e5da5Sopenharmony_ci
14fd4e5da5Sopenharmony_ci#include "source/opt/fold.h"
15fd4e5da5Sopenharmony_ci
16fd4e5da5Sopenharmony_ci#include <limits>
17fd4e5da5Sopenharmony_ci#include <memory>
18fd4e5da5Sopenharmony_ci#include <string>
19fd4e5da5Sopenharmony_ci#include <unordered_set>
20fd4e5da5Sopenharmony_ci#include <vector>
21fd4e5da5Sopenharmony_ci
22fd4e5da5Sopenharmony_ci#include "effcee/effcee.h"
23fd4e5da5Sopenharmony_ci#include "gmock/gmock.h"
24fd4e5da5Sopenharmony_ci#include "gtest/gtest.h"
25fd4e5da5Sopenharmony_ci#include "source/opt/build_module.h"
26fd4e5da5Sopenharmony_ci#include "source/opt/def_use_manager.h"
27fd4e5da5Sopenharmony_ci#include "source/opt/ir_context.h"
28fd4e5da5Sopenharmony_ci#include "source/opt/module.h"
29fd4e5da5Sopenharmony_ci#include "spirv-tools/libspirv.hpp"
30fd4e5da5Sopenharmony_ci
31fd4e5da5Sopenharmony_cinamespace spvtools {
32fd4e5da5Sopenharmony_cinamespace opt {
33fd4e5da5Sopenharmony_cinamespace {
34fd4e5da5Sopenharmony_ci
35fd4e5da5Sopenharmony_ciusing ::testing::Contains;
36fd4e5da5Sopenharmony_ci
37fd4e5da5Sopenharmony_cistd::string Disassemble(const std::string& original, IRContext* context,
38fd4e5da5Sopenharmony_ci                        uint32_t disassemble_options = 0) {
39fd4e5da5Sopenharmony_ci  std::vector<uint32_t> optimized_bin;
40fd4e5da5Sopenharmony_ci  context->module()->ToBinary(&optimized_bin, true);
41fd4e5da5Sopenharmony_ci  spv_target_env target_env = SPV_ENV_UNIVERSAL_1_2;
42fd4e5da5Sopenharmony_ci  SpirvTools tools(target_env);
43fd4e5da5Sopenharmony_ci  std::string optimized_asm;
44fd4e5da5Sopenharmony_ci  EXPECT_TRUE(
45fd4e5da5Sopenharmony_ci      tools.Disassemble(optimized_bin, &optimized_asm, disassemble_options))
46fd4e5da5Sopenharmony_ci      << "Disassembling failed for shader:\n"
47fd4e5da5Sopenharmony_ci      << original << std::endl;
48fd4e5da5Sopenharmony_ci  return optimized_asm;
49fd4e5da5Sopenharmony_ci}
50fd4e5da5Sopenharmony_ci
51fd4e5da5Sopenharmony_civoid Match(const std::string& original, IRContext* context,
52fd4e5da5Sopenharmony_ci           uint32_t disassemble_options = 0) {
53fd4e5da5Sopenharmony_ci  std::string disassembly = Disassemble(original, context, disassemble_options);
54fd4e5da5Sopenharmony_ci  auto match_result = effcee::Match(disassembly, original);
55fd4e5da5Sopenharmony_ci  EXPECT_EQ(effcee::Result::Status::Ok, match_result.status())
56fd4e5da5Sopenharmony_ci      << match_result.message() << "\nChecking result:\n"
57fd4e5da5Sopenharmony_ci      << disassembly;
58fd4e5da5Sopenharmony_ci}
59fd4e5da5Sopenharmony_ci
60fd4e5da5Sopenharmony_citemplate <class ResultType>
61fd4e5da5Sopenharmony_cistruct InstructionFoldingCase {
62fd4e5da5Sopenharmony_ci  InstructionFoldingCase(const std::string& tb, uint32_t id, ResultType result)
63fd4e5da5Sopenharmony_ci      : test_body(tb), id_to_fold(id), expected_result(result) {}
64fd4e5da5Sopenharmony_ci
65fd4e5da5Sopenharmony_ci  std::string test_body;
66fd4e5da5Sopenharmony_ci  uint32_t id_to_fold;
67fd4e5da5Sopenharmony_ci  ResultType expected_result;
68fd4e5da5Sopenharmony_ci};
69fd4e5da5Sopenharmony_ci
70fd4e5da5Sopenharmony_ciusing IntegerInstructionFoldingTest =
71fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCase<uint32_t>>;
72fd4e5da5Sopenharmony_ci
73fd4e5da5Sopenharmony_ciTEST_P(IntegerInstructionFoldingTest, Case) {
74fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
75fd4e5da5Sopenharmony_ci
76fd4e5da5Sopenharmony_ci  // Build module.
77fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
78fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
79fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
80fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
81fd4e5da5Sopenharmony_ci
82fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
83fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
84fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
85fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
86fd4e5da5Sopenharmony_ci
87fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
88fd4e5da5Sopenharmony_ci  EXPECT_TRUE(succeeded);
89fd4e5da5Sopenharmony_ci  if (inst != nullptr) {
90fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpCopyObject);
91fd4e5da5Sopenharmony_ci    inst = def_use_mgr->GetDef(inst->GetSingleWordInOperand(0));
92fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpConstant);
93fd4e5da5Sopenharmony_ci    analysis::ConstantManager* const_mrg = context->get_constant_mgr();
94fd4e5da5Sopenharmony_ci    const analysis::Constant* constant = const_mrg->GetConstantFromInst(inst);
95fd4e5da5Sopenharmony_ci    // We expect to see either integer types or 16-bit float types here.
96fd4e5da5Sopenharmony_ci    EXPECT_TRUE((constant->AsIntConstant() != nullptr) ||
97fd4e5da5Sopenharmony_ci                ((constant->AsFloatConstant() != nullptr) &&
98fd4e5da5Sopenharmony_ci                 (constant->type()->AsFloat()->width() == 16)));
99fd4e5da5Sopenharmony_ci    const analysis::ScalarConstant* result =
100fd4e5da5Sopenharmony_ci        const_mrg->GetConstantFromInst(inst)->AsScalarConstant();
101fd4e5da5Sopenharmony_ci    EXPECT_NE(result, nullptr);
102fd4e5da5Sopenharmony_ci    if (result != nullptr) {
103fd4e5da5Sopenharmony_ci      EXPECT_EQ(result->GetU32BitValue(), tc.expected_result);
104fd4e5da5Sopenharmony_ci    }
105fd4e5da5Sopenharmony_ci  }
106fd4e5da5Sopenharmony_ci}
107fd4e5da5Sopenharmony_ci
108fd4e5da5Sopenharmony_ci// Returns a common SPIR-V header for all of the test that follow.
109fd4e5da5Sopenharmony_ci#define INT_0_ID 100
110fd4e5da5Sopenharmony_ci#define TRUE_ID 101
111fd4e5da5Sopenharmony_ci#define VEC2_0_ID 102
112fd4e5da5Sopenharmony_ci#define INT_7_ID 103
113fd4e5da5Sopenharmony_ci#define FLOAT_0_ID 104
114fd4e5da5Sopenharmony_ci#define DOUBLE_0_ID 105
115fd4e5da5Sopenharmony_ci#define VEC4_0_ID 106
116fd4e5da5Sopenharmony_ci#define DVEC4_0_ID 106
117fd4e5da5Sopenharmony_ci#define HALF_0_ID 108
118fd4e5da5Sopenharmony_ciconst std::string& Header() {
119fd4e5da5Sopenharmony_ci  static const std::string header = R"(OpCapability Shader
120fd4e5da5Sopenharmony_ciOpCapability Float16
121fd4e5da5Sopenharmony_ciOpCapability Float64
122fd4e5da5Sopenharmony_ciOpCapability Int8
123fd4e5da5Sopenharmony_ciOpCapability Int16
124fd4e5da5Sopenharmony_ciOpCapability Int64
125fd4e5da5Sopenharmony_ci%1 = OpExtInstImport "GLSL.std.450"
126fd4e5da5Sopenharmony_ciOpMemoryModel Logical GLSL450
127fd4e5da5Sopenharmony_ciOpEntryPoint Fragment %main "main"
128fd4e5da5Sopenharmony_ciOpExecutionMode %main OriginUpperLeft
129fd4e5da5Sopenharmony_ciOpSource GLSL 140
130fd4e5da5Sopenharmony_ciOpName %main "main"
131fd4e5da5Sopenharmony_ci%void = OpTypeVoid
132fd4e5da5Sopenharmony_ci%void_func = OpTypeFunction %void
133fd4e5da5Sopenharmony_ci%bool = OpTypeBool
134fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
135fd4e5da5Sopenharmony_ci%double = OpTypeFloat 64
136fd4e5da5Sopenharmony_ci%half = OpTypeFloat 16
137fd4e5da5Sopenharmony_ci%101 = OpConstantTrue %bool ; Need a def with an numerical id to define id maps.
138fd4e5da5Sopenharmony_ci%true = OpConstantTrue %bool
139fd4e5da5Sopenharmony_ci%false = OpConstantFalse %bool
140fd4e5da5Sopenharmony_ci%bool_null = OpConstantNull %bool
141fd4e5da5Sopenharmony_ci%short = OpTypeInt 16 1
142fd4e5da5Sopenharmony_ci%ushort = OpTypeInt 16 0
143fd4e5da5Sopenharmony_ci%byte = OpTypeInt 8 1
144fd4e5da5Sopenharmony_ci%ubyte = OpTypeInt 8 0
145fd4e5da5Sopenharmony_ci%int = OpTypeInt 32 1
146fd4e5da5Sopenharmony_ci%long = OpTypeInt 64 1
147fd4e5da5Sopenharmony_ci%uint = OpTypeInt 32 0
148fd4e5da5Sopenharmony_ci%ulong = OpTypeInt 64 0
149fd4e5da5Sopenharmony_ci%v2int = OpTypeVector %int 2
150fd4e5da5Sopenharmony_ci%v4int = OpTypeVector %int 4
151fd4e5da5Sopenharmony_ci%v4float = OpTypeVector %float 4
152fd4e5da5Sopenharmony_ci%v4double = OpTypeVector %double 4
153fd4e5da5Sopenharmony_ci%v2uint = OpTypeVector %uint 2
154fd4e5da5Sopenharmony_ci%v2float = OpTypeVector %float 2
155fd4e5da5Sopenharmony_ci%v2double = OpTypeVector %double 2
156fd4e5da5Sopenharmony_ci%v2half = OpTypeVector %half 2
157fd4e5da5Sopenharmony_ci%v2bool = OpTypeVector %bool 2
158fd4e5da5Sopenharmony_ci%m2x2int = OpTypeMatrix %v2int 2
159fd4e5da5Sopenharmony_ci%mat4v2float = OpTypeMatrix %v2float 4
160fd4e5da5Sopenharmony_ci%mat2v4float = OpTypeMatrix %v4float 2
161fd4e5da5Sopenharmony_ci%mat4v4float = OpTypeMatrix %v4float 4
162fd4e5da5Sopenharmony_ci%mat4v4double = OpTypeMatrix %v4double 4
163fd4e5da5Sopenharmony_ci%struct_v2int_int_int = OpTypeStruct %v2int %int %int
164fd4e5da5Sopenharmony_ci%_ptr_int = OpTypePointer Function %int
165fd4e5da5Sopenharmony_ci%_ptr_uint = OpTypePointer Function %uint
166fd4e5da5Sopenharmony_ci%_ptr_bool = OpTypePointer Function %bool
167fd4e5da5Sopenharmony_ci%_ptr_float = OpTypePointer Function %float
168fd4e5da5Sopenharmony_ci%_ptr_double = OpTypePointer Function %double
169fd4e5da5Sopenharmony_ci%_ptr_half = OpTypePointer Function %half
170fd4e5da5Sopenharmony_ci%_ptr_long = OpTypePointer Function %long
171fd4e5da5Sopenharmony_ci%_ptr_ulong = OpTypePointer Function %ulong
172fd4e5da5Sopenharmony_ci%_ptr_v2int = OpTypePointer Function %v2int
173fd4e5da5Sopenharmony_ci%_ptr_v4int = OpTypePointer Function %v4int
174fd4e5da5Sopenharmony_ci%_ptr_v4float = OpTypePointer Function %v4float
175fd4e5da5Sopenharmony_ci%_ptr_v4double = OpTypePointer Function %v4double
176fd4e5da5Sopenharmony_ci%_ptr_struct_v2int_int_int = OpTypePointer Function %struct_v2int_int_int
177fd4e5da5Sopenharmony_ci%_ptr_v2float = OpTypePointer Function %v2float
178fd4e5da5Sopenharmony_ci%_ptr_v2double = OpTypePointer Function %v2double
179fd4e5da5Sopenharmony_ci%int_2 = OpConstant %int 2
180fd4e5da5Sopenharmony_ci%int_arr_2 = OpTypeArray %int %int_2
181fd4e5da5Sopenharmony_ci%short_0 = OpConstant %short 0
182fd4e5da5Sopenharmony_ci%short_2 = OpConstant %short 2
183fd4e5da5Sopenharmony_ci%short_3 = OpConstant %short 3
184fd4e5da5Sopenharmony_ci%ubyte_1 = OpConstant %ubyte 1
185fd4e5da5Sopenharmony_ci%byte_n1 = OpConstant %byte -1
186fd4e5da5Sopenharmony_ci%100 = OpConstant %int 0 ; Need a def with an numerical id to define id maps.
187fd4e5da5Sopenharmony_ci%103 = OpConstant %int 7 ; Need a def with an numerical id to define id maps.
188fd4e5da5Sopenharmony_ci%int_0 = OpConstant %int 0
189fd4e5da5Sopenharmony_ci%int_1 = OpConstant %int 1
190fd4e5da5Sopenharmony_ci%int_3 = OpConstant %int 3
191fd4e5da5Sopenharmony_ci%int_4 = OpConstant %int 4
192fd4e5da5Sopenharmony_ci%int_10 = OpConstant %int 10
193fd4e5da5Sopenharmony_ci%int_1073741824 = OpConstant %int 1073741824
194fd4e5da5Sopenharmony_ci%int_n1 = OpConstant %int -1
195fd4e5da5Sopenharmony_ci%int_n24 = OpConstant %int -24
196fd4e5da5Sopenharmony_ci%int_n858993459 = OpConstant %int -858993459
197fd4e5da5Sopenharmony_ci%int_min = OpConstant %int -2147483648
198fd4e5da5Sopenharmony_ci%int_max = OpConstant %int 2147483647
199fd4e5da5Sopenharmony_ci%long_0 = OpConstant %long 0
200fd4e5da5Sopenharmony_ci%long_1 = OpConstant %long 1
201fd4e5da5Sopenharmony_ci%long_2 = OpConstant %long 2
202fd4e5da5Sopenharmony_ci%long_3 = OpConstant %long 3
203fd4e5da5Sopenharmony_ci%long_10 = OpConstant %long 10
204fd4e5da5Sopenharmony_ci%long_4611686018427387904 = OpConstant %long 4611686018427387904
205fd4e5da5Sopenharmony_ci%long_n1 = OpConstant %long -1
206fd4e5da5Sopenharmony_ci%long_n3689348814741910323 = OpConstant %long -3689348814741910323
207fd4e5da5Sopenharmony_ci%long_min = OpConstant %long -9223372036854775808
208fd4e5da5Sopenharmony_ci%long_max = OpConstant %long 9223372036854775807
209fd4e5da5Sopenharmony_ci%uint_0 = OpConstant %uint 0
210fd4e5da5Sopenharmony_ci%uint_1 = OpConstant %uint 1
211fd4e5da5Sopenharmony_ci%uint_2 = OpConstant %uint 2
212fd4e5da5Sopenharmony_ci%uint_3 = OpConstant %uint 3
213fd4e5da5Sopenharmony_ci%uint_4 = OpConstant %uint 4
214fd4e5da5Sopenharmony_ci%uint_32 = OpConstant %uint 32
215fd4e5da5Sopenharmony_ci%uint_42 = OpConstant %uint 42
216fd4e5da5Sopenharmony_ci%uint_2147483649 = OpConstant %uint 2147483649
217fd4e5da5Sopenharmony_ci%uint_max = OpConstant %uint 4294967295
218fd4e5da5Sopenharmony_ci%ulong_0 = OpConstant %ulong 0
219fd4e5da5Sopenharmony_ci%ulong_1 = OpConstant %ulong 1
220fd4e5da5Sopenharmony_ci%ulong_2 = OpConstant %ulong 2
221fd4e5da5Sopenharmony_ci%ulong_9223372036854775809 = OpConstant %ulong 9223372036854775809
222fd4e5da5Sopenharmony_ci%ulong_max = OpConstant %ulong 18446744073709551615
223fd4e5da5Sopenharmony_ci%v2int_undef = OpUndef %v2int
224fd4e5da5Sopenharmony_ci%v2int_0_0 = OpConstantComposite %v2int %int_0 %int_0
225fd4e5da5Sopenharmony_ci%v2int_1_0 = OpConstantComposite %v2int %int_1 %int_0
226fd4e5da5Sopenharmony_ci%v2int_2_2 = OpConstantComposite %v2int %int_2 %int_2
227fd4e5da5Sopenharmony_ci%v2int_2_3 = OpConstantComposite %v2int %int_2 %int_3
228fd4e5da5Sopenharmony_ci%v2int_3_2 = OpConstantComposite %v2int %int_3 %int_2
229fd4e5da5Sopenharmony_ci%v2int_n1_n24 = OpConstantComposite %v2int %int_n1 %int_n24
230fd4e5da5Sopenharmony_ci%v2int_4_4 = OpConstantComposite %v2int %int_4 %int_4
231fd4e5da5Sopenharmony_ci%v2int_min_max = OpConstantComposite %v2int %int_min %int_max
232fd4e5da5Sopenharmony_ci%v2bool_null = OpConstantNull %v2bool
233fd4e5da5Sopenharmony_ci%v2bool_true_false = OpConstantComposite %v2bool %true %false
234fd4e5da5Sopenharmony_ci%v2bool_false_true = OpConstantComposite %v2bool %false %true
235fd4e5da5Sopenharmony_ci%struct_v2int_int_int_null = OpConstantNull %struct_v2int_int_int
236fd4e5da5Sopenharmony_ci%v2int_null = OpConstantNull %v2int
237fd4e5da5Sopenharmony_ci%102 = OpConstantComposite %v2int %103 %103
238fd4e5da5Sopenharmony_ci%v4int_undef = OpUndef %v4int
239fd4e5da5Sopenharmony_ci%v4int_0_0_0_0 = OpConstantComposite %v4int %int_0 %int_0 %int_0 %int_0
240fd4e5da5Sopenharmony_ci%m2x2int_undef = OpUndef %m2x2int
241fd4e5da5Sopenharmony_ci%struct_undef_0_0 = OpConstantComposite %struct_v2int_int_int %v2int_undef %int_0 %int_0
242fd4e5da5Sopenharmony_ci%float_n1 = OpConstant %float -1
243fd4e5da5Sopenharmony_ci%104 = OpConstant %float 0 ; Need a def with an numerical id to define id maps.
244fd4e5da5Sopenharmony_ci%float_null = OpConstantNull %float
245fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
246fd4e5da5Sopenharmony_ci%float_n0 = OpConstant %float -0.0
247fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
248fd4e5da5Sopenharmony_ci%float_2 = OpConstant %float 2
249fd4e5da5Sopenharmony_ci%float_3 = OpConstant %float 3
250fd4e5da5Sopenharmony_ci%float_4 = OpConstant %float 4
251fd4e5da5Sopenharmony_ci%float_2049 = OpConstant %float 2049
252fd4e5da5Sopenharmony_ci%float_n2049 = OpConstant %float -2049
253fd4e5da5Sopenharmony_ci%float_0p5 = OpConstant %float 0.5
254fd4e5da5Sopenharmony_ci%float_0p2 = OpConstant %float 0.2
255fd4e5da5Sopenharmony_ci%float_pi = OpConstant %float 1.5555
256fd4e5da5Sopenharmony_ci%float_1e16 = OpConstant %float 1e16
257fd4e5da5Sopenharmony_ci%float_n1e16 = OpConstant %float -1e16
258fd4e5da5Sopenharmony_ci%float_1en16 = OpConstant %float 1e-16
259fd4e5da5Sopenharmony_ci%float_n1en16 = OpConstant %float -1e-16
260fd4e5da5Sopenharmony_ci%v2float_0_0 = OpConstantComposite %v2float %float_0 %float_0
261fd4e5da5Sopenharmony_ci%v2float_2_2 = OpConstantComposite %v2float %float_2 %float_2
262fd4e5da5Sopenharmony_ci%v2float_2_3 = OpConstantComposite %v2float %float_2 %float_3
263fd4e5da5Sopenharmony_ci%v2float_3_2 = OpConstantComposite %v2float %float_3 %float_2
264fd4e5da5Sopenharmony_ci%v2float_4_4 = OpConstantComposite %v2float %float_4 %float_4
265fd4e5da5Sopenharmony_ci%v2float_2_0p5 = OpConstantComposite %v2float %float_2 %float_0p5
266fd4e5da5Sopenharmony_ci%v2float_0p2_0p5 = OpConstantComposite %v2float %float_0p2 %float_0p5
267fd4e5da5Sopenharmony_ci%v2float_null = OpConstantNull %v2float
268fd4e5da5Sopenharmony_ci%double_n1 = OpConstant %double -1
269fd4e5da5Sopenharmony_ci%105 = OpConstant %double 0 ; Need a def with an numerical id to define id maps.
270fd4e5da5Sopenharmony_ci%double_null = OpConstantNull %double
271fd4e5da5Sopenharmony_ci%double_0 = OpConstant %double 0
272fd4e5da5Sopenharmony_ci%double_n0 = OpConstant %double -0.0
273fd4e5da5Sopenharmony_ci%double_1 = OpConstant %double 1
274fd4e5da5Sopenharmony_ci%double_2 = OpConstant %double 2
275fd4e5da5Sopenharmony_ci%double_3 = OpConstant %double 3
276fd4e5da5Sopenharmony_ci%double_4 = OpConstant %double 4
277fd4e5da5Sopenharmony_ci%double_5 = OpConstant %double 5
278fd4e5da5Sopenharmony_ci%double_0p5 = OpConstant %double 0.5
279fd4e5da5Sopenharmony_ci%double_0p2 = OpConstant %double 0.2
280fd4e5da5Sopenharmony_ci%v2double_0_0 = OpConstantComposite %v2double %double_0 %double_0
281fd4e5da5Sopenharmony_ci%v2double_2_2 = OpConstantComposite %v2double %double_2 %double_2
282fd4e5da5Sopenharmony_ci%v2double_2_3 = OpConstantComposite %v2double %double_2 %double_3
283fd4e5da5Sopenharmony_ci%v2double_3_2 = OpConstantComposite %v2double %double_3 %double_2
284fd4e5da5Sopenharmony_ci%v2double_4_4 = OpConstantComposite %v2double %double_4 %double_4
285fd4e5da5Sopenharmony_ci%v2double_2_0p5 = OpConstantComposite %v2double %double_2 %double_0p5
286fd4e5da5Sopenharmony_ci%v2double_null = OpConstantNull %v2double
287fd4e5da5Sopenharmony_ci%108 = OpConstant %half 0
288fd4e5da5Sopenharmony_ci%half_1 = OpConstant %half 1
289fd4e5da5Sopenharmony_ci%half_2 = OpConstant %half 2
290fd4e5da5Sopenharmony_ci%half_0_1 = OpConstantComposite %v2half %108 %half_1
291fd4e5da5Sopenharmony_ci%106 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
292fd4e5da5Sopenharmony_ci%v4float_0_0_0_0 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
293fd4e5da5Sopenharmony_ci%v4float_0_0_0_1 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_1
294fd4e5da5Sopenharmony_ci%v4float_0_1_0_0 = OpConstantComposite %v4float %float_0 %float_1 %float_null %float_0
295fd4e5da5Sopenharmony_ci%v4float_1_1_1_1 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
296fd4e5da5Sopenharmony_ci%v4float_1_2_3_4 = OpConstantComposite %v4float %float_1 %float_2 %float_3 %float_4
297fd4e5da5Sopenharmony_ci%v4float_null = OpConstantNull %v4float
298fd4e5da5Sopenharmony_ci%mat2v4float_null = OpConstantNull %mat2v4float
299fd4e5da5Sopenharmony_ci%mat4v4float_null = OpConstantNull %mat4v4float
300fd4e5da5Sopenharmony_ci%mat4v4float_1_2_3_4 = OpConstantComposite %mat4v4float %v4float_1_2_3_4 %v4float_1_2_3_4 %v4float_1_2_3_4 %v4float_1_2_3_4
301fd4e5da5Sopenharmony_ci%mat4v4float_1_2_3_4_null = OpConstantComposite %mat4v4float %v4float_1_2_3_4 %v4float_null %v4float_1_2_3_4 %v4float_null
302fd4e5da5Sopenharmony_ci%107 = OpConstantComposite %v4double %double_0 %double_0 %double_0 %double_0
303fd4e5da5Sopenharmony_ci%v4double_0_0_0_0 = OpConstantComposite %v4double %double_0 %double_0 %double_0 %double_0
304fd4e5da5Sopenharmony_ci%v4double_0_0_0_1 = OpConstantComposite %v4double %double_0 %double_0 %double_0 %double_1
305fd4e5da5Sopenharmony_ci%v4double_0_1_0_0 = OpConstantComposite %v4double %double_0 %double_1 %double_null %double_0
306fd4e5da5Sopenharmony_ci%v4double_1_1_1_1 = OpConstantComposite %v4double %double_1 %double_1 %double_1 %double_1
307fd4e5da5Sopenharmony_ci%v4double_1_2_3_4 = OpConstantComposite %v4double %double_1 %double_2 %double_3 %double_4
308fd4e5da5Sopenharmony_ci%v4double_1_1_1_0p5 = OpConstantComposite %v4double %double_1 %double_1 %double_1 %double_0p5
309fd4e5da5Sopenharmony_ci%v4double_null = OpConstantNull %v4double
310fd4e5da5Sopenharmony_ci%mat4v4double_null = OpConstantNull %mat4v4double
311fd4e5da5Sopenharmony_ci%mat4v4double_1_2_3_4 = OpConstantComposite %mat4v4double %v4double_1_2_3_4 %v4double_1_2_3_4 %v4double_1_2_3_4 %v4double_1_2_3_4
312fd4e5da5Sopenharmony_ci%mat4v4double_1_2_3_4_null = OpConstantComposite %mat4v4double %v4double_1_2_3_4 %v4double_null %v4double_1_2_3_4 %v4double_null
313fd4e5da5Sopenharmony_ci%v4float_n1_2_1_3 = OpConstantComposite %v4float %float_n1 %float_2 %float_1 %float_3
314fd4e5da5Sopenharmony_ci%uint_0x3f800000 = OpConstant %uint 0x3f800000
315fd4e5da5Sopenharmony_ci%uint_0xbf800000 = OpConstant %uint 0xbf800000
316fd4e5da5Sopenharmony_ci%v2uint_0x3f800000_0xbf800000 = OpConstantComposite %v2uint %uint_0x3f800000 %uint_0xbf800000
317fd4e5da5Sopenharmony_ci%long_0xbf8000003f800000 = OpConstant %long 0xbf8000003f800000
318fd4e5da5Sopenharmony_ci%int_0x3FF00000 = OpConstant %int 0x3FF00000
319fd4e5da5Sopenharmony_ci%int_0x00000000 = OpConstant %int 0x00000000
320fd4e5da5Sopenharmony_ci%int_0xC05FD666 = OpConstant %int 0xC05FD666
321fd4e5da5Sopenharmony_ci%int_0x66666666 = OpConstant %int 0x66666666
322fd4e5da5Sopenharmony_ci%v4int_0x3FF00000_0x00000000_0xC05FD666_0x66666666 = OpConstantComposite %v4int %int_0x00000000 %int_0x3FF00000 %int_0x66666666 %int_0xC05FD666
323fd4e5da5Sopenharmony_ci%ushort_0x4400 = OpConstant %ushort 0x4400
324fd4e5da5Sopenharmony_ci%short_0x4400 = OpConstant %short 0x4400
325fd4e5da5Sopenharmony_ci%ushort_0xBC00 = OpConstant %ushort 0xBC00
326fd4e5da5Sopenharmony_ci%short_0xBC00 = OpConstant %short 0xBC00
327fd4e5da5Sopenharmony_ci%int_arr_2_undef = OpUndef %int_arr_2
328fd4e5da5Sopenharmony_ci)";
329fd4e5da5Sopenharmony_ci
330fd4e5da5Sopenharmony_ci  return header;
331fd4e5da5Sopenharmony_ci}
332fd4e5da5Sopenharmony_ci
333fd4e5da5Sopenharmony_ci// Returns the header with definitions of float NaN and double NaN. Since FC
334fd4e5da5Sopenharmony_ci// "; CHECK: [[double_n0:%\\w+]] = OpConstant [[double]] -0\n" finds
335fd4e5da5Sopenharmony_ci// %double_nan = OpConstant %double -0x1.8p+1024 instead of
336fd4e5da5Sopenharmony_ci// %double_n0 = OpConstant %double -0,
337fd4e5da5Sopenharmony_ci// we separates those definitions from Header().
338fd4e5da5Sopenharmony_ciconst std::string& HeaderWithNaN() {
339fd4e5da5Sopenharmony_ci  static const std::string headerWithNaN =
340fd4e5da5Sopenharmony_ci      Header() +
341fd4e5da5Sopenharmony_ci      R"(%float_nan = OpConstant %float -0x1.8p+128
342fd4e5da5Sopenharmony_ci%double_nan = OpConstant %double -0x1.8p+1024
343fd4e5da5Sopenharmony_ci)";
344fd4e5da5Sopenharmony_ci
345fd4e5da5Sopenharmony_ci  return headerWithNaN;
346fd4e5da5Sopenharmony_ci}
347fd4e5da5Sopenharmony_ci
348fd4e5da5Sopenharmony_ci// clang-format off
349fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(TestCase, IntegerInstructionFoldingTest,
350fd4e5da5Sopenharmony_ci                        ::testing::Values(
351fd4e5da5Sopenharmony_ci  // Test case 0: fold 0*n
352fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
353fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
354fd4e5da5Sopenharmony_ci    "%main_lab = OpLabel\n" +
355fd4e5da5Sopenharmony_ci           "%n = OpVariable %_ptr_int Function\n" +
356fd4e5da5Sopenharmony_ci        "%load = OpLoad %int %n\n" +
357fd4e5da5Sopenharmony_ci           "%2 = OpIMul %int %int_0 %load\n" +
358fd4e5da5Sopenharmony_ci                "OpReturn\n" +
359fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
360fd4e5da5Sopenharmony_ci    2, 0),
361fd4e5da5Sopenharmony_ci  // Test case 1: fold n*0
362fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
363fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
364fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
365fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_int Function\n" +
366fd4e5da5Sopenharmony_ci        "%load = OpLoad %int %n\n" +
367fd4e5da5Sopenharmony_ci        "%2 = OpIMul %int %load %int_0\n" +
368fd4e5da5Sopenharmony_ci        "OpReturn\n" +
369fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
370fd4e5da5Sopenharmony_ci    2, 0),
371fd4e5da5Sopenharmony_ci  // Test case 2: fold 0/n (signed)
372fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
373fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
374fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
375fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_int Function\n" +
376fd4e5da5Sopenharmony_ci        "%load = OpLoad %int %n\n" +
377fd4e5da5Sopenharmony_ci        "%2 = OpSDiv %int %int_0 %load\n" +
378fd4e5da5Sopenharmony_ci        "OpReturn\n" +
379fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
380fd4e5da5Sopenharmony_ci        2, 0),
381fd4e5da5Sopenharmony_ci  // Test case 3: fold n/0 (signed)
382fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
383fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
384fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
385fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_int Function\n" +
386fd4e5da5Sopenharmony_ci        "%load = OpLoad %int %n\n" +
387fd4e5da5Sopenharmony_ci        "%2 = OpSDiv %int %load %int_0\n" +
388fd4e5da5Sopenharmony_ci        "OpReturn\n" +
389fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
390fd4e5da5Sopenharmony_ci    2, 0),
391fd4e5da5Sopenharmony_ci  // Test case 4: fold 0/n (unsigned)
392fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
393fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
394fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
395fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_uint Function\n" +
396fd4e5da5Sopenharmony_ci        "%load = OpLoad %uint %n\n" +
397fd4e5da5Sopenharmony_ci        "%2 = OpUDiv %uint %uint_0 %load\n" +
398fd4e5da5Sopenharmony_ci        "OpReturn\n" +
399fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
400fd4e5da5Sopenharmony_ci    2, 0),
401fd4e5da5Sopenharmony_ci  // Test case 5: fold n/0 (unsigned)
402fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
403fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
404fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
405fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_int Function\n" +
406fd4e5da5Sopenharmony_ci        "%load = OpLoad %int %n\n" +
407fd4e5da5Sopenharmony_ci        "%2 = OpSDiv %int %load %int_0\n" +
408fd4e5da5Sopenharmony_ci        "OpReturn\n" +
409fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
410fd4e5da5Sopenharmony_ci    2, 0),
411fd4e5da5Sopenharmony_ci  // Test case 6: fold 0 remainder n
412fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
413fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
414fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
415fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_int Function\n" +
416fd4e5da5Sopenharmony_ci        "%load = OpLoad %int %n\n" +
417fd4e5da5Sopenharmony_ci        "%2 = OpSRem %int %int_0 %load\n" +
418fd4e5da5Sopenharmony_ci        "OpReturn\n" +
419fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
420fd4e5da5Sopenharmony_ci    2, 0),
421fd4e5da5Sopenharmony_ci  // Test case 7: fold n remainder 0
422fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
423fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
424fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
425fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_int Function\n" +
426fd4e5da5Sopenharmony_ci        "%load = OpLoad %int %n\n" +
427fd4e5da5Sopenharmony_ci        "%2 = OpSRem %int %load %int_0\n" +
428fd4e5da5Sopenharmony_ci        "OpReturn\n" +
429fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
430fd4e5da5Sopenharmony_ci    2, 0),
431fd4e5da5Sopenharmony_ci  // Test case 8: fold 0%n (signed)
432fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
433fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
434fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
435fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_int Function\n" +
436fd4e5da5Sopenharmony_ci        "%load = OpLoad %int %n\n" +
437fd4e5da5Sopenharmony_ci        "%2 = OpSMod %int %int_0 %load\n" +
438fd4e5da5Sopenharmony_ci        "OpReturn\n" +
439fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
440fd4e5da5Sopenharmony_ci    2, 0),
441fd4e5da5Sopenharmony_ci  // Test case 9: fold n%0 (signed)
442fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
443fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
444fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
445fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_int Function\n" +
446fd4e5da5Sopenharmony_ci        "%load = OpLoad %int %n\n" +
447fd4e5da5Sopenharmony_ci        "%2 = OpSMod %int %load %int_0\n" +
448fd4e5da5Sopenharmony_ci        "OpReturn\n" +
449fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
450fd4e5da5Sopenharmony_ci    2, 0),
451fd4e5da5Sopenharmony_ci  // Test case 10: fold 0%n (unsigned)
452fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
453fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
454fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
455fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_uint Function\n" +
456fd4e5da5Sopenharmony_ci        "%load = OpLoad %uint %n\n" +
457fd4e5da5Sopenharmony_ci        "%2 = OpUMod %uint %uint_0 %load\n" +
458fd4e5da5Sopenharmony_ci        "OpReturn\n" +
459fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
460fd4e5da5Sopenharmony_ci    2, 0),
461fd4e5da5Sopenharmony_ci  // Test case 11: fold n%0 (unsigned)
462fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
463fd4e5da5Sopenharmony_ci    Header() + "%main = OpFunction %void None %void_func\n" +
464fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
465fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_uint Function\n" +
466fd4e5da5Sopenharmony_ci        "%load = OpLoad %uint %n\n" +
467fd4e5da5Sopenharmony_ci        "%2 = OpUMod %uint %load %uint_0\n" +
468fd4e5da5Sopenharmony_ci        "OpReturn\n" +
469fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
470fd4e5da5Sopenharmony_ci    2, 0),
471fd4e5da5Sopenharmony_ci  // Test case 12: fold n << 32
472fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
473fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
474fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
475fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
476fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
477fd4e5da5Sopenharmony_ci          "%2 = OpShiftLeftLogical %uint %load %uint_32\n" +
478fd4e5da5Sopenharmony_ci          "OpReturn\n" +
479fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
480fd4e5da5Sopenharmony_ci      2, 0),
481fd4e5da5Sopenharmony_ci  // Test case 13: fold n >> 32
482fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
483fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
484fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
485fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
486fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
487fd4e5da5Sopenharmony_ci          "%2 = OpShiftRightLogical %uint %load %uint_32\n" +
488fd4e5da5Sopenharmony_ci          "OpReturn\n" +
489fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
490fd4e5da5Sopenharmony_ci      2, 0),
491fd4e5da5Sopenharmony_ci  // Test case 14: fold n | 0xFFFFFFFF
492fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
493fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
494fd4e5da5Sopenharmony_ci  "%main_lab = OpLabel\n" +
495fd4e5da5Sopenharmony_ci  "%n = OpVariable %_ptr_uint Function\n" +
496fd4e5da5Sopenharmony_ci  "%load = OpLoad %uint %n\n" +
497fd4e5da5Sopenharmony_ci  "%2 = OpBitwiseOr %uint %load %uint_max\n" +
498fd4e5da5Sopenharmony_ci  "OpReturn\n" +
499fd4e5da5Sopenharmony_ci  "OpFunctionEnd",
500fd4e5da5Sopenharmony_ci  2, 0xFFFFFFFF),
501fd4e5da5Sopenharmony_ci  // Test case 15: fold 0xFFFFFFFF | n
502fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
503fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
504fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
505fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
506fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
507fd4e5da5Sopenharmony_ci          "%2 = OpBitwiseOr %uint %uint_max %load\n" +
508fd4e5da5Sopenharmony_ci          "OpReturn\n" +
509fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
510fd4e5da5Sopenharmony_ci      2, 0xFFFFFFFF),
511fd4e5da5Sopenharmony_ci  // Test case 16: fold n & 0
512fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
513fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
514fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
515fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
516fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
517fd4e5da5Sopenharmony_ci          "%2 = OpBitwiseAnd %uint %load %uint_0\n" +
518fd4e5da5Sopenharmony_ci          "OpReturn\n" +
519fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
520fd4e5da5Sopenharmony_ci      2, 0),
521fd4e5da5Sopenharmony_ci  // Test case 17: fold 1/0 (signed)
522fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
523fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
524fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
525fd4e5da5Sopenharmony_ci          "%2 = OpSDiv %int %int_1 %int_0\n" +
526fd4e5da5Sopenharmony_ci          "OpReturn\n" +
527fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
528fd4e5da5Sopenharmony_ci      2, 0),
529fd4e5da5Sopenharmony_ci  // Test case 18: fold 1/0 (unsigned)
530fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
531fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
532fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
533fd4e5da5Sopenharmony_ci          "%2 = OpUDiv %uint %uint_1 %uint_0\n" +
534fd4e5da5Sopenharmony_ci          "OpReturn\n" +
535fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
536fd4e5da5Sopenharmony_ci      2, 0),
537fd4e5da5Sopenharmony_ci  // Test case 19: fold OpSRem 1 0 (signed)
538fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
539fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
540fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
541fd4e5da5Sopenharmony_ci          "%2 = OpSRem %int %int_1 %int_0\n" +
542fd4e5da5Sopenharmony_ci          "OpReturn\n" +
543fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
544fd4e5da5Sopenharmony_ci      2, 0),
545fd4e5da5Sopenharmony_ci  // Test case 20: fold 1%0 (signed)
546fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
547fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
548fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
549fd4e5da5Sopenharmony_ci          "%2 = OpSMod %int %int_1 %int_0\n" +
550fd4e5da5Sopenharmony_ci          "OpReturn\n" +
551fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
552fd4e5da5Sopenharmony_ci      2, 0),
553fd4e5da5Sopenharmony_ci  // Test case 21: fold 1%0 (unsigned)
554fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
555fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
556fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
557fd4e5da5Sopenharmony_ci          "%2 = OpUMod %uint %uint_1 %uint_0\n" +
558fd4e5da5Sopenharmony_ci          "OpReturn\n" +
559fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
560fd4e5da5Sopenharmony_ci      2, 0),
561fd4e5da5Sopenharmony_ci  // Test case 22: fold unsigned n >> 42 (undefined, so set to zero).
562fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
563fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
564fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
565fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
566fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
567fd4e5da5Sopenharmony_ci          "%2 = OpShiftRightLogical %uint %load %uint_42\n" +
568fd4e5da5Sopenharmony_ci          "OpReturn\n" +
569fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
570fd4e5da5Sopenharmony_ci      2, 0),
571fd4e5da5Sopenharmony_ci  // Test case 23: fold signed n >> 42 (undefined, so set to zero).
572fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
573fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
574fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
575fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
576fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
577fd4e5da5Sopenharmony_ci          "%2 = OpShiftRightLogical %int %load %uint_42\n" +
578fd4e5da5Sopenharmony_ci          "OpReturn\n" +
579fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
580fd4e5da5Sopenharmony_ci      2, 0),
581fd4e5da5Sopenharmony_ci  // Test case 24: fold n << 42 (undefined, so set to zero).
582fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
583fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
584fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
585fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
586fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
587fd4e5da5Sopenharmony_ci          "%2 = OpShiftLeftLogical %int %load %uint_42\n" +
588fd4e5da5Sopenharmony_ci          "OpReturn\n" +
589fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
590fd4e5da5Sopenharmony_ci      2, 0),
591fd4e5da5Sopenharmony_ci  // Test case 25: fold -24 >> 32 (defined as -1)
592fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
593fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
594fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
595fd4e5da5Sopenharmony_ci          "%2 = OpShiftRightArithmetic %int %int_n24 %uint_32\n" +
596fd4e5da5Sopenharmony_ci          "OpReturn\n" +
597fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
598fd4e5da5Sopenharmony_ci      2, -1),
599fd4e5da5Sopenharmony_ci  // Test case 26: fold 2 >> 32 (signed)
600fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
601fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
602fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
603fd4e5da5Sopenharmony_ci          "%2 = OpShiftRightArithmetic %int %int_2 %uint_32\n" +
604fd4e5da5Sopenharmony_ci          "OpReturn\n" +
605fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
606fd4e5da5Sopenharmony_ci      2, 0),
607fd4e5da5Sopenharmony_ci  // Test case 27: fold 2 >> 32 (unsigned)
608fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
609fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
610fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
611fd4e5da5Sopenharmony_ci          "%2 = OpShiftRightLogical %int %int_2 %uint_32\n" +
612fd4e5da5Sopenharmony_ci          "OpReturn\n" +
613fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
614fd4e5da5Sopenharmony_ci      2, 0),
615fd4e5da5Sopenharmony_ci  // Test case 28: fold 2 << 32
616fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
617fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
618fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
619fd4e5da5Sopenharmony_ci          "%2 = OpShiftLeftLogical %int %int_2 %uint_32\n" +
620fd4e5da5Sopenharmony_ci          "OpReturn\n" +
621fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
622fd4e5da5Sopenharmony_ci      2, 0),
623fd4e5da5Sopenharmony_ci  // Test case 29: fold -INT_MIN
624fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
625fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
626fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
627fd4e5da5Sopenharmony_ci          "%2 = OpSNegate %int %int_min\n" +
628fd4e5da5Sopenharmony_ci          "OpReturn\n" +
629fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
630fd4e5da5Sopenharmony_ci      2, std::numeric_limits<int32_t>::min()),
631fd4e5da5Sopenharmony_ci  // Test case 30: fold UMin 3 4
632fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
633fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
634fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
635fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %uint %1 UMin %uint_3 %uint_4\n" +
636fd4e5da5Sopenharmony_ci          "OpReturn\n" +
637fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
638fd4e5da5Sopenharmony_ci      2, 3),
639fd4e5da5Sopenharmony_ci  // Test case 31: fold UMin 4 2
640fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
641fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
642fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
643fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %uint %1 UMin %uint_4 %uint_2\n" +
644fd4e5da5Sopenharmony_ci          "OpReturn\n" +
645fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
646fd4e5da5Sopenharmony_ci      2, 2),
647fd4e5da5Sopenharmony_ci  // Test case 32: fold SMin 3 4
648fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
649fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
650fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
651fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %int %1 UMin %int_3 %int_4\n" +
652fd4e5da5Sopenharmony_ci          "OpReturn\n" +
653fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
654fd4e5da5Sopenharmony_ci      2, 3),
655fd4e5da5Sopenharmony_ci  // Test case 33: fold SMin 4 2
656fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
657fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
658fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
659fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %int %1 SMin %int_4 %int_2\n" +
660fd4e5da5Sopenharmony_ci          "OpReturn\n" +
661fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
662fd4e5da5Sopenharmony_ci      2, 2),
663fd4e5da5Sopenharmony_ci  // Test case 34: fold UMax 3 4
664fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
665fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
666fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
667fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %uint %1 UMax %uint_3 %uint_4\n" +
668fd4e5da5Sopenharmony_ci          "OpReturn\n" +
669fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
670fd4e5da5Sopenharmony_ci      2, 4),
671fd4e5da5Sopenharmony_ci  // Test case 35: fold UMax 3 2
672fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
673fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
674fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
675fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %uint %1 UMax %uint_3 %uint_2\n" +
676fd4e5da5Sopenharmony_ci          "OpReturn\n" +
677fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
678fd4e5da5Sopenharmony_ci      2, 3),
679fd4e5da5Sopenharmony_ci  // Test case 36: fold SMax 3 4
680fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
681fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
682fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
683fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %int %1 UMax %int_3 %int_4\n" +
684fd4e5da5Sopenharmony_ci          "OpReturn\n" +
685fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
686fd4e5da5Sopenharmony_ci      2, 4),
687fd4e5da5Sopenharmony_ci  // Test case 37: fold SMax 3 2
688fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
689fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
690fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
691fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %int %1 SMax %int_3 %int_2\n" +
692fd4e5da5Sopenharmony_ci          "OpReturn\n" +
693fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
694fd4e5da5Sopenharmony_ci      2, 3),
695fd4e5da5Sopenharmony_ci  // Test case 38: fold UClamp 2 3 4
696fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
697fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
698fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
699fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %uint %1 UClamp %uint_2 %uint_3 %uint_4\n" +
700fd4e5da5Sopenharmony_ci          "OpReturn\n" +
701fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
702fd4e5da5Sopenharmony_ci      2, 3),
703fd4e5da5Sopenharmony_ci  // Test case 39: fold UClamp 2 0 4
704fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
705fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
706fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
707fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %uint %1 UClamp %uint_2 %uint_0 %uint_4\n" +
708fd4e5da5Sopenharmony_ci          "OpReturn\n" +
709fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
710fd4e5da5Sopenharmony_ci      2, 2),
711fd4e5da5Sopenharmony_ci  // Test case 40: fold UClamp 2 0 1
712fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
713fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
714fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
715fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %uint %1 UClamp %uint_2 %uint_0 %uint_1\n" +
716fd4e5da5Sopenharmony_ci          "OpReturn\n" +
717fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
718fd4e5da5Sopenharmony_ci      2, 1),
719fd4e5da5Sopenharmony_ci  // Test case 41: fold SClamp 2 3 4
720fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
721fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
722fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
723fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %int %1 SClamp %int_2 %int_3 %int_4\n" +
724fd4e5da5Sopenharmony_ci          "OpReturn\n" +
725fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
726fd4e5da5Sopenharmony_ci      2, 3),
727fd4e5da5Sopenharmony_ci  // Test case 42: fold SClamp 2 0 4
728fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
729fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
730fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
731fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %int %1 SClamp %int_2 %int_0 %int_4\n" +
732fd4e5da5Sopenharmony_ci          "OpReturn\n" +
733fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
734fd4e5da5Sopenharmony_ci      2, 2),
735fd4e5da5Sopenharmony_ci  // Test case 43: fold SClamp 2 0 1
736fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
737fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
738fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
739fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %int %1 SClamp %int_2 %int_0 %int_1\n" +
740fd4e5da5Sopenharmony_ci          "OpReturn\n" +
741fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
742fd4e5da5Sopenharmony_ci      2, 1),
743fd4e5da5Sopenharmony_ci  // Test case 44: SClamp 1 2 x
744fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
745fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
746fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
747fd4e5da5Sopenharmony_ci          "%undef = OpUndef %int\n" +
748fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %int %1 SClamp %int_1 %int_2 %undef\n" +
749fd4e5da5Sopenharmony_ci          "OpReturn\n" +
750fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
751fd4e5da5Sopenharmony_ci      2, 2),
752fd4e5da5Sopenharmony_ci  // Test case 45: SClamp 2 x 1
753fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
754fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
755fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
756fd4e5da5Sopenharmony_ci          "%undef = OpUndef %int\n" +
757fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %int %1 SClamp %int_2 %undef %int_1\n" +
758fd4e5da5Sopenharmony_ci          "OpReturn\n" +
759fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
760fd4e5da5Sopenharmony_ci      2, 1),
761fd4e5da5Sopenharmony_ci  // Test case 46: UClamp 1 2 x
762fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
763fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
764fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
765fd4e5da5Sopenharmony_ci          "%undef = OpUndef %uint\n" +
766fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %uint %1 UClamp %uint_1 %uint_2 %undef\n" +
767fd4e5da5Sopenharmony_ci          "OpReturn\n" +
768fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
769fd4e5da5Sopenharmony_ci      2, 2),
770fd4e5da5Sopenharmony_ci  // Test case 47: UClamp 2 x 1
771fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
772fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
773fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
774fd4e5da5Sopenharmony_ci          "%undef = OpUndef %uint\n" +
775fd4e5da5Sopenharmony_ci          "%2 = OpExtInst %uint %1 UClamp %uint_2 %undef %uint_1\n" +
776fd4e5da5Sopenharmony_ci          "OpReturn\n" +
777fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
778fd4e5da5Sopenharmony_ci      2, 1),
779fd4e5da5Sopenharmony_ci    // Test case 48: Bit-cast int 0 to unsigned int
780fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
781fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
782fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
783fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %uint %int_0\n" +
784fd4e5da5Sopenharmony_ci            "OpReturn\n" +
785fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
786fd4e5da5Sopenharmony_ci        2, 0),
787fd4e5da5Sopenharmony_ci    // Test case 49: Bit-cast int -24 to unsigned int
788fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
789fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
790fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
791fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %uint %int_n24\n" +
792fd4e5da5Sopenharmony_ci            "OpReturn\n" +
793fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
794fd4e5da5Sopenharmony_ci        2, static_cast<uint32_t>(-24)),
795fd4e5da5Sopenharmony_ci    // Test case 50: Bit-cast float 1.0f to unsigned int
796fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
797fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
798fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
799fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %uint %float_1\n" +
800fd4e5da5Sopenharmony_ci            "OpReturn\n" +
801fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
802fd4e5da5Sopenharmony_ci        2, static_cast<uint32_t>(0x3f800000)),
803fd4e5da5Sopenharmony_ci    // Test case 51: Bit-cast ushort 0xBC00 to ushort
804fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
805fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
806fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
807fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %ushort %ushort_0xBC00\n" +
808fd4e5da5Sopenharmony_ci            "OpReturn\n" +
809fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
810fd4e5da5Sopenharmony_ci        2, 0xBC00),
811fd4e5da5Sopenharmony_ci    // Test case 52: Bit-cast short 0xBC00 to ushort
812fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
813fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
814fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
815fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %ushort %short_0xBC00\n" +
816fd4e5da5Sopenharmony_ci            "OpReturn\n" +
817fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
818fd4e5da5Sopenharmony_ci        2, 0xFFFFBC00),
819fd4e5da5Sopenharmony_ci    // Test case 53: Bit-cast half 1 to ushort
820fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
821fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
822fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
823fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %ushort %half_1\n" +
824fd4e5da5Sopenharmony_ci            "OpReturn\n" +
825fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
826fd4e5da5Sopenharmony_ci        2, 0x3C00),
827fd4e5da5Sopenharmony_ci    // Test case 54: Bit-cast ushort 0xBC00 to short
828fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
829fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
830fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
831fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %short %ushort_0xBC00\n" +
832fd4e5da5Sopenharmony_ci            "OpReturn\n" +
833fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
834fd4e5da5Sopenharmony_ci        2, 0xBC00),
835fd4e5da5Sopenharmony_ci    // Test case 55: Bit-cast short 0xBC00 to short
836fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
837fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
838fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
839fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %short %short_0xBC00\n" +
840fd4e5da5Sopenharmony_ci            "OpReturn\n" +
841fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
842fd4e5da5Sopenharmony_ci        2, 0xFFFFBC00),
843fd4e5da5Sopenharmony_ci    // Test case 56: Bit-cast half 1 to short
844fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
845fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
846fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
847fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %short %half_1\n" +
848fd4e5da5Sopenharmony_ci            "OpReturn\n" +
849fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
850fd4e5da5Sopenharmony_ci        2, 0x3C00),
851fd4e5da5Sopenharmony_ci    // Test case 57: Bit-cast ushort 0xBC00 to half
852fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
853fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
854fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
855fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %half %ushort_0xBC00\n" +
856fd4e5da5Sopenharmony_ci            "OpReturn\n" +
857fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
858fd4e5da5Sopenharmony_ci        2, 0xBC00),
859fd4e5da5Sopenharmony_ci    // Test case 58: Bit-cast short 0xBC00 to half
860fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
861fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
862fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
863fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %half %short_0xBC00\n" +
864fd4e5da5Sopenharmony_ci            "OpReturn\n" +
865fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
866fd4e5da5Sopenharmony_ci        2, 0xFFFFBC00),
867fd4e5da5Sopenharmony_ci    // Test case 59: Bit-cast half 1 to half
868fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
869fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
870fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
871fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %half %half_1\n" +
872fd4e5da5Sopenharmony_ci            "OpReturn\n" +
873fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
874fd4e5da5Sopenharmony_ci        2, 0x3C00),
875fd4e5da5Sopenharmony_ci    // Test case 60: Bit-cast ubyte 1 to byte
876fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
877fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
878fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
879fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %byte %ubyte_1\n" +
880fd4e5da5Sopenharmony_ci            "OpReturn\n" +
881fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
882fd4e5da5Sopenharmony_ci        2, 1),
883fd4e5da5Sopenharmony_ci    // Test case 61: Bit-cast byte -1 to ubyte
884fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
885fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
886fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
887fd4e5da5Sopenharmony_ci            "%2 = OpBitcast %ubyte %byte_n1\n" +
888fd4e5da5Sopenharmony_ci            "OpReturn\n" +
889fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
890fd4e5da5Sopenharmony_ci        2, 0xFFFFFFFF),
891fd4e5da5Sopenharmony_ci    // Test case 62: Negate 2.
892fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
893fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
894fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
895fd4e5da5Sopenharmony_ci            "%2 = OpSNegate %int %int_2\n" +
896fd4e5da5Sopenharmony_ci            "OpReturn\n" +
897fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
898fd4e5da5Sopenharmony_ci        2, -2),
899fd4e5da5Sopenharmony_ci    // Test case 63: Negate negative short.
900fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
901fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
902fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
903fd4e5da5Sopenharmony_ci            "%2 = OpSNegate %short %short_0xBC00\n" +
904fd4e5da5Sopenharmony_ci            "OpReturn\n" +
905fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
906fd4e5da5Sopenharmony_ci        2, 0x4400 /* expected to be sign extended. */),
907fd4e5da5Sopenharmony_ci    // Test case 64: Negate positive short.
908fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
909fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
910fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
911fd4e5da5Sopenharmony_ci            "%2 = OpSNegate %short %short_0x4400\n" +
912fd4e5da5Sopenharmony_ci            "OpReturn\n" +
913fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
914fd4e5da5Sopenharmony_ci        2, 0xFFFFBC00 /* expected to be sign extended. */),
915fd4e5da5Sopenharmony_ci    // Test case 65: Negate a negative short.
916fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
917fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
918fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
919fd4e5da5Sopenharmony_ci            "%2 = OpSNegate %ushort %ushort_0xBC00\n" +
920fd4e5da5Sopenharmony_ci            "OpReturn\n" +
921fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
922fd4e5da5Sopenharmony_ci        2, 0x4400 /* expected to be zero extended. */),
923fd4e5da5Sopenharmony_ci    // Test case 66: Negate positive short.
924fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
925fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
926fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
927fd4e5da5Sopenharmony_ci            "%2 = OpSNegate %ushort %ushort_0x4400\n" +
928fd4e5da5Sopenharmony_ci            "OpReturn\n" +
929fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
930fd4e5da5Sopenharmony_ci        2, 0xBC00 /* expected to be zero extended. */)
931fd4e5da5Sopenharmony_ci));
932fd4e5da5Sopenharmony_ci// clang-format on
933fd4e5da5Sopenharmony_ci
934fd4e5da5Sopenharmony_ciusing UIntVectorInstructionFoldingTest =
935fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCase<std::vector<uint32_t>>>;
936fd4e5da5Sopenharmony_ci
937fd4e5da5Sopenharmony_ciTEST_P(UIntVectorInstructionFoldingTest, Case) {
938fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
939fd4e5da5Sopenharmony_ci
940fd4e5da5Sopenharmony_ci  // Build module.
941fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
942fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
943fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
944fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
945fd4e5da5Sopenharmony_ci
946fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
947fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
948fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
949fd4e5da5Sopenharmony_ci  spv::Op original_opcode = inst->opcode();
950fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
951fd4e5da5Sopenharmony_ci
952fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
953fd4e5da5Sopenharmony_ci  EXPECT_EQ(succeeded, inst == nullptr || inst->opcode() != original_opcode);
954fd4e5da5Sopenharmony_ci  if (succeeded && inst != nullptr) {
955fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpCopyObject);
956fd4e5da5Sopenharmony_ci    inst = def_use_mgr->GetDef(inst->GetSingleWordInOperand(0));
957fd4e5da5Sopenharmony_ci    std::vector<spv::Op> opcodes = {spv::Op::OpConstantComposite};
958fd4e5da5Sopenharmony_ci    EXPECT_THAT(opcodes, Contains(inst->opcode()));
959fd4e5da5Sopenharmony_ci    analysis::ConstantManager* const_mrg = context->get_constant_mgr();
960fd4e5da5Sopenharmony_ci    const analysis::Constant* result = const_mrg->GetConstantFromInst(inst);
961fd4e5da5Sopenharmony_ci    EXPECT_NE(result, nullptr);
962fd4e5da5Sopenharmony_ci    if (result != nullptr) {
963fd4e5da5Sopenharmony_ci      const std::vector<const analysis::Constant*>& componenets =
964fd4e5da5Sopenharmony_ci          result->AsVectorConstant()->GetComponents();
965fd4e5da5Sopenharmony_ci      EXPECT_EQ(componenets.size(), tc.expected_result.size());
966fd4e5da5Sopenharmony_ci      for (size_t i = 0; i < componenets.size(); i++) {
967fd4e5da5Sopenharmony_ci        EXPECT_EQ(tc.expected_result[i], componenets[i]->GetU32());
968fd4e5da5Sopenharmony_ci      }
969fd4e5da5Sopenharmony_ci    }
970fd4e5da5Sopenharmony_ci  }
971fd4e5da5Sopenharmony_ci}
972fd4e5da5Sopenharmony_ci
973fd4e5da5Sopenharmony_ci// clang-format off
974fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(TestCase, UIntVectorInstructionFoldingTest,
975fd4e5da5Sopenharmony_ci::testing::Values(
976fd4e5da5Sopenharmony_ci    // Test case 0: fold 0*n
977fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<uint32_t>>(
978fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
979fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
980fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
981fd4e5da5Sopenharmony_ci            "%load = OpLoad %int %n\n" +
982fd4e5da5Sopenharmony_ci            "%2 = OpVectorShuffle %v2int %v2int_2_2 %v2int_2_3 0 3\n" +
983fd4e5da5Sopenharmony_ci            "OpReturn\n" +
984fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
985fd4e5da5Sopenharmony_ci        2, {2,3}),
986fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<uint32_t>>(
987fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
988fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
989fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
990fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
991fd4e5da5Sopenharmony_ci          "%2 = OpVectorShuffle %v2int %v2int_null %v2int_2_3 0 3\n" +
992fd4e5da5Sopenharmony_ci          "OpReturn\n" +
993fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
994fd4e5da5Sopenharmony_ci      2, {0,3}),
995fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<uint32_t>>(
996fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
997fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
998fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
999fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
1000fd4e5da5Sopenharmony_ci          "%2 = OpVectorShuffle %v2int %v2int_null %v2int_2_3 4294967295 3\n" +
1001fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1002fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1003fd4e5da5Sopenharmony_ci      2, {0,0}),
1004fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<uint32_t>>(
1005fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1006fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1007fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
1008fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
1009fd4e5da5Sopenharmony_ci          "%2 = OpVectorShuffle %v2int %v2int_null %v2int_2_3 0 4294967295 \n" +
1010fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1011fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1012fd4e5da5Sopenharmony_ci      2, {0,0}),
1013fd4e5da5Sopenharmony_ci    // Test case 4: fold bit-cast int -24 to unsigned int
1014fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<uint32_t>>(
1015fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1016fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1017fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
1018fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
1019fd4e5da5Sopenharmony_ci          "%2 = OpBitcast %v2uint %v2int_min_max\n" +
1020fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1021fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1022fd4e5da5Sopenharmony_ci      2, {2147483648, 2147483647}),
1023fd4e5da5Sopenharmony_ci    // Test case 5: fold SNegate vector of uint
1024fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<uint32_t>>(
1025fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1026fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1027fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
1028fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
1029fd4e5da5Sopenharmony_ci          "%2 = OpSNegate %v2uint %v2uint_0x3f800000_0xbf800000\n" +
1030fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1031fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1032fd4e5da5Sopenharmony_ci      2, {static_cast<uint32_t>(-0x3f800000), static_cast<uint32_t>(-0xbf800000)}),
1033fd4e5da5Sopenharmony_ci    // Test case 6: fold vector components of uint (incuding integer overflow)
1034fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<uint32_t>>(
1035fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1036fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1037fd4e5da5Sopenharmony_ci          "%2 = OpIAdd %v2uint %v2uint_0x3f800000_0xbf800000 %v2uint_0x3f800000_0xbf800000\n" +
1038fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1039fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1040fd4e5da5Sopenharmony_ci      2, {0x7f000000u, 0x7f000000u})
1041fd4e5da5Sopenharmony_ci));
1042fd4e5da5Sopenharmony_ci// clang-format on
1043fd4e5da5Sopenharmony_ci
1044fd4e5da5Sopenharmony_ciusing IntVectorInstructionFoldingTest =
1045fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCase<std::vector<int32_t>>>;
1046fd4e5da5Sopenharmony_ci
1047fd4e5da5Sopenharmony_ciTEST_P(IntVectorInstructionFoldingTest, Case) {
1048fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
1049fd4e5da5Sopenharmony_ci
1050fd4e5da5Sopenharmony_ci  // Build module.
1051fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
1052fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
1053fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1054fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
1055fd4e5da5Sopenharmony_ci
1056fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
1057fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
1058fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
1059fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
1060fd4e5da5Sopenharmony_ci
1061fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
1062fd4e5da5Sopenharmony_ci  EXPECT_TRUE(succeeded);
1063fd4e5da5Sopenharmony_ci  if (succeeded && inst != nullptr) {
1064fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpCopyObject);
1065fd4e5da5Sopenharmony_ci    inst = def_use_mgr->GetDef(inst->GetSingleWordInOperand(0));
1066fd4e5da5Sopenharmony_ci    std::vector<spv::Op> opcodes = {spv::Op::OpConstantComposite};
1067fd4e5da5Sopenharmony_ci    EXPECT_THAT(opcodes, Contains(inst->opcode()));
1068fd4e5da5Sopenharmony_ci    analysis::ConstantManager* const_mrg = context->get_constant_mgr();
1069fd4e5da5Sopenharmony_ci    const analysis::Constant* result = const_mrg->GetConstantFromInst(inst);
1070fd4e5da5Sopenharmony_ci    EXPECT_NE(result, nullptr);
1071fd4e5da5Sopenharmony_ci    if (result != nullptr) {
1072fd4e5da5Sopenharmony_ci      const std::vector<const analysis::Constant*>& componenets =
1073fd4e5da5Sopenharmony_ci          result->AsVectorConstant()->GetComponents();
1074fd4e5da5Sopenharmony_ci      EXPECT_EQ(componenets.size(), tc.expected_result.size());
1075fd4e5da5Sopenharmony_ci      for (size_t i = 0; i < componenets.size(); i++) {
1076fd4e5da5Sopenharmony_ci        EXPECT_EQ(tc.expected_result[i], componenets[i]->GetS32());
1077fd4e5da5Sopenharmony_ci      }
1078fd4e5da5Sopenharmony_ci    }
1079fd4e5da5Sopenharmony_ci  }
1080fd4e5da5Sopenharmony_ci}
1081fd4e5da5Sopenharmony_ci
1082fd4e5da5Sopenharmony_ci// clang-format off
1083fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(TestCase, IntVectorInstructionFoldingTest,
1084fd4e5da5Sopenharmony_ci::testing::Values(
1085fd4e5da5Sopenharmony_ci    // Test case 0: fold negate of a vector
1086fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<int32_t>>(
1087fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1088fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1089fd4e5da5Sopenharmony_ci          "%2 = OpSNegate %v2int %v2int_2_3\n" +
1090fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1091fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1092fd4e5da5Sopenharmony_ci      2, {-2, -3}),
1093fd4e5da5Sopenharmony_ci    // Test case 1: fold negate of a vector containing negative values.
1094fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<int32_t>>(
1095fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1096fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1097fd4e5da5Sopenharmony_ci          "%2 = OpSNegate %v2int %v2int_n1_n24\n" +
1098fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1099fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1100fd4e5da5Sopenharmony_ci      2, {1, 24}),
1101fd4e5da5Sopenharmony_ci    // Test case 2: fold negate of a vector at the limits
1102fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<int32_t>>(
1103fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1104fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1105fd4e5da5Sopenharmony_ci          "%2 = OpSNegate %v2int %v2int_min_max\n" +
1106fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1107fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1108fd4e5da5Sopenharmony_ci      2, {INT_MIN, -INT_MAX}),
1109fd4e5da5Sopenharmony_ci    // Test case 3: fold vector components of int
1110fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<int32_t>>(
1111fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1112fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1113fd4e5da5Sopenharmony_ci          "%2 = OpIMul %v2int %v2int_2_3 %v2int_2_3\n" +
1114fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1115fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1116fd4e5da5Sopenharmony_ci      2, {4,9})
1117fd4e5da5Sopenharmony_ci));
1118fd4e5da5Sopenharmony_ci// clang-format on
1119fd4e5da5Sopenharmony_ci
1120fd4e5da5Sopenharmony_ciusing DoubleVectorInstructionFoldingTest =
1121fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCase<std::vector<double>>>;
1122fd4e5da5Sopenharmony_ci
1123fd4e5da5Sopenharmony_ciTEST_P(DoubleVectorInstructionFoldingTest, Case) {
1124fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
1125fd4e5da5Sopenharmony_ci
1126fd4e5da5Sopenharmony_ci  // Build module.
1127fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
1128fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
1129fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1130fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
1131fd4e5da5Sopenharmony_ci
1132fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
1133fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
1134fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
1135fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
1136fd4e5da5Sopenharmony_ci
1137fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
1138fd4e5da5Sopenharmony_ci  EXPECT_TRUE(succeeded);
1139fd4e5da5Sopenharmony_ci  if (succeeded && inst != nullptr) {
1140fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpCopyObject);
1141fd4e5da5Sopenharmony_ci    inst = def_use_mgr->GetDef(inst->GetSingleWordInOperand(0));
1142fd4e5da5Sopenharmony_ci    std::vector<spv::Op> opcodes = {spv::Op::OpConstantComposite};
1143fd4e5da5Sopenharmony_ci    EXPECT_THAT(opcodes, Contains(inst->opcode()));
1144fd4e5da5Sopenharmony_ci    analysis::ConstantManager* const_mrg = context->get_constant_mgr();
1145fd4e5da5Sopenharmony_ci    const analysis::Constant* result = const_mrg->GetConstantFromInst(inst);
1146fd4e5da5Sopenharmony_ci    EXPECT_NE(result, nullptr);
1147fd4e5da5Sopenharmony_ci    if (result != nullptr) {
1148fd4e5da5Sopenharmony_ci      const std::vector<const analysis::Constant*>& componenets =
1149fd4e5da5Sopenharmony_ci          result->AsVectorConstant()->GetComponents();
1150fd4e5da5Sopenharmony_ci      EXPECT_EQ(componenets.size(), tc.expected_result.size());
1151fd4e5da5Sopenharmony_ci      for (size_t i = 0; i < componenets.size(); i++) {
1152fd4e5da5Sopenharmony_ci        EXPECT_EQ(tc.expected_result[i], componenets[i]->GetDouble());
1153fd4e5da5Sopenharmony_ci      }
1154fd4e5da5Sopenharmony_ci    }
1155fd4e5da5Sopenharmony_ci  }
1156fd4e5da5Sopenharmony_ci}
1157fd4e5da5Sopenharmony_ci
1158fd4e5da5Sopenharmony_ci// clang-format off
1159fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(TestCase, DoubleVectorInstructionFoldingTest,
1160fd4e5da5Sopenharmony_ci::testing::Values(
1161fd4e5da5Sopenharmony_ci   // Test case 0: bit-cast int {0x3FF00000,0x00000000,0xC05FD666,0x66666666}
1162fd4e5da5Sopenharmony_ci   //              to double vector
1163fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<double>>(
1164fd4e5da5Sopenharmony_ci       Header() + "%main = OpFunction %void None %void_func\n" +
1165fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
1166fd4e5da5Sopenharmony_ci           "%2 = OpBitcast %v2double %v4int_0x3FF00000_0x00000000_0xC05FD666_0x66666666\n" +
1167fd4e5da5Sopenharmony_ci           "OpReturn\n" +
1168fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
1169fd4e5da5Sopenharmony_ci       2, {1.0,-127.35}),
1170fd4e5da5Sopenharmony_ci   // Test case 1: OpVectorTimesMatrix Non-Zero Zero {{0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}} {1.0, 2.0, 3.0, 4.0} {0.0, 0.0, 0.0, 0.0}
1171fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<double>>(
1172fd4e5da5Sopenharmony_ci       Header() +
1173fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1174fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1175fd4e5da5Sopenharmony_ci       "%2 = OpVectorTimesMatrix %v4double %v4double_1_2_3_4 %mat4v4double_null\n" +
1176fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1177fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1178fd4e5da5Sopenharmony_ci       2, {0.0,0.0,0.0,0.0}),
1179fd4e5da5Sopenharmony_ci   // Test case 2: OpVectorTimesMatrix Zero Non-Zero {{1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}} {0.0, 0.0, 0.0, 0.0} {0.0, 0.0, 0.0, 0.0}
1180fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<double>>(
1181fd4e5da5Sopenharmony_ci       Header() +
1182fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1183fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1184fd4e5da5Sopenharmony_ci       "%2 = OpVectorTimesMatrix %v4double %v4double_null %mat4v4double_1_2_3_4\n" +
1185fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1186fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1187fd4e5da5Sopenharmony_ci       2, {0.0,0.0,0.0,0.0}),
1188fd4e5da5Sopenharmony_ci   // Test case 3: OpVectorTimesMatrix Non-Zero Non-Zero {{1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}} {1.0, 2.0, 3.0, 4.0} {30.0, 30.0, 30.0, 30.0}
1189fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<double>>(
1190fd4e5da5Sopenharmony_ci       Header() +
1191fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1192fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1193fd4e5da5Sopenharmony_ci       "%2 = OpVectorTimesMatrix %v4double %v4double_1_2_3_4 %mat4v4double_1_2_3_4\n" +
1194fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1195fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1196fd4e5da5Sopenharmony_ci       2, {30.0,30.0,30.0,30.0}),
1197fd4e5da5Sopenharmony_ci   // Test case 4: OpVectorTimesMatrix Non-Zero Non-Zero {{1.0, 2.0, 3.0, 4.0}, Null, {1.0, 2.0, 3.0, 4.0}, Null} {1.0, 2.0, 3.0, 4.0} {30.0, 0.0, 30.0, 0.0}
1198fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<double>>(
1199fd4e5da5Sopenharmony_ci       Header() +
1200fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1201fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1202fd4e5da5Sopenharmony_ci       "%2 = OpVectorTimesMatrix %v4double %v4double_1_2_3_4 %mat4v4double_1_2_3_4_null\n" +
1203fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1204fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1205fd4e5da5Sopenharmony_ci       2, {30.0,0.0,30.0,0.0}),
1206fd4e5da5Sopenharmony_ci   // Test case 5: OpMatrixTimesVector Zero Non-Zero {1.0, 2.0, 3.0, 4.0} {{0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}} {0.0, 0.0, 0.0, 0.0}
1207fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<double>>(
1208fd4e5da5Sopenharmony_ci       Header() +
1209fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1210fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1211fd4e5da5Sopenharmony_ci       "%2 = OpMatrixTimesVector %v4double %mat4v4double_null %v4double_1_2_3_4\n" +
1212fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1213fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1214fd4e5da5Sopenharmony_ci       2, {0.0,0.0,0.0,0.0}),
1215fd4e5da5Sopenharmony_ci   // Test case 6: OpMatrixTimesVector Non-Zero Zero {{1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}} {0.0, 0.0, 0.0, 0.0} {0.0, 0.0, 0.0, 0.0}
1216fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<double>>(
1217fd4e5da5Sopenharmony_ci       Header() +
1218fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1219fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1220fd4e5da5Sopenharmony_ci       "%2 = OpMatrixTimesVector %v4double %mat4v4double_1_2_3_4 %v4double_null\n" +
1221fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1222fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1223fd4e5da5Sopenharmony_ci       2, {0.0,0.0,0.0,0.0}),
1224fd4e5da5Sopenharmony_ci   // Test case 7: OpMatrixTimesVector Non-Zero Non-Zero {1.0, 2.0, 3.0, 4.0} {{1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}} {10.0, 20.0, 30.0, 40.0}
1225fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<double>>(
1226fd4e5da5Sopenharmony_ci       Header() +
1227fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1228fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1229fd4e5da5Sopenharmony_ci       "%2 = OpMatrixTimesVector %v4double %mat4v4double_1_2_3_4 %v4double_1_2_3_4\n" +
1230fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1231fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1232fd4e5da5Sopenharmony_ci       2, {10.0,20.0,30.0,40.0}),
1233fd4e5da5Sopenharmony_ci   // Test case 8: OpMatrixTimesVector Non-Zero Non-Zero {1.0, 2.0, 3.0, 4.0} {{1.0, 2.0, 3.0, 4.0}, Null, {1.0, 2.0, 3.0, 4.0}, Null} {10.0, 20.0, 30.0, 40.0}
1234fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<double>>(
1235fd4e5da5Sopenharmony_ci       Header() +
1236fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1237fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1238fd4e5da5Sopenharmony_ci       "%2 = OpMatrixTimesVector %v4double %mat4v4double_1_2_3_4_null %v4double_1_2_3_4\n" +
1239fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1240fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1241fd4e5da5Sopenharmony_ci       2, {4.0,8.0,12.0,16.0})
1242fd4e5da5Sopenharmony_ci));
1243fd4e5da5Sopenharmony_ci
1244fd4e5da5Sopenharmony_ciusing FloatVectorInstructionFoldingTest =
1245fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCase<std::vector<float>>>;
1246fd4e5da5Sopenharmony_ci
1247fd4e5da5Sopenharmony_ciTEST_P(FloatVectorInstructionFoldingTest, Case) {
1248fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
1249fd4e5da5Sopenharmony_ci
1250fd4e5da5Sopenharmony_ci  // Build module.
1251fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
1252fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
1253fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1254fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
1255fd4e5da5Sopenharmony_ci
1256fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
1257fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
1258fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
1259fd4e5da5Sopenharmony_ci  spv::Op original_opcode = inst->opcode();
1260fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
1261fd4e5da5Sopenharmony_ci
1262fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
1263fd4e5da5Sopenharmony_ci  EXPECT_EQ(succeeded, inst == nullptr || inst->opcode() != original_opcode);
1264fd4e5da5Sopenharmony_ci  if (succeeded && inst != nullptr) {
1265fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpCopyObject);
1266fd4e5da5Sopenharmony_ci    inst = def_use_mgr->GetDef(inst->GetSingleWordInOperand(0));
1267fd4e5da5Sopenharmony_ci    std::vector<spv::Op> opcodes = {spv::Op::OpConstantComposite};
1268fd4e5da5Sopenharmony_ci    EXPECT_THAT(opcodes, Contains(inst->opcode()));
1269fd4e5da5Sopenharmony_ci    analysis::ConstantManager* const_mrg = context->get_constant_mgr();
1270fd4e5da5Sopenharmony_ci    const analysis::Constant* result = const_mrg->GetConstantFromInst(inst);
1271fd4e5da5Sopenharmony_ci    EXPECT_NE(result, nullptr);
1272fd4e5da5Sopenharmony_ci    if (result != nullptr) {
1273fd4e5da5Sopenharmony_ci      const std::vector<const analysis::Constant*>& componenets =
1274fd4e5da5Sopenharmony_ci          result->AsVectorConstant()->GetComponents();
1275fd4e5da5Sopenharmony_ci      EXPECT_EQ(componenets.size(), tc.expected_result.size());
1276fd4e5da5Sopenharmony_ci      for (size_t i = 0; i < componenets.size(); i++) {
1277fd4e5da5Sopenharmony_ci        EXPECT_EQ(tc.expected_result[i], componenets[i]->GetFloat());
1278fd4e5da5Sopenharmony_ci      }
1279fd4e5da5Sopenharmony_ci    }
1280fd4e5da5Sopenharmony_ci  }
1281fd4e5da5Sopenharmony_ci}
1282fd4e5da5Sopenharmony_ci
1283fd4e5da5Sopenharmony_ci// clang-format off
1284fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(TestCase, FloatVectorInstructionFoldingTest,
1285fd4e5da5Sopenharmony_ci::testing::Values(
1286fd4e5da5Sopenharmony_ci   // Test case 0: FMix {2.0, 2.0}, {2.0, 3.0} {0.2,0.5}
1287fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<float>>(
1288fd4e5da5Sopenharmony_ci       Header() + "%main = OpFunction %void None %void_func\n" +
1289fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
1290fd4e5da5Sopenharmony_ci           "%2 = OpExtInst %v2float %1 FMix %v2float_2_3 %v2float_0_0 %v2float_0p2_0p5\n" +
1291fd4e5da5Sopenharmony_ci           "OpReturn\n" +
1292fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
1293fd4e5da5Sopenharmony_ci       2, {1.6f,1.5f}),
1294fd4e5da5Sopenharmony_ci   // Test case 1: bit-cast unsigned int vector {0x3f800000, 0xbf800000} to
1295fd4e5da5Sopenharmony_ci   //              float vector
1296fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<float>>(
1297fd4e5da5Sopenharmony_ci       Header() + "%main = OpFunction %void None %void_func\n" +
1298fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
1299fd4e5da5Sopenharmony_ci           "%2 = OpBitcast %v2float %v2uint_0x3f800000_0xbf800000\n" +
1300fd4e5da5Sopenharmony_ci           "OpReturn\n" +
1301fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
1302fd4e5da5Sopenharmony_ci       2, {1.0f,-1.0f}),
1303fd4e5da5Sopenharmony_ci   // Test case 2: bit-cast long int 0xbf8000003f800000 to float vector
1304fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<float>>(
1305fd4e5da5Sopenharmony_ci       Header() + "%main = OpFunction %void None %void_func\n" +
1306fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
1307fd4e5da5Sopenharmony_ci           "%2 = OpBitcast %v2float %long_0xbf8000003f800000\n" +
1308fd4e5da5Sopenharmony_ci           "OpReturn\n" +
1309fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
1310fd4e5da5Sopenharmony_ci       2, {1.0f,-1.0f}),
1311fd4e5da5Sopenharmony_ci   // Test case 3: OpVectorTimesMatrix Non-Zero Zero {{0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}} {1.0, 2.0, 3.0, 4.0} {0.0, 0.0, 0.0, 0.0}
1312fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<float>>(
1313fd4e5da5Sopenharmony_ci       Header() +
1314fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1315fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1316fd4e5da5Sopenharmony_ci       "%2 = OpVectorTimesMatrix %v4float %v4float_1_2_3_4 %mat4v4float_null\n" +
1317fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1318fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1319fd4e5da5Sopenharmony_ci       2, {0.0f,0.0f,0.0f,0.0f}),
1320fd4e5da5Sopenharmony_ci   // Test case 4: OpVectorTimesMatrix Non-Zero Non-Zero {{1.0, 2.0, 3.0, 4.0}, Null, {1.0, 2.0, 3.0, 4.0}, Null} {1.0, 2.0, 3.0, 4.0} {30.0, 0.0, 30.0, 0.0}
1321fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<float>>(
1322fd4e5da5Sopenharmony_ci       Header() +
1323fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1324fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1325fd4e5da5Sopenharmony_ci       "%2 = OpVectorTimesMatrix %v4float %v4float_1_2_3_4 %mat4v4float_1_2_3_4_null\n" +
1326fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1327fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1328fd4e5da5Sopenharmony_ci       2, {30.0,0.0,30.0,0.0}),
1329fd4e5da5Sopenharmony_ci   // Test case 5: OpVectorTimesMatrix Zero Non-Zero {{1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}} {0.0, 0.0, 0.0, 0.0} {0.0, 0.0, 0.0, 0.0}
1330fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<float>>(
1331fd4e5da5Sopenharmony_ci       Header() +
1332fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1333fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1334fd4e5da5Sopenharmony_ci       "%2 = OpVectorTimesMatrix %v4float %v4float_null %mat4v4float_1_2_3_4\n" +
1335fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1336fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1337fd4e5da5Sopenharmony_ci       2, {0.0f,0.0f,0.0f,0.0f}),
1338fd4e5da5Sopenharmony_ci   // Test case 6: OpVectorTimesMatrix Non-Zero Non-Zero {{1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}} {1.0, 2.0, 3.0, 4.0} {30.0, 30.0, 30.0, 30.0}
1339fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<float>>(
1340fd4e5da5Sopenharmony_ci       Header() +
1341fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1342fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1343fd4e5da5Sopenharmony_ci       "%2 = OpVectorTimesMatrix %v4float %v4float_1_2_3_4 %mat4v4float_1_2_3_4\n" +
1344fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1345fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1346fd4e5da5Sopenharmony_ci       2, {30.0f,30.0f,30.0f,30.0f}),
1347fd4e5da5Sopenharmony_ci   // Test case 7: OpMatrixTimesVector Zero Non-Zero {1.0, 2.0, 3.0, 4.0} {{0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0}} {0.0, 0.0, 0.0, 0.0}
1348fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<float>>(
1349fd4e5da5Sopenharmony_ci       Header() +
1350fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1351fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1352fd4e5da5Sopenharmony_ci       "%2 = OpMatrixTimesVector %v4float %mat4v4float_null %v4float_1_2_3_4\n" +
1353fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1354fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1355fd4e5da5Sopenharmony_ci       2, {0.0f,0.0f,0.0f,0.0f}),
1356fd4e5da5Sopenharmony_ci   // Test case 8: OpMatrixTimesVector Non-Zero Zero {{1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}} {0.0, 0.0, 0.0, 0.0} {0.0, 0.0, 0.0, 0.0}
1357fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<float>>(
1358fd4e5da5Sopenharmony_ci       Header() +
1359fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1360fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1361fd4e5da5Sopenharmony_ci       "%2 = OpMatrixTimesVector %v4float %mat4v4float_1_2_3_4 %v4float_null\n" +
1362fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1363fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1364fd4e5da5Sopenharmony_ci       2, {0.0f,0.0f,0.0f,0.0f}),
1365fd4e5da5Sopenharmony_ci   // Test case 9: OpMatrixTimesVector Non-Zero Non-Zero {1.0, 2.0, 3.0, 4.0} {{1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}, {1.0, 2.0, 3.0, 4.0}} {10.0, 20.0, 30.0, 40.0}
1366fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<float>>(
1367fd4e5da5Sopenharmony_ci       Header() +
1368fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1369fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1370fd4e5da5Sopenharmony_ci       "%2 = OpMatrixTimesVector %v4float %mat4v4float_1_2_3_4 %v4float_1_2_3_4\n" +
1371fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1372fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1373fd4e5da5Sopenharmony_ci       2, {10.0f,20.0f,30.0f,40.0f}),
1374fd4e5da5Sopenharmony_ci   // Test case 10: OpMatrixTimesVector Non-Zero Non-Zero {1.0, 2.0, 3.0, 4.0} {{1.0, 2.0, 3.0, 4.0}, Null, {1.0, 2.0, 3.0, 4.0}, Null} {10.0, 20.0, 30.0, 40.0}
1375fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<float>>(
1376fd4e5da5Sopenharmony_ci       Header() +
1377fd4e5da5Sopenharmony_ci       "%main = OpFunction %void None %void_func\n" +
1378fd4e5da5Sopenharmony_ci       "%main_lab = OpLabel\n" +
1379fd4e5da5Sopenharmony_ci       "%2 = OpMatrixTimesVector %v4float %mat4v4float_1_2_3_4_null %v4float_1_2_3_4\n" +
1380fd4e5da5Sopenharmony_ci       "OpReturn\n" +
1381fd4e5da5Sopenharmony_ci       "OpFunctionEnd",
1382fd4e5da5Sopenharmony_ci       2, {4.0,8.0,12.0,16.0})
1383fd4e5da5Sopenharmony_ci));
1384fd4e5da5Sopenharmony_ci// clang-format on
1385fd4e5da5Sopenharmony_ci
1386fd4e5da5Sopenharmony_ciusing FloatMatrixInstructionFoldingTest = ::testing::TestWithParam<
1387fd4e5da5Sopenharmony_ci    InstructionFoldingCase<std::vector<std::vector<float>>>>;
1388fd4e5da5Sopenharmony_ci
1389fd4e5da5Sopenharmony_ciTEST_P(FloatMatrixInstructionFoldingTest, Case) {
1390fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
1391fd4e5da5Sopenharmony_ci
1392fd4e5da5Sopenharmony_ci  // Build module.
1393fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
1394fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
1395fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1396fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
1397fd4e5da5Sopenharmony_ci
1398fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
1399fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
1400fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
1401fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
1402fd4e5da5Sopenharmony_ci
1403fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
1404fd4e5da5Sopenharmony_ci  EXPECT_TRUE(succeeded);
1405fd4e5da5Sopenharmony_ci  EXPECT_EQ(inst->opcode(), spv::Op::OpCopyObject);
1406fd4e5da5Sopenharmony_ci
1407fd4e5da5Sopenharmony_ci  if (inst->opcode() == spv::Op::OpCopyObject) {
1408fd4e5da5Sopenharmony_ci    inst = def_use_mgr->GetDef(inst->GetSingleWordInOperand(0));
1409fd4e5da5Sopenharmony_ci    analysis::ConstantManager* const_mgr = context->get_constant_mgr();
1410fd4e5da5Sopenharmony_ci    const analysis::Constant* result = const_mgr->GetConstantFromInst(inst);
1411fd4e5da5Sopenharmony_ci    EXPECT_NE(result, nullptr);
1412fd4e5da5Sopenharmony_ci    if (result != nullptr) {
1413fd4e5da5Sopenharmony_ci      std::vector<const analysis::Constant*> matrix =
1414fd4e5da5Sopenharmony_ci          result->AsMatrixConstant()->GetComponents();
1415fd4e5da5Sopenharmony_ci      EXPECT_EQ(matrix.size(), tc.expected_result.size());
1416fd4e5da5Sopenharmony_ci      for (size_t c = 0; c < matrix.size(); c++) {
1417fd4e5da5Sopenharmony_ci        if (matrix[c]->AsNullConstant() != nullptr) {
1418fd4e5da5Sopenharmony_ci          matrix[c] = const_mgr->GetNullCompositeConstant(matrix[c]->type());
1419fd4e5da5Sopenharmony_ci        }
1420fd4e5da5Sopenharmony_ci        const analysis::VectorConstant* column_const =
1421fd4e5da5Sopenharmony_ci            matrix[c]->AsVectorConstant();
1422fd4e5da5Sopenharmony_ci        ASSERT_NE(column_const, nullptr);
1423fd4e5da5Sopenharmony_ci        const std::vector<const analysis::Constant*>& column =
1424fd4e5da5Sopenharmony_ci            column_const->GetComponents();
1425fd4e5da5Sopenharmony_ci        EXPECT_EQ(column.size(), tc.expected_result[c].size());
1426fd4e5da5Sopenharmony_ci        for (size_t r = 0; r < column.size(); r++) {
1427fd4e5da5Sopenharmony_ci          EXPECT_EQ(tc.expected_result[c][r], column[r]->GetFloat());
1428fd4e5da5Sopenharmony_ci        }
1429fd4e5da5Sopenharmony_ci      }
1430fd4e5da5Sopenharmony_ci    }
1431fd4e5da5Sopenharmony_ci  }
1432fd4e5da5Sopenharmony_ci}
1433fd4e5da5Sopenharmony_ci
1434fd4e5da5Sopenharmony_ci// clang-format off
1435fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(TestCase, FloatMatrixInstructionFoldingTest,
1436fd4e5da5Sopenharmony_ci::testing::Values(
1437fd4e5da5Sopenharmony_ci   // Test case 0: OpTranspose square null matrix
1438fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<std::vector<float>>>(
1439fd4e5da5Sopenharmony_ci       Header() + "%main = OpFunction %void None %void_func\n" +
1440fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
1441fd4e5da5Sopenharmony_ci           "%2 = OpTranspose %mat4v4float %mat4v4float_null\n" +
1442fd4e5da5Sopenharmony_ci           "OpReturn\n" +
1443fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
1444fd4e5da5Sopenharmony_ci       2, {{0.0f, 0.0f, 0.0f, 0.0f},{0.0f, 0.0f, 0.0f, 0.0f},{0.0f, 0.0f, 0.0f, 0.0f},{0.0f, 0.0f, 0.0f, 0.0f}}),
1445fd4e5da5Sopenharmony_ci   // Test case 1: OpTranspose rectangular null matrix
1446fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<std::vector<float>>>(
1447fd4e5da5Sopenharmony_ci       Header() + "%main = OpFunction %void None %void_func\n" +
1448fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
1449fd4e5da5Sopenharmony_ci           "%2 = OpTranspose %mat4v2float %mat2v4float_null\n" +
1450fd4e5da5Sopenharmony_ci           "OpReturn\n" +
1451fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
1452fd4e5da5Sopenharmony_ci       2, {{0.0f, 0.0f},{0.0f, 0.0f},{0.0f, 0.0f},{0.0f, 0.0f}}),
1453fd4e5da5Sopenharmony_ci   InstructionFoldingCase<std::vector<std::vector<float>>>(
1454fd4e5da5Sopenharmony_ci       Header() + "%main = OpFunction %void None %void_func\n" +
1455fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
1456fd4e5da5Sopenharmony_ci           "%2 = OpTranspose %mat4v4float %mat4v4float_1_2_3_4\n" +
1457fd4e5da5Sopenharmony_ci           "OpReturn\n" +
1458fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
1459fd4e5da5Sopenharmony_ci       2, {{1.0f, 1.0f, 1.0f, 1.0f},{2.0f, 2.0f, 2.0f, 2.0f},{3.0f, 3.0f, 3.0f, 3.0f},{4.0f, 4.0f, 4.0f, 4.0f}})
1460fd4e5da5Sopenharmony_ci));
1461fd4e5da5Sopenharmony_ci// clang-format on
1462fd4e5da5Sopenharmony_ci
1463fd4e5da5Sopenharmony_ciusing BooleanInstructionFoldingTest =
1464fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCase<bool>>;
1465fd4e5da5Sopenharmony_ci
1466fd4e5da5Sopenharmony_ciTEST_P(BooleanInstructionFoldingTest, Case) {
1467fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
1468fd4e5da5Sopenharmony_ci
1469fd4e5da5Sopenharmony_ci  // Build module.
1470fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
1471fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
1472fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
1473fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
1474fd4e5da5Sopenharmony_ci
1475fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
1476fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
1477fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
1478fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
1479fd4e5da5Sopenharmony_ci
1480fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
1481fd4e5da5Sopenharmony_ci  EXPECT_TRUE(succeeded);
1482fd4e5da5Sopenharmony_ci  if (inst != nullptr) {
1483fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpCopyObject);
1484fd4e5da5Sopenharmony_ci    inst = def_use_mgr->GetDef(inst->GetSingleWordInOperand(0));
1485fd4e5da5Sopenharmony_ci    std::vector<spv::Op> bool_opcodes = {spv::Op::OpConstantTrue,
1486fd4e5da5Sopenharmony_ci                                         spv::Op::OpConstantFalse};
1487fd4e5da5Sopenharmony_ci    EXPECT_THAT(bool_opcodes, Contains(inst->opcode()));
1488fd4e5da5Sopenharmony_ci    analysis::ConstantManager* const_mrg = context->get_constant_mgr();
1489fd4e5da5Sopenharmony_ci    const analysis::BoolConstant* result =
1490fd4e5da5Sopenharmony_ci        const_mrg->GetConstantFromInst(inst)->AsBoolConstant();
1491fd4e5da5Sopenharmony_ci    EXPECT_NE(result, nullptr);
1492fd4e5da5Sopenharmony_ci    if (result != nullptr) {
1493fd4e5da5Sopenharmony_ci      EXPECT_EQ(result->value(), tc.expected_result);
1494fd4e5da5Sopenharmony_ci    }
1495fd4e5da5Sopenharmony_ci  }
1496fd4e5da5Sopenharmony_ci}
1497fd4e5da5Sopenharmony_ci
1498fd4e5da5Sopenharmony_ci// clang-format off
1499fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(TestCase, BooleanInstructionFoldingTest,
1500fd4e5da5Sopenharmony_ci                        ::testing::Values(
1501fd4e5da5Sopenharmony_ci  // Test case 0: fold true || n
1502fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1503fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1504fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1505fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_bool Function\n" +
1506fd4e5da5Sopenharmony_ci          "%load = OpLoad %bool %n\n" +
1507fd4e5da5Sopenharmony_ci          "%2 = OpLogicalOr %bool %true %load\n" +
1508fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1509fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1510fd4e5da5Sopenharmony_ci      2, true),
1511fd4e5da5Sopenharmony_ci  // Test case 1: fold n || true
1512fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1513fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1514fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1515fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_bool Function\n" +
1516fd4e5da5Sopenharmony_ci          "%load = OpLoad %bool %n\n" +
1517fd4e5da5Sopenharmony_ci          "%2 = OpLogicalOr %bool %load %true\n" +
1518fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1519fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1520fd4e5da5Sopenharmony_ci      2, true),
1521fd4e5da5Sopenharmony_ci  // Test case 2: fold false && n
1522fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1523fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1524fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1525fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_bool Function\n" +
1526fd4e5da5Sopenharmony_ci          "%load = OpLoad %bool %n\n" +
1527fd4e5da5Sopenharmony_ci          "%2 = OpLogicalAnd %bool %false %load\n" +
1528fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1529fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1530fd4e5da5Sopenharmony_ci      2, false),
1531fd4e5da5Sopenharmony_ci  // Test case 3: fold n && false
1532fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1533fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1534fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1535fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_bool Function\n" +
1536fd4e5da5Sopenharmony_ci          "%load = OpLoad %bool %n\n" +
1537fd4e5da5Sopenharmony_ci          "%2 = OpLogicalAnd %bool %load %false\n" +
1538fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1539fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1540fd4e5da5Sopenharmony_ci      2, false),
1541fd4e5da5Sopenharmony_ci  // Test case 4: fold n < 0 (unsigned)
1542fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1543fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1544fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1545fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
1546fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
1547fd4e5da5Sopenharmony_ci          "%2 = OpULessThan %bool %load %uint_0\n" +
1548fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1549fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1550fd4e5da5Sopenharmony_ci      2, false),
1551fd4e5da5Sopenharmony_ci  // Test case 5: fold UINT_MAX < n (unsigned)
1552fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1553fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1554fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1555fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
1556fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
1557fd4e5da5Sopenharmony_ci          "%2 = OpULessThan %bool %uint_max %load\n" +
1558fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1559fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1560fd4e5da5Sopenharmony_ci      2, false),
1561fd4e5da5Sopenharmony_ci  // Test case 6: fold INT_MAX < n (signed)
1562fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1563fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1564fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1565fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
1566fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
1567fd4e5da5Sopenharmony_ci          "%2 = OpSLessThan %bool %int_max %load\n" +
1568fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1569fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1570fd4e5da5Sopenharmony_ci      2, false),
1571fd4e5da5Sopenharmony_ci  // Test case 7: fold n < INT_MIN (signed)
1572fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1573fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1574fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1575fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
1576fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
1577fd4e5da5Sopenharmony_ci          "%2 = OpSLessThan %bool %load %int_min\n" +
1578fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1579fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1580fd4e5da5Sopenharmony_ci      2, false),
1581fd4e5da5Sopenharmony_ci  // Test case 8: fold 0 > n (unsigned)
1582fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1583fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1584fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1585fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
1586fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
1587fd4e5da5Sopenharmony_ci          "%2 = OpUGreaterThan %bool %uint_0 %load\n" +
1588fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1589fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1590fd4e5da5Sopenharmony_ci      2, false),
1591fd4e5da5Sopenharmony_ci  // Test case 9: fold n > UINT_MAX (unsigned)
1592fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1593fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1594fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1595fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
1596fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
1597fd4e5da5Sopenharmony_ci          "%2 = OpUGreaterThan %bool %load %uint_max\n" +
1598fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1599fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1600fd4e5da5Sopenharmony_ci      2, false),
1601fd4e5da5Sopenharmony_ci  // Test case 10: fold n > INT_MAX (signed)
1602fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1603fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1604fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1605fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
1606fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
1607fd4e5da5Sopenharmony_ci          "%2 = OpSGreaterThan %bool %load %int_max\n" +
1608fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1609fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1610fd4e5da5Sopenharmony_ci      2, false),
1611fd4e5da5Sopenharmony_ci  // Test case 11: fold INT_MIN > n (signed)
1612fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1613fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1614fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1615fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
1616fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
1617fd4e5da5Sopenharmony_ci          "%2 = OpSGreaterThan %bool %int_min %load\n" +
1618fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1619fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1620fd4e5da5Sopenharmony_ci      2, false),
1621fd4e5da5Sopenharmony_ci  // Test case 12: fold 0 <= n (unsigned)
1622fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1623fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1624fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1625fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
1626fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
1627fd4e5da5Sopenharmony_ci          "%2 = OpULessThanEqual %bool %uint_0 %load\n" +
1628fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1629fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1630fd4e5da5Sopenharmony_ci      2, true),
1631fd4e5da5Sopenharmony_ci  // Test case 13: fold n <= UINT_MAX (unsigned)
1632fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1633fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1634fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1635fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
1636fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
1637fd4e5da5Sopenharmony_ci          "%2 = OpULessThanEqual %bool %load %uint_max\n" +
1638fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1639fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1640fd4e5da5Sopenharmony_ci      2, true),
1641fd4e5da5Sopenharmony_ci  // Test case 14: fold INT_MIN <= n (signed)
1642fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1643fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1644fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1645fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
1646fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
1647fd4e5da5Sopenharmony_ci          "%2 = OpSLessThanEqual %bool %int_min %load\n" +
1648fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1649fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1650fd4e5da5Sopenharmony_ci      2, true),
1651fd4e5da5Sopenharmony_ci  // Test case 15: fold n <= INT_MAX (signed)
1652fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1653fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1654fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1655fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
1656fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
1657fd4e5da5Sopenharmony_ci          "%2 = OpSLessThanEqual %bool %load %int_max\n" +
1658fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1659fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1660fd4e5da5Sopenharmony_ci      2, true),
1661fd4e5da5Sopenharmony_ci  // Test case 16: fold n >= 0 (unsigned)
1662fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1663fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1664fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1665fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
1666fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
1667fd4e5da5Sopenharmony_ci          "%2 = OpUGreaterThanEqual %bool %load %uint_0\n" +
1668fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1669fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1670fd4e5da5Sopenharmony_ci      2, true),
1671fd4e5da5Sopenharmony_ci  // Test case 17: fold UINT_MAX >= n (unsigned)
1672fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1673fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1674fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1675fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_uint Function\n" +
1676fd4e5da5Sopenharmony_ci          "%load = OpLoad %uint %n\n" +
1677fd4e5da5Sopenharmony_ci          "%2 = OpUGreaterThanEqual %bool %uint_max %load\n" +
1678fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1679fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1680fd4e5da5Sopenharmony_ci      2, true),
1681fd4e5da5Sopenharmony_ci  // Test case 18: fold n >= INT_MIN (signed)
1682fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1683fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1684fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1685fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
1686fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
1687fd4e5da5Sopenharmony_ci          "%2 = OpSGreaterThanEqual %bool %load %int_min\n" +
1688fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1689fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1690fd4e5da5Sopenharmony_ci      2, true),
1691fd4e5da5Sopenharmony_ci  // Test case 19: fold INT_MAX >= n (signed)
1692fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
1693fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1694fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
1695fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
1696fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
1697fd4e5da5Sopenharmony_ci          "%2 = OpSGreaterThanEqual %bool %int_max %load\n" +
1698fd4e5da5Sopenharmony_ci          "OpReturn\n" +
1699fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
1700fd4e5da5Sopenharmony_ci      2, true)
1701fd4e5da5Sopenharmony_ci));
1702fd4e5da5Sopenharmony_ci
1703fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FClampAndCmpLHS, BooleanInstructionFoldingTest,
1704fd4e5da5Sopenharmony_ci::testing::Values(
1705fd4e5da5Sopenharmony_ci    // Test case 0: fold 0.0 > clamp(n, 0.0, 1.0)
1706fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1707fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1708fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1709fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1710fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1711fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_0 %float_1\n" +
1712fd4e5da5Sopenharmony_ci            "%2 = OpFOrdGreaterThan %bool %float_0 %clamp\n" +
1713fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1714fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1715fd4e5da5Sopenharmony_ci        2, false),
1716fd4e5da5Sopenharmony_ci    // Test case 1: fold 0.0 > clamp(n, -1.0, -1.0)
1717fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1718fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1719fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1720fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1721fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1722fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_n1\n" +
1723fd4e5da5Sopenharmony_ci            "%2 = OpFOrdGreaterThan %bool %float_0 %clamp\n" +
1724fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1725fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1726fd4e5da5Sopenharmony_ci        2, true),
1727fd4e5da5Sopenharmony_ci    // Test case 2: fold 0.0 >= clamp(n, 1, 2)
1728fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1729fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1730fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1731fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1732fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1733fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_2\n" +
1734fd4e5da5Sopenharmony_ci            "%2 = OpFOrdGreaterThanEqual %bool %float_0 %clamp\n" +
1735fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1736fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1737fd4e5da5Sopenharmony_ci        2, false),
1738fd4e5da5Sopenharmony_ci    // Test case 3: fold 0.0 >= clamp(n, -1.0, 0.0)
1739fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1740fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1741fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1742fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1743fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1744fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
1745fd4e5da5Sopenharmony_ci            "%2 = OpFOrdGreaterThanEqual %bool %float_0 %clamp\n" +
1746fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1747fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1748fd4e5da5Sopenharmony_ci        2, true),
1749fd4e5da5Sopenharmony_ci    // Test case 4: fold 0.0 <= clamp(n, 0.0, 1.0)
1750fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1751fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1752fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1753fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1754fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1755fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_0 %float_1\n" +
1756fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThanEqual %bool %float_0 %clamp\n" +
1757fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1758fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1759fd4e5da5Sopenharmony_ci        2, true),
1760fd4e5da5Sopenharmony_ci    // Test case 5: fold 0.0 <= clamp(n, -1.0, -1.0)
1761fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1762fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1763fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1764fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1765fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1766fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_n1\n" +
1767fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThanEqual %bool %float_0 %clamp\n" +
1768fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1769fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1770fd4e5da5Sopenharmony_ci        2, false),
1771fd4e5da5Sopenharmony_ci    // Test case 6: fold 0.0 < clamp(n, 1, 2)
1772fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1773fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1774fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1775fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1776fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1777fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_2\n" +
1778fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThan %bool %float_0 %clamp\n" +
1779fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1780fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1781fd4e5da5Sopenharmony_ci        2, true),
1782fd4e5da5Sopenharmony_ci    // Test case 7: fold 0.0 < clamp(n, -1.0, 0.0)
1783fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1784fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1785fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1786fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1787fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1788fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
1789fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThan %bool %float_0 %clamp\n" +
1790fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1791fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1792fd4e5da5Sopenharmony_ci        2, false),
1793fd4e5da5Sopenharmony_ci    // Test case 8: fold 0.0 > clamp(n, 0.0, 1.0)
1794fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1795fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1796fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1797fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1798fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1799fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_0 %float_1\n" +
1800fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThan %bool %float_0 %clamp\n" +
1801fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1802fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1803fd4e5da5Sopenharmony_ci        2, false),
1804fd4e5da5Sopenharmony_ci    // Test case 9: fold 0.0 > clamp(n, -1.0, -1.0)
1805fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1806fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1807fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1808fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1809fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1810fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_n1\n" +
1811fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThan %bool %float_0 %clamp\n" +
1812fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1813fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1814fd4e5da5Sopenharmony_ci        2, true),
1815fd4e5da5Sopenharmony_ci    // Test case 10: fold 0.0 >= clamp(n, 1, 2)
1816fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1817fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1818fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1819fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1820fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1821fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_2\n" +
1822fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThanEqual %bool %float_0 %clamp\n" +
1823fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1824fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1825fd4e5da5Sopenharmony_ci        2, false),
1826fd4e5da5Sopenharmony_ci    // Test case 11: fold 0.0 >= clamp(n, -1.0, 0.0)
1827fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1828fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1829fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1830fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1831fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1832fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
1833fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThanEqual %bool %float_0 %clamp\n" +
1834fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1835fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1836fd4e5da5Sopenharmony_ci        2, true),
1837fd4e5da5Sopenharmony_ci    // Test case 12: fold 0.0 <= clamp(n, 0.0, 1.0)
1838fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1839fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1840fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1841fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1842fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1843fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_0 %float_1\n" +
1844fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThanEqual %bool %float_0 %clamp\n" +
1845fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1846fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1847fd4e5da5Sopenharmony_ci        2, true),
1848fd4e5da5Sopenharmony_ci    // Test case 13: fold 0.0 <= clamp(n, -1.0, -1.0)
1849fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1850fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1851fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1852fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1853fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1854fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_n1\n" +
1855fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThanEqual %bool %float_0 %clamp\n" +
1856fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1857fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1858fd4e5da5Sopenharmony_ci        2, false),
1859fd4e5da5Sopenharmony_ci    // Test case 14: fold 0.0 < clamp(n, 1, 2)
1860fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1861fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1862fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1863fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1864fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1865fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_2\n" +
1866fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThan %bool %float_0 %clamp\n" +
1867fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1868fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1869fd4e5da5Sopenharmony_ci        2, true),
1870fd4e5da5Sopenharmony_ci    // Test case 15: fold 0.0 < clamp(n, -1.0, 0.0)
1871fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1872fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1873fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1874fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1875fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1876fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
1877fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThan %bool %float_0 %clamp\n" +
1878fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1879fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1880fd4e5da5Sopenharmony_ci        2, false)
1881fd4e5da5Sopenharmony_ci));
1882fd4e5da5Sopenharmony_ci
1883fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FClampAndCmpRHS, BooleanInstructionFoldingTest,
1884fd4e5da5Sopenharmony_ci::testing::Values(
1885fd4e5da5Sopenharmony_ci    // Test case 0: fold clamp(n, 0.0, 1.0) > 1.0
1886fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1887fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1888fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
1889fd4e5da5Sopenharmony_ci      "%n = OpVariable %_ptr_float Function\n" +
1890fd4e5da5Sopenharmony_ci      "%ld = OpLoad %float %n\n" +
1891fd4e5da5Sopenharmony_ci      "%clamp = OpExtInst %float %1 FClamp %ld %float_0 %float_1\n" +
1892fd4e5da5Sopenharmony_ci      "%2 = OpFOrdGreaterThan %bool %clamp %float_1\n" +
1893fd4e5da5Sopenharmony_ci      "OpReturn\n" +
1894fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
1895fd4e5da5Sopenharmony_ci      2, false),
1896fd4e5da5Sopenharmony_ci    // Test case 1: fold clamp(n, 1.0, 1.0) > 0.0
1897fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1898fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1899fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
1900fd4e5da5Sopenharmony_ci      "%n = OpVariable %_ptr_float Function\n" +
1901fd4e5da5Sopenharmony_ci      "%ld = OpLoad %float %n\n" +
1902fd4e5da5Sopenharmony_ci      "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_1\n" +
1903fd4e5da5Sopenharmony_ci      "%2 = OpFOrdGreaterThan %bool %clamp %float_0\n" +
1904fd4e5da5Sopenharmony_ci      "OpReturn\n" +
1905fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
1906fd4e5da5Sopenharmony_ci      2, true),
1907fd4e5da5Sopenharmony_ci    // Test case 2: fold clamp(n, 1, 2) >= 0.0
1908fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1909fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1910fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
1911fd4e5da5Sopenharmony_ci      "%n = OpVariable %_ptr_float Function\n" +
1912fd4e5da5Sopenharmony_ci      "%ld = OpLoad %float %n\n" +
1913fd4e5da5Sopenharmony_ci      "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_2\n" +
1914fd4e5da5Sopenharmony_ci      "%2 = OpFOrdGreaterThanEqual %bool %clamp %float_0\n" +
1915fd4e5da5Sopenharmony_ci      "OpReturn\n" +
1916fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
1917fd4e5da5Sopenharmony_ci      2, true),
1918fd4e5da5Sopenharmony_ci    // Test case 3: fold clamp(n, 1.0, 2.0) >= 3.0
1919fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1920fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
1921fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
1922fd4e5da5Sopenharmony_ci      "%n = OpVariable %_ptr_float Function\n" +
1923fd4e5da5Sopenharmony_ci      "%ld = OpLoad %float %n\n" +
1924fd4e5da5Sopenharmony_ci      "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_2\n" +
1925fd4e5da5Sopenharmony_ci      "%2 = OpFOrdGreaterThanEqual %bool %clamp %float_3\n" +
1926fd4e5da5Sopenharmony_ci      "OpReturn\n" +
1927fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
1928fd4e5da5Sopenharmony_ci      2, false),
1929fd4e5da5Sopenharmony_ci    // Test case 4: fold clamp(n, 0.0, 1.0) <= 1.0
1930fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1931fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1932fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1933fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1934fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1935fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_0 %float_1\n" +
1936fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThanEqual %bool %clamp %float_1\n" +
1937fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1938fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1939fd4e5da5Sopenharmony_ci        2, true),
1940fd4e5da5Sopenharmony_ci    // Test case 5: fold clamp(n, 1.0, 2.0) <= 0.0
1941fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1942fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1943fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1944fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1945fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1946fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_2\n" +
1947fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThanEqual %bool %clamp %float_0\n" +
1948fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1949fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1950fd4e5da5Sopenharmony_ci        2, false),
1951fd4e5da5Sopenharmony_ci    // Test case 6: fold clamp(n, 1, 2) < 3
1952fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1953fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1954fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1955fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1956fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1957fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_2\n" +
1958fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThan %bool %clamp %float_3\n" +
1959fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1960fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1961fd4e5da5Sopenharmony_ci        2, true),
1962fd4e5da5Sopenharmony_ci    // Test case 7: fold clamp(n, -1.0, 0.0) < -1.0
1963fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1964fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1965fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1966fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1967fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1968fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
1969fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThan %bool %clamp %float_n1\n" +
1970fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1971fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1972fd4e5da5Sopenharmony_ci        2, false),
1973fd4e5da5Sopenharmony_ci    // Test case 8: fold clamp(n, 0.0, 1.0) > 1.0
1974fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1975fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1976fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1977fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1978fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1979fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_0 %float_1\n" +
1980fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThan %bool %clamp %float_1\n" +
1981fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1982fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1983fd4e5da5Sopenharmony_ci        2, false),
1984fd4e5da5Sopenharmony_ci    // Test case 9: fold clamp(n, 1.0, 2.0) > 0.0
1985fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1986fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1987fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1988fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
1989fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
1990fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_2\n" +
1991fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThan %bool %clamp %float_0\n" +
1992fd4e5da5Sopenharmony_ci            "OpReturn\n" +
1993fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
1994fd4e5da5Sopenharmony_ci        2, true),
1995fd4e5da5Sopenharmony_ci    // Test case 10: fold clamp(n, 1, 2) >= 3.0
1996fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
1997fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
1998fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
1999fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
2000fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
2001fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_2\n" +
2002fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThanEqual %bool %clamp %float_3\n" +
2003fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2004fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2005fd4e5da5Sopenharmony_ci        2, false),
2006fd4e5da5Sopenharmony_ci    // Test case 11: fold clamp(n, -1.0, 0.0) >= -1.0
2007fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
2008fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2009fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2010fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
2011fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
2012fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
2013fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThanEqual %bool %clamp %float_n1\n" +
2014fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2015fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2016fd4e5da5Sopenharmony_ci        2, true),
2017fd4e5da5Sopenharmony_ci    // Test case 12: fold clamp(n, 0.0, 1.0) <= 1.0
2018fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
2019fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2020fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2021fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
2022fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
2023fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_0 %float_1\n" +
2024fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThanEqual %bool %clamp %float_1\n" +
2025fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2026fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2027fd4e5da5Sopenharmony_ci        2, true),
2028fd4e5da5Sopenharmony_ci    // Test case 13: fold clamp(n, 1.0, 1.0) <= 0.0
2029fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
2030fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2031fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2032fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
2033fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
2034fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_1\n" +
2035fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThanEqual %bool %clamp %float_0\n" +
2036fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2037fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2038fd4e5da5Sopenharmony_ci        2, false),
2039fd4e5da5Sopenharmony_ci    // Test case 14: fold clamp(n, 1, 2) < 3
2040fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
2041fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2042fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2043fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
2044fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
2045fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_1 %float_2\n" +
2046fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThan %bool %clamp %float_3\n" +
2047fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2048fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2049fd4e5da5Sopenharmony_ci        2, true),
2050fd4e5da5Sopenharmony_ci    // Test case 15: fold clamp(n, -1.0, 0.0) < -1.0
2051fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
2052fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2053fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2054fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
2055fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
2056fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
2057fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThan %bool %clamp %float_n1\n" +
2058fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2059fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2060fd4e5da5Sopenharmony_ci        2, false),
2061fd4e5da5Sopenharmony_ci    // Test case 16: fold clamp(n, -1.0, 0.0) < -1.0 (one test for double)
2062fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
2063fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2064fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2065fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
2066fd4e5da5Sopenharmony_ci            "%ld = OpLoad %double %n\n" +
2067fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %double %1 FClamp %ld %double_n1 %double_0\n" +
2068fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThan %bool %clamp %double_n1\n" +
2069fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2070fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2071fd4e5da5Sopenharmony_ci        2, false)
2072fd4e5da5Sopenharmony_ci));
2073fd4e5da5Sopenharmony_ci// clang-format on
2074fd4e5da5Sopenharmony_ci
2075fd4e5da5Sopenharmony_ciusing FloatInstructionFoldingTest =
2076fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCase<float>>;
2077fd4e5da5Sopenharmony_ci
2078fd4e5da5Sopenharmony_ciTEST_P(FloatInstructionFoldingTest, Case) {
2079fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
2080fd4e5da5Sopenharmony_ci
2081fd4e5da5Sopenharmony_ci  // Build module.
2082fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
2083fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
2084fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2085fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
2086fd4e5da5Sopenharmony_ci
2087fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
2088fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
2089fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
2090fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
2091fd4e5da5Sopenharmony_ci
2092fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
2093fd4e5da5Sopenharmony_ci  EXPECT_TRUE(succeeded);
2094fd4e5da5Sopenharmony_ci  if (inst != nullptr) {
2095fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpCopyObject);
2096fd4e5da5Sopenharmony_ci    inst = def_use_mgr->GetDef(inst->GetSingleWordInOperand(0));
2097fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpConstant);
2098fd4e5da5Sopenharmony_ci    analysis::ConstantManager* const_mrg = context->get_constant_mgr();
2099fd4e5da5Sopenharmony_ci    const analysis::FloatConstant* result =
2100fd4e5da5Sopenharmony_ci        const_mrg->GetConstantFromInst(inst)->AsFloatConstant();
2101fd4e5da5Sopenharmony_ci    EXPECT_NE(result, nullptr);
2102fd4e5da5Sopenharmony_ci    if (result != nullptr) {
2103fd4e5da5Sopenharmony_ci      if (!std::isnan(tc.expected_result)) {
2104fd4e5da5Sopenharmony_ci        EXPECT_EQ(result->GetFloatValue(), tc.expected_result);
2105fd4e5da5Sopenharmony_ci      } else {
2106fd4e5da5Sopenharmony_ci        EXPECT_TRUE(std::isnan(result->GetFloatValue()));
2107fd4e5da5Sopenharmony_ci      }
2108fd4e5da5Sopenharmony_ci    }
2109fd4e5da5Sopenharmony_ci  }
2110fd4e5da5Sopenharmony_ci}
2111fd4e5da5Sopenharmony_ci
2112fd4e5da5Sopenharmony_ci// Not testing NaNs because there are no expectations concerning NaNs according
2113fd4e5da5Sopenharmony_ci// to the "Precision and Operation of SPIR-V Instructions" section of the Vulkan
2114fd4e5da5Sopenharmony_ci// specification.
2115fd4e5da5Sopenharmony_ci
2116fd4e5da5Sopenharmony_ci// clang-format off
2117fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FloatConstantFoldingTest, FloatInstructionFoldingTest,
2118fd4e5da5Sopenharmony_ci::testing::Values(
2119fd4e5da5Sopenharmony_ci    // Test case 0: Fold 2.0 - 1.0
2120fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2121fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2122fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2123fd4e5da5Sopenharmony_ci            "%2 = OpFSub %float %float_2 %float_1\n" +
2124fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2125fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2126fd4e5da5Sopenharmony_ci        2, 1.0),
2127fd4e5da5Sopenharmony_ci    // Test case 1: Fold 2.0 + 1.0
2128fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2129fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2130fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2131fd4e5da5Sopenharmony_ci            "%2 = OpFAdd %float %float_2 %float_1\n" +
2132fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2133fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2134fd4e5da5Sopenharmony_ci        2, 3.0),
2135fd4e5da5Sopenharmony_ci    // Test case 2: Fold 3.0 * 2.0
2136fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2137fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2138fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2139fd4e5da5Sopenharmony_ci            "%2 = OpFMul %float %float_3 %float_2\n" +
2140fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2141fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2142fd4e5da5Sopenharmony_ci        2, 6.0),
2143fd4e5da5Sopenharmony_ci    // Test case 3: Fold 1.0 / 2.0
2144fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2145fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2146fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2147fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %float %float_1 %float_2\n" +
2148fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2149fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2150fd4e5da5Sopenharmony_ci        2, 0.5),
2151fd4e5da5Sopenharmony_ci    // Test case 4: Fold 1.0 / 0.0
2152fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2153fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2154fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2155fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %float %float_1 %float_0\n" +
2156fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2157fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2158fd4e5da5Sopenharmony_ci        2, std::numeric_limits<float>::infinity()),
2159fd4e5da5Sopenharmony_ci    // Test case 5: Fold -1.0 / 0.0
2160fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2161fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2162fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2163fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %float %float_n1 %float_0\n" +
2164fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2165fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2166fd4e5da5Sopenharmony_ci        2, -std::numeric_limits<float>::infinity()),
2167fd4e5da5Sopenharmony_ci    // Test case 6: Fold (2.0, 3.0) dot (2.0, 0.5)
2168fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2169fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2170fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2171fd4e5da5Sopenharmony_ci            "%2 = OpDot %float %v2float_2_3 %v2float_2_0p5\n" +
2172fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2173fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2174fd4e5da5Sopenharmony_ci        2, 5.5f),
2175fd4e5da5Sopenharmony_ci    // Test case 7: Fold (0.0, 0.0) dot v
2176fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2177fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2178fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2179fd4e5da5Sopenharmony_ci            "%v = OpVariable %_ptr_v2float Function\n" +
2180fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v2float %v\n" +
2181fd4e5da5Sopenharmony_ci            "%3 = OpDot %float %v2float_0_0 %2\n" +
2182fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2183fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2184fd4e5da5Sopenharmony_ci        3, 0.0f),
2185fd4e5da5Sopenharmony_ci    // Test case 8: Fold v dot (0.0, 0.0)
2186fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2187fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2188fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2189fd4e5da5Sopenharmony_ci            "%v = OpVariable %_ptr_v2float Function\n" +
2190fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v2float %v\n" +
2191fd4e5da5Sopenharmony_ci            "%3 = OpDot %float %2 %v2float_0_0\n" +
2192fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2193fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2194fd4e5da5Sopenharmony_ci        3, 0.0f),
2195fd4e5da5Sopenharmony_ci    // Test case 9: Fold Null dot v
2196fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2197fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2198fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2199fd4e5da5Sopenharmony_ci            "%v = OpVariable %_ptr_v2float Function\n" +
2200fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v2float %v\n" +
2201fd4e5da5Sopenharmony_ci            "%3 = OpDot %float %v2float_null %2\n" +
2202fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2203fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2204fd4e5da5Sopenharmony_ci        3, 0.0f),
2205fd4e5da5Sopenharmony_ci    // Test case 10: Fold v dot Null
2206fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2207fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2208fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2209fd4e5da5Sopenharmony_ci            "%v = OpVariable %_ptr_v2float Function\n" +
2210fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v2float %v\n" +
2211fd4e5da5Sopenharmony_ci            "%3 = OpDot %float %2 %v2float_null\n" +
2212fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2213fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2214fd4e5da5Sopenharmony_ci        3, 0.0f),
2215fd4e5da5Sopenharmony_ci    // Test case 11: Fold -2.0
2216fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2217fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2218fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2219fd4e5da5Sopenharmony_ci            "%2 = OpFNegate %float %float_2\n" +
2220fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2221fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2222fd4e5da5Sopenharmony_ci        2, -2),
2223fd4e5da5Sopenharmony_ci    // Test case 12: QuantizeToF16 1.0
2224fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2225fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2226fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2227fd4e5da5Sopenharmony_ci            "%2 = OpQuantizeToF16 %float %float_1\n" +
2228fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2229fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2230fd4e5da5Sopenharmony_ci        2, 1.0),
2231fd4e5da5Sopenharmony_ci    // Test case 13: QuantizeToF16 positive non exact
2232fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2233fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2234fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2235fd4e5da5Sopenharmony_ci            "%2 = OpQuantizeToF16 %float %float_2049\n" +
2236fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2237fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2238fd4e5da5Sopenharmony_ci        2, 2048),
2239fd4e5da5Sopenharmony_ci    // Test case 14: QuantizeToF16 negative non exact
2240fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2241fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2242fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2243fd4e5da5Sopenharmony_ci            "%2 = OpQuantizeToF16 %float %float_n2049\n" +
2244fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2245fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2246fd4e5da5Sopenharmony_ci        2, -2048),
2247fd4e5da5Sopenharmony_ci    // Test case 15: QuantizeToF16 large positive
2248fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2249fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2250fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2251fd4e5da5Sopenharmony_ci            "%2 = OpQuantizeToF16 %float %float_1e16\n" +
2252fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2253fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2254fd4e5da5Sopenharmony_ci        2, std::numeric_limits<float>::infinity()),
2255fd4e5da5Sopenharmony_ci    // Test case 16: QuantizeToF16 large negative
2256fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2257fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2258fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2259fd4e5da5Sopenharmony_ci            "%2 = OpQuantizeToF16 %float %float_n1e16\n" +
2260fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2261fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2262fd4e5da5Sopenharmony_ci        2, -std::numeric_limits<float>::infinity()),
2263fd4e5da5Sopenharmony_ci    // Test case 17: QuantizeToF16 small positive
2264fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2265fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2266fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2267fd4e5da5Sopenharmony_ci            "%2 = OpQuantizeToF16 %float %float_1en16\n" +
2268fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2269fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2270fd4e5da5Sopenharmony_ci        2, 0.0),
2271fd4e5da5Sopenharmony_ci    // Test case 18: QuantizeToF16 small negative
2272fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2273fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2274fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2275fd4e5da5Sopenharmony_ci            "%2 = OpQuantizeToF16 %float %float_n1en16\n" +
2276fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2277fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2278fd4e5da5Sopenharmony_ci        2, 0.0),
2279fd4e5da5Sopenharmony_ci    // Test case 19: QuantizeToF16 nan
2280fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2281fd4e5da5Sopenharmony_ci        HeaderWithNaN() + "%main = OpFunction %void None %void_func\n" +
2282fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2283fd4e5da5Sopenharmony_ci            "%2 = OpQuantizeToF16 %float %float_nan\n" +
2284fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2285fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2286fd4e5da5Sopenharmony_ci        2, std::numeric_limits<float>::quiet_NaN()),
2287fd4e5da5Sopenharmony_ci    // Test case 20: FMix 1.0 4.0 0.2
2288fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2289fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2290fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2291fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FMix %float_1 %float_4 %float_0p2\n" +
2292fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2293fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2294fd4e5da5Sopenharmony_ci        2, 1.6f),
2295fd4e5da5Sopenharmony_ci    // Test case 21: FMin 1.0 4.0
2296fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2297fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2298fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2299fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FMin %float_1 %float_4\n" +
2300fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2301fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2302fd4e5da5Sopenharmony_ci        2, 1.0f),
2303fd4e5da5Sopenharmony_ci    // Test case 22: FMin 4.0 0.2
2304fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2305fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2306fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2307fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FMin %float_4 %float_0p2\n" +
2308fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2309fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2310fd4e5da5Sopenharmony_ci        2, 0.2f),
2311fd4e5da5Sopenharmony_ci    // Test case 23: FMax 1.0 4.0
2312fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2313fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2314fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2315fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FMax %float_1 %float_4\n" +
2316fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2317fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2318fd4e5da5Sopenharmony_ci        2, 4.0f),
2319fd4e5da5Sopenharmony_ci    // Test case 24: FMax 1.0 0.2
2320fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2321fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2322fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2323fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FMax %float_1 %float_0p2\n" +
2324fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2325fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2326fd4e5da5Sopenharmony_ci        2, 1.0f),
2327fd4e5da5Sopenharmony_ci    // Test case 25: FClamp 1.0 0.2 4.0
2328fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2329fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2330fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2331fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FClamp %float_1 %float_0p2 %float_4\n" +
2332fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2333fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2334fd4e5da5Sopenharmony_ci        2, 1.0f),
2335fd4e5da5Sopenharmony_ci    // Test case 26: FClamp 0.2 2.0 4.0
2336fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2337fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2338fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2339fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FClamp %float_0p2 %float_2 %float_4\n" +
2340fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2341fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2342fd4e5da5Sopenharmony_ci        2, 2.0f),
2343fd4e5da5Sopenharmony_ci    // Test case 27: FClamp 2049.0 2.0 4.0
2344fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2345fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2346fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2347fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FClamp %float_2049 %float_2 %float_4\n" +
2348fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2349fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2350fd4e5da5Sopenharmony_ci        2, 4.0f),
2351fd4e5da5Sopenharmony_ci    // Test case 28: FClamp 1.0 2.0 x
2352fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2353fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2354fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2355fd4e5da5Sopenharmony_ci            "%undef = OpUndef %float\n" +
2356fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FClamp %float_1 %float_2 %undef\n" +
2357fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2358fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2359fd4e5da5Sopenharmony_ci        2, 2.0),
2360fd4e5da5Sopenharmony_ci    // Test case 29: FClamp 1.0 x 0.5
2361fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2362fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2363fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2364fd4e5da5Sopenharmony_ci            "%undef = OpUndef %float\n" +
2365fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FClamp %float_1 %undef %float_0p5\n" +
2366fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2367fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2368fd4e5da5Sopenharmony_ci        2, 0.5),
2369fd4e5da5Sopenharmony_ci    // Test case 30: Sin 0.0
2370fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2371fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2372fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2373fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Sin %float_0\n" +
2374fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2375fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2376fd4e5da5Sopenharmony_ci        2, 0.0),
2377fd4e5da5Sopenharmony_ci    // Test case 31: Cos 0.0
2378fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2379fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2380fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2381fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Cos %float_0\n" +
2382fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2383fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2384fd4e5da5Sopenharmony_ci        2, 1.0),
2385fd4e5da5Sopenharmony_ci    // Test case 32: Tan 0.0
2386fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2387fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2388fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2389fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Tan %float_0\n" +
2390fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2391fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2392fd4e5da5Sopenharmony_ci        2, 0.0),
2393fd4e5da5Sopenharmony_ci    // Test case 33: Asin 0.0
2394fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2395fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2396fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2397fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Asin %float_0\n" +
2398fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2399fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2400fd4e5da5Sopenharmony_ci        2, 0.0),
2401fd4e5da5Sopenharmony_ci    // Test case 34: Acos 1.0
2402fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2403fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2404fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2405fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Acos %float_1\n" +
2406fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2407fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2408fd4e5da5Sopenharmony_ci        2, 0.0),
2409fd4e5da5Sopenharmony_ci    // Test case 35: Atan 0.0
2410fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2411fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2412fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2413fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Atan %float_0\n" +
2414fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2415fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2416fd4e5da5Sopenharmony_ci        2, 0.0),
2417fd4e5da5Sopenharmony_ci    // Test case 36: Exp 0.0
2418fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2419fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2420fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2421fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Exp %float_0\n" +
2422fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2423fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2424fd4e5da5Sopenharmony_ci        2, 1.0),
2425fd4e5da5Sopenharmony_ci    // Test case 37: Log 1.0
2426fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2427fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2428fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2429fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Log %float_1\n" +
2430fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2431fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2432fd4e5da5Sopenharmony_ci        2, 0.0),
2433fd4e5da5Sopenharmony_ci    // Test case 38: Exp2 2.0
2434fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2435fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2436fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2437fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Exp2 %float_2\n" +
2438fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2439fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2440fd4e5da5Sopenharmony_ci        2, 4.0),
2441fd4e5da5Sopenharmony_ci    // Test case 39: Log2 4.0
2442fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2443fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2444fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2445fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Log2 %float_4\n" +
2446fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2447fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2448fd4e5da5Sopenharmony_ci        2, 2.0),
2449fd4e5da5Sopenharmony_ci    // Test case 40: Sqrt 4.0
2450fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2451fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2452fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2453fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Sqrt %float_4\n" +
2454fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2455fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2456fd4e5da5Sopenharmony_ci        2, 2.0),
2457fd4e5da5Sopenharmony_ci    // Test case 41: Atan2 0.0 1.0
2458fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2459fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2460fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2461fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Atan2 %float_0 %float_1\n" +
2462fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2463fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2464fd4e5da5Sopenharmony_ci        2, 0.0),
2465fd4e5da5Sopenharmony_ci    // Test case 42: Pow 2.0 3.0
2466fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2467fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2468fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2469fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 Pow %float_2 %float_3\n" +
2470fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2471fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2472fd4e5da5Sopenharmony_ci        2, 8.0),
2473fd4e5da5Sopenharmony_ci    // Test case 43: Fold 1.0 / -0.0.
2474fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2475fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2476fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2477fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %float %float_1 %float_n0\n" +
2478fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2479fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2480fd4e5da5Sopenharmony_ci        2, -std::numeric_limits<float>::infinity()),
2481fd4e5da5Sopenharmony_ci    // Test case 44: Fold -1.0 / -0.0
2482fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2483fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2484fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2485fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %float %float_n1 %float_n0\n" +
2486fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2487fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2488fd4e5da5Sopenharmony_ci        2, std::numeric_limits<float>::infinity()),
2489fd4e5da5Sopenharmony_ci    // Test case 45: Fold 0.0 / 0.0
2490fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2491fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2492fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2493fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %float %float_0 %float_0\n" +
2494fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2495fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2496fd4e5da5Sopenharmony_ci        2, std::numeric_limits<float>::quiet_NaN()),
2497fd4e5da5Sopenharmony_ci    // Test case 46: Fold 0.0 / -0.0
2498fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
2499fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2500fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2501fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %float %float_0 %float_n0\n" +
2502fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2503fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2504fd4e5da5Sopenharmony_ci        2, std::numeric_limits<float>::quiet_NaN())
2505fd4e5da5Sopenharmony_ci));
2506fd4e5da5Sopenharmony_ci// clang-format on
2507fd4e5da5Sopenharmony_ci
2508fd4e5da5Sopenharmony_ciusing DoubleInstructionFoldingTest =
2509fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCase<double>>;
2510fd4e5da5Sopenharmony_ci
2511fd4e5da5Sopenharmony_ciTEST_P(DoubleInstructionFoldingTest, Case) {
2512fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
2513fd4e5da5Sopenharmony_ci
2514fd4e5da5Sopenharmony_ci  // Build module.
2515fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
2516fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
2517fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
2518fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
2519fd4e5da5Sopenharmony_ci
2520fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
2521fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
2522fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
2523fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
2524fd4e5da5Sopenharmony_ci
2525fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
2526fd4e5da5Sopenharmony_ci  EXPECT_TRUE(succeeded);
2527fd4e5da5Sopenharmony_ci  if (inst != nullptr) {
2528fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpCopyObject);
2529fd4e5da5Sopenharmony_ci    inst = def_use_mgr->GetDef(inst->GetSingleWordInOperand(0));
2530fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpConstant);
2531fd4e5da5Sopenharmony_ci    analysis::ConstantManager* const_mrg = context->get_constant_mgr();
2532fd4e5da5Sopenharmony_ci    const analysis::FloatConstant* result =
2533fd4e5da5Sopenharmony_ci        const_mrg->GetConstantFromInst(inst)->AsFloatConstant();
2534fd4e5da5Sopenharmony_ci    EXPECT_NE(result, nullptr);
2535fd4e5da5Sopenharmony_ci    if (result != nullptr) {
2536fd4e5da5Sopenharmony_ci      if (!std::isnan(tc.expected_result)) {
2537fd4e5da5Sopenharmony_ci        EXPECT_EQ(result->GetDoubleValue(), tc.expected_result);
2538fd4e5da5Sopenharmony_ci      } else {
2539fd4e5da5Sopenharmony_ci        EXPECT_TRUE(std::isnan(result->GetDoubleValue()));
2540fd4e5da5Sopenharmony_ci      }
2541fd4e5da5Sopenharmony_ci    }
2542fd4e5da5Sopenharmony_ci  }
2543fd4e5da5Sopenharmony_ci}
2544fd4e5da5Sopenharmony_ci
2545fd4e5da5Sopenharmony_ci// clang-format off
2546fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(DoubleConstantFoldingTest, DoubleInstructionFoldingTest,
2547fd4e5da5Sopenharmony_ci::testing::Values(
2548fd4e5da5Sopenharmony_ci    // Test case 0: Fold 2.0 - 1.0
2549fd4e5da5Sopenharmony_ci    InstructionFoldingCase<double>(
2550fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
2551fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
2552fd4e5da5Sopenharmony_ci            "%2 = OpFSub %double %double_2 %double_1\n" +
2553fd4e5da5Sopenharmony_ci            "OpReturn\n" +
2554fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
2555fd4e5da5Sopenharmony_ci        2, 1.0),
2556fd4e5da5Sopenharmony_ci        // Test case 1: Fold 2.0 + 1.0
2557fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2558fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2559fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2560fd4e5da5Sopenharmony_ci                "%2 = OpFAdd %double %double_2 %double_1\n" +
2561fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2562fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2563fd4e5da5Sopenharmony_ci            2, 3.0),
2564fd4e5da5Sopenharmony_ci        // Test case 2: Fold 3.0 * 2.0
2565fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2566fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2567fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2568fd4e5da5Sopenharmony_ci                "%2 = OpFMul %double %double_3 %double_2\n" +
2569fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2570fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2571fd4e5da5Sopenharmony_ci            2, 6.0),
2572fd4e5da5Sopenharmony_ci        // Test case 3: Fold 1.0 / 2.0
2573fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2574fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2575fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2576fd4e5da5Sopenharmony_ci                "%2 = OpFDiv %double %double_1 %double_2\n" +
2577fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2578fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2579fd4e5da5Sopenharmony_ci            2, 0.5),
2580fd4e5da5Sopenharmony_ci        // Test case 4: Fold 1.0 / 0.0
2581fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2582fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2583fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2584fd4e5da5Sopenharmony_ci                "%2 = OpFDiv %double %double_1 %double_0\n" +
2585fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2586fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2587fd4e5da5Sopenharmony_ci            2, std::numeric_limits<double>::infinity()),
2588fd4e5da5Sopenharmony_ci        // Test case 5: Fold -1.0 / 0.0
2589fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2590fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2591fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2592fd4e5da5Sopenharmony_ci                "%2 = OpFDiv %double %double_n1 %double_0\n" +
2593fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2594fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2595fd4e5da5Sopenharmony_ci            2, -std::numeric_limits<double>::infinity()),
2596fd4e5da5Sopenharmony_ci        // Test case 6: Fold (2.0, 3.0) dot (2.0, 0.5)
2597fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2598fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2599fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2600fd4e5da5Sopenharmony_ci                "%2 = OpDot %double %v2double_2_3 %v2double_2_0p5\n" +
2601fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2602fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2603fd4e5da5Sopenharmony_ci            2, 5.5f),
2604fd4e5da5Sopenharmony_ci        // Test case 7: Fold (0.0, 0.0) dot v
2605fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2606fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2607fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2608fd4e5da5Sopenharmony_ci                "%v = OpVariable %_ptr_v2double Function\n" +
2609fd4e5da5Sopenharmony_ci                "%2 = OpLoad %v2double %v\n" +
2610fd4e5da5Sopenharmony_ci                "%3 = OpDot %double %v2double_0_0 %2\n" +
2611fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2612fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2613fd4e5da5Sopenharmony_ci            3, 0.0f),
2614fd4e5da5Sopenharmony_ci        // Test case 8: Fold v dot (0.0, 0.0)
2615fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2616fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2617fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2618fd4e5da5Sopenharmony_ci                "%v = OpVariable %_ptr_v2double Function\n" +
2619fd4e5da5Sopenharmony_ci                "%2 = OpLoad %v2double %v\n" +
2620fd4e5da5Sopenharmony_ci                "%3 = OpDot %double %2 %v2double_0_0\n" +
2621fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2622fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2623fd4e5da5Sopenharmony_ci            3, 0.0f),
2624fd4e5da5Sopenharmony_ci        // Test case 9: Fold Null dot v
2625fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2626fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2627fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2628fd4e5da5Sopenharmony_ci                "%v = OpVariable %_ptr_v2double Function\n" +
2629fd4e5da5Sopenharmony_ci                "%2 = OpLoad %v2double %v\n" +
2630fd4e5da5Sopenharmony_ci                "%3 = OpDot %double %v2double_null %2\n" +
2631fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2632fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2633fd4e5da5Sopenharmony_ci            3, 0.0f),
2634fd4e5da5Sopenharmony_ci        // Test case 10: Fold v dot Null
2635fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2636fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2637fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2638fd4e5da5Sopenharmony_ci                "%v = OpVariable %_ptr_v2double Function\n" +
2639fd4e5da5Sopenharmony_ci                "%2 = OpLoad %v2double %v\n" +
2640fd4e5da5Sopenharmony_ci                "%3 = OpDot %double %2 %v2double_null\n" +
2641fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2642fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2643fd4e5da5Sopenharmony_ci            3, 0.0f),
2644fd4e5da5Sopenharmony_ci        // Test case 11: Fold -2.0
2645fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2646fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2647fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2648fd4e5da5Sopenharmony_ci                "%2 = OpFNegate %double %double_2\n" +
2649fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2650fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2651fd4e5da5Sopenharmony_ci            2, -2),
2652fd4e5da5Sopenharmony_ci        // Test case 12: FMin 1.0 4.0
2653fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2654fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2655fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2656fd4e5da5Sopenharmony_ci                "%2 = OpExtInst %double %1 FMin %double_1 %double_4\n" +
2657fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2658fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2659fd4e5da5Sopenharmony_ci            2, 1.0),
2660fd4e5da5Sopenharmony_ci        // Test case 13: FMin 4.0 0.2
2661fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2662fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2663fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2664fd4e5da5Sopenharmony_ci                "%2 = OpExtInst %double %1 FMin %double_4 %double_0p2\n" +
2665fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2666fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2667fd4e5da5Sopenharmony_ci            2, 0.2),
2668fd4e5da5Sopenharmony_ci        // Test case 14: FMax 1.0 4.0
2669fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2670fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2671fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2672fd4e5da5Sopenharmony_ci                "%2 = OpExtInst %double %1 FMax %double_1 %double_4\n" +
2673fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2674fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2675fd4e5da5Sopenharmony_ci            2, 4.0),
2676fd4e5da5Sopenharmony_ci        // Test case 15: FMax 1.0 0.2
2677fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2678fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2679fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2680fd4e5da5Sopenharmony_ci                "%2 = OpExtInst %double %1 FMax %double_1 %double_0p2\n" +
2681fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2682fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2683fd4e5da5Sopenharmony_ci            2, 1.0),
2684fd4e5da5Sopenharmony_ci        // Test case 16: FClamp 1.0 0.2 4.0
2685fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2686fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2687fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2688fd4e5da5Sopenharmony_ci                "%2 = OpExtInst %double %1 FClamp %double_1 %double_0p2 %double_4\n" +
2689fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2690fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2691fd4e5da5Sopenharmony_ci            2, 1.0),
2692fd4e5da5Sopenharmony_ci        // Test case 17: FClamp 0.2 2.0 4.0
2693fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2694fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2695fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2696fd4e5da5Sopenharmony_ci                "%2 = OpExtInst %double %1 FClamp %double_0p2 %double_2 %double_4\n" +
2697fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2698fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2699fd4e5da5Sopenharmony_ci            2, 2.0),
2700fd4e5da5Sopenharmony_ci        // Test case 18: FClamp 5.0 2.0 4.0
2701fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2702fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2703fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2704fd4e5da5Sopenharmony_ci                "%2 = OpExtInst %double %1 FClamp %double_5 %double_2 %double_4\n" +
2705fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2706fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2707fd4e5da5Sopenharmony_ci            2, 4.0),
2708fd4e5da5Sopenharmony_ci        // Test case 19: FClamp 1.0 2.0 x
2709fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2710fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2711fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2712fd4e5da5Sopenharmony_ci                "%undef = OpUndef %double\n" +
2713fd4e5da5Sopenharmony_ci                "%2 = OpExtInst %double %1 FClamp %double_1 %double_2 %undef\n" +
2714fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2715fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2716fd4e5da5Sopenharmony_ci            2, 2.0),
2717fd4e5da5Sopenharmony_ci        // Test case 20: FClamp 1.0 x 0.5
2718fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2719fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2720fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2721fd4e5da5Sopenharmony_ci                "%undef = OpUndef %double\n" +
2722fd4e5da5Sopenharmony_ci                "%2 = OpExtInst %double %1 FClamp %double_1 %undef %double_0p5\n" +
2723fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2724fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2725fd4e5da5Sopenharmony_ci            2, 0.5),
2726fd4e5da5Sopenharmony_ci        // Test case 21: Sqrt 4.0
2727fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2728fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2729fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2730fd4e5da5Sopenharmony_ci                "%undef = OpUndef %double\n" +
2731fd4e5da5Sopenharmony_ci                "%2 = OpExtInst %double %1 Sqrt %double_4\n" +
2732fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2733fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2734fd4e5da5Sopenharmony_ci            2, 2.0),
2735fd4e5da5Sopenharmony_ci        // Test case 22: Pow 2.0 3.0
2736fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2737fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2738fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2739fd4e5da5Sopenharmony_ci                "%undef = OpUndef %double\n" +
2740fd4e5da5Sopenharmony_ci                "%2 = OpExtInst %double %1 Pow %double_2 %double_3\n" +
2741fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2742fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2743fd4e5da5Sopenharmony_ci            2, 8.0),
2744fd4e5da5Sopenharmony_ci        // Test case 23: Fold 1.0 / -0.0.
2745fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2746fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2747fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2748fd4e5da5Sopenharmony_ci                "%2 = OpFDiv %double %double_1 %double_n0\n" +
2749fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2750fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2751fd4e5da5Sopenharmony_ci            2, -std::numeric_limits<double>::infinity()),
2752fd4e5da5Sopenharmony_ci        // Test case 24: Fold -1.0 / -0.0
2753fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2754fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2755fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2756fd4e5da5Sopenharmony_ci                "%2 = OpFDiv %double %double_n1 %double_n0\n" +
2757fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2758fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2759fd4e5da5Sopenharmony_ci            2, std::numeric_limits<double>::infinity()),
2760fd4e5da5Sopenharmony_ci        // Test case 25: Fold 0.0 / 0.0
2761fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2762fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2763fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2764fd4e5da5Sopenharmony_ci                "%2 = OpFDiv %double %double_0 %double_0\n" +
2765fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2766fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2767fd4e5da5Sopenharmony_ci            2, std::numeric_limits<double>::quiet_NaN()),
2768fd4e5da5Sopenharmony_ci        // Test case 26: Fold 0.0 / -0.0
2769fd4e5da5Sopenharmony_ci        InstructionFoldingCase<double>(
2770fd4e5da5Sopenharmony_ci            Header() + "%main = OpFunction %void None %void_func\n" +
2771fd4e5da5Sopenharmony_ci                "%main_lab = OpLabel\n" +
2772fd4e5da5Sopenharmony_ci                "%2 = OpFDiv %double %double_0 %double_n0\n" +
2773fd4e5da5Sopenharmony_ci                "OpReturn\n" +
2774fd4e5da5Sopenharmony_ci                "OpFunctionEnd",
2775fd4e5da5Sopenharmony_ci            2, std::numeric_limits<double>::quiet_NaN())
2776fd4e5da5Sopenharmony_ci));
2777fd4e5da5Sopenharmony_ci// clang-format on
2778fd4e5da5Sopenharmony_ci
2779fd4e5da5Sopenharmony_ci// clang-format off
2780fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(DoubleOrderedCompareConstantFoldingTest, BooleanInstructionFoldingTest,
2781fd4e5da5Sopenharmony_ci                        ::testing::Values(
2782fd4e5da5Sopenharmony_ci  // Test case 0: fold 1.0 == 2.0
2783fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2784fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2785fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2786fd4e5da5Sopenharmony_ci          "%2 = OpFOrdEqual %bool %double_1 %double_2\n" +
2787fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2788fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2789fd4e5da5Sopenharmony_ci      2, false),
2790fd4e5da5Sopenharmony_ci  // Test case 1: fold 1.0 != 2.0
2791fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2792fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2793fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2794fd4e5da5Sopenharmony_ci          "%2 = OpFOrdNotEqual %bool %double_1 %double_2\n" +
2795fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2796fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2797fd4e5da5Sopenharmony_ci      2, true),
2798fd4e5da5Sopenharmony_ci  // Test case 2: fold 1.0 < 2.0
2799fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2800fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2801fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2802fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThan %bool %double_1 %double_2\n" +
2803fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2804fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2805fd4e5da5Sopenharmony_ci      2, true),
2806fd4e5da5Sopenharmony_ci  // Test case 3: fold 1.0 > 2.0
2807fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2808fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2809fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2810fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThan %bool %double_1 %double_2\n" +
2811fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2812fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2813fd4e5da5Sopenharmony_ci      2, false),
2814fd4e5da5Sopenharmony_ci  // Test case 4: fold 1.0 <= 2.0
2815fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2816fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2817fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2818fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThanEqual %bool %double_1 %double_2\n" +
2819fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2820fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2821fd4e5da5Sopenharmony_ci      2, true),
2822fd4e5da5Sopenharmony_ci  // Test case 5: fold 1.0 >= 2.0
2823fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2824fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2825fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2826fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThanEqual %bool %double_1 %double_2\n" +
2827fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2828fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2829fd4e5da5Sopenharmony_ci      2, false),
2830fd4e5da5Sopenharmony_ci  // Test case 6: fold 1.0 == 1.0
2831fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2832fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2833fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2834fd4e5da5Sopenharmony_ci          "%2 = OpFOrdEqual %bool %double_1 %double_1\n" +
2835fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2836fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2837fd4e5da5Sopenharmony_ci      2, true),
2838fd4e5da5Sopenharmony_ci  // Test case 7: fold 1.0 != 1.0
2839fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2840fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2841fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2842fd4e5da5Sopenharmony_ci          "%2 = OpFOrdNotEqual %bool %double_1 %double_1\n" +
2843fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2844fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2845fd4e5da5Sopenharmony_ci      2, false),
2846fd4e5da5Sopenharmony_ci  // Test case 8: fold 1.0 < 1.0
2847fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2848fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2849fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2850fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThan %bool %double_1 %double_1\n" +
2851fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2852fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2853fd4e5da5Sopenharmony_ci      2, false),
2854fd4e5da5Sopenharmony_ci  // Test case 9: fold 1.0 > 1.0
2855fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2856fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2857fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2858fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThan %bool %double_1 %double_1\n" +
2859fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2860fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2861fd4e5da5Sopenharmony_ci      2, false),
2862fd4e5da5Sopenharmony_ci  // Test case 10: fold 1.0 <= 1.0
2863fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2864fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2865fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2866fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThanEqual %bool %double_1 %double_1\n" +
2867fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2868fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2869fd4e5da5Sopenharmony_ci      2, true),
2870fd4e5da5Sopenharmony_ci  // Test case 11: fold 1.0 >= 1.0
2871fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2872fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2873fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2874fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThanEqual %bool %double_1 %double_1\n" +
2875fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2876fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2877fd4e5da5Sopenharmony_ci      2, true),
2878fd4e5da5Sopenharmony_ci  // Test case 12: fold 2.0 < 1.0
2879fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2880fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2881fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2882fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThan %bool %double_2 %double_1\n" +
2883fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2884fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2885fd4e5da5Sopenharmony_ci      2, false),
2886fd4e5da5Sopenharmony_ci  // Test case 13: fold 2.0 > 1.0
2887fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2888fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2889fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2890fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThan %bool %double_2 %double_1\n" +
2891fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2892fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2893fd4e5da5Sopenharmony_ci      2, true),
2894fd4e5da5Sopenharmony_ci  // Test case 14: fold 2.0 <= 1.0
2895fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2896fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2897fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2898fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThanEqual %bool %double_2 %double_1\n" +
2899fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2900fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2901fd4e5da5Sopenharmony_ci      2, false),
2902fd4e5da5Sopenharmony_ci  // Test case 15: fold 2.0 >= 1.0
2903fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2904fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2905fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2906fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThanEqual %bool %double_2 %double_1\n" +
2907fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2908fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2909fd4e5da5Sopenharmony_ci      2, true)
2910fd4e5da5Sopenharmony_ci));
2911fd4e5da5Sopenharmony_ci
2912fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(DoubleUnorderedCompareConstantFoldingTest, BooleanInstructionFoldingTest,
2913fd4e5da5Sopenharmony_ci                        ::testing::Values(
2914fd4e5da5Sopenharmony_ci  // Test case 0: fold 1.0 == 2.0
2915fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2916fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2917fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2918fd4e5da5Sopenharmony_ci          "%2 = OpFUnordEqual %bool %double_1 %double_2\n" +
2919fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2920fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2921fd4e5da5Sopenharmony_ci      2, false),
2922fd4e5da5Sopenharmony_ci  // Test case 1: fold 1.0 != 2.0
2923fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2924fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2925fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2926fd4e5da5Sopenharmony_ci          "%2 = OpFUnordNotEqual %bool %double_1 %double_2\n" +
2927fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2928fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2929fd4e5da5Sopenharmony_ci      2, true),
2930fd4e5da5Sopenharmony_ci  // Test case 2: fold 1.0 < 2.0
2931fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2932fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2933fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2934fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThan %bool %double_1 %double_2\n" +
2935fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2936fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2937fd4e5da5Sopenharmony_ci      2, true),
2938fd4e5da5Sopenharmony_ci  // Test case 3: fold 1.0 > 2.0
2939fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2940fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2941fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2942fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThan %bool %double_1 %double_2\n" +
2943fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2944fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2945fd4e5da5Sopenharmony_ci      2, false),
2946fd4e5da5Sopenharmony_ci  // Test case 4: fold 1.0 <= 2.0
2947fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2948fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2949fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2950fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThanEqual %bool %double_1 %double_2\n" +
2951fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2952fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2953fd4e5da5Sopenharmony_ci      2, true),
2954fd4e5da5Sopenharmony_ci  // Test case 5: fold 1.0 >= 2.0
2955fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2956fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2957fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2958fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThanEqual %bool %double_1 %double_2\n" +
2959fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2960fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2961fd4e5da5Sopenharmony_ci      2, false),
2962fd4e5da5Sopenharmony_ci  // Test case 6: fold 1.0 == 1.0
2963fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2964fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2965fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2966fd4e5da5Sopenharmony_ci          "%2 = OpFUnordEqual %bool %double_1 %double_1\n" +
2967fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2968fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2969fd4e5da5Sopenharmony_ci      2, true),
2970fd4e5da5Sopenharmony_ci  // Test case 7: fold 1.0 != 1.0
2971fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2972fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2973fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2974fd4e5da5Sopenharmony_ci          "%2 = OpFUnordNotEqual %bool %double_1 %double_1\n" +
2975fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2976fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2977fd4e5da5Sopenharmony_ci      2, false),
2978fd4e5da5Sopenharmony_ci  // Test case 8: fold 1.0 < 1.0
2979fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2980fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2981fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2982fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThan %bool %double_1 %double_1\n" +
2983fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2984fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2985fd4e5da5Sopenharmony_ci      2, false),
2986fd4e5da5Sopenharmony_ci  // Test case 9: fold 1.0 > 1.0
2987fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2988fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2989fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2990fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThan %bool %double_1 %double_1\n" +
2991fd4e5da5Sopenharmony_ci          "OpReturn\n" +
2992fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
2993fd4e5da5Sopenharmony_ci      2, false),
2994fd4e5da5Sopenharmony_ci  // Test case 10: fold 1.0 <= 1.0
2995fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
2996fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
2997fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
2998fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThanEqual %bool %double_1 %double_1\n" +
2999fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3000fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3001fd4e5da5Sopenharmony_ci      2, true),
3002fd4e5da5Sopenharmony_ci  // Test case 11: fold 1.0 >= 1.0
3003fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3004fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3005fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3006fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThanEqual %bool %double_1 %double_1\n" +
3007fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3008fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3009fd4e5da5Sopenharmony_ci      2, true),
3010fd4e5da5Sopenharmony_ci  // Test case 12: fold 2.0 < 1.0
3011fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3012fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3013fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3014fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThan %bool %double_2 %double_1\n" +
3015fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3016fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3017fd4e5da5Sopenharmony_ci      2, false),
3018fd4e5da5Sopenharmony_ci  // Test case 13: fold 2.0 > 1.0
3019fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3020fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3021fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3022fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThan %bool %double_2 %double_1\n" +
3023fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3024fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3025fd4e5da5Sopenharmony_ci      2, true),
3026fd4e5da5Sopenharmony_ci  // Test case 14: fold 2.0 <= 1.0
3027fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3028fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3029fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3030fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThanEqual %bool %double_2 %double_1\n" +
3031fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3032fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3033fd4e5da5Sopenharmony_ci      2, false),
3034fd4e5da5Sopenharmony_ci  // Test case 15: fold 2.0 >= 1.0
3035fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3036fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3037fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3038fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThanEqual %bool %double_2 %double_1\n" +
3039fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3040fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3041fd4e5da5Sopenharmony_ci      2, true)
3042fd4e5da5Sopenharmony_ci));
3043fd4e5da5Sopenharmony_ci
3044fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FloatOrderedCompareConstantFoldingTest, BooleanInstructionFoldingTest,
3045fd4e5da5Sopenharmony_ci                        ::testing::Values(
3046fd4e5da5Sopenharmony_ci  // Test case 0: fold 1.0 == 2.0
3047fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3048fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3049fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3050fd4e5da5Sopenharmony_ci          "%2 = OpFOrdEqual %bool %float_1 %float_2\n" +
3051fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3052fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3053fd4e5da5Sopenharmony_ci      2, false),
3054fd4e5da5Sopenharmony_ci  // Test case 1: fold 1.0 != 2.0
3055fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3056fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3057fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3058fd4e5da5Sopenharmony_ci          "%2 = OpFOrdNotEqual %bool %float_1 %float_2\n" +
3059fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3060fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3061fd4e5da5Sopenharmony_ci      2, true),
3062fd4e5da5Sopenharmony_ci  // Test case 2: fold 1.0 < 2.0
3063fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3064fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3065fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3066fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThan %bool %float_1 %float_2\n" +
3067fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3068fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3069fd4e5da5Sopenharmony_ci      2, true),
3070fd4e5da5Sopenharmony_ci  // Test case 3: fold 1.0 > 2.0
3071fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3072fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3073fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3074fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThan %bool %float_1 %float_2\n" +
3075fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3076fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3077fd4e5da5Sopenharmony_ci      2, false),
3078fd4e5da5Sopenharmony_ci  // Test case 4: fold 1.0 <= 2.0
3079fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3080fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3081fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3082fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThanEqual %bool %float_1 %float_2\n" +
3083fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3084fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3085fd4e5da5Sopenharmony_ci      2, true),
3086fd4e5da5Sopenharmony_ci  // Test case 5: fold 1.0 >= 2.0
3087fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3088fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3089fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3090fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThanEqual %bool %float_1 %float_2\n" +
3091fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3092fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3093fd4e5da5Sopenharmony_ci      2, false),
3094fd4e5da5Sopenharmony_ci  // Test case 6: fold 1.0 == 1.0
3095fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3096fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3097fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3098fd4e5da5Sopenharmony_ci          "%2 = OpFOrdEqual %bool %float_1 %float_1\n" +
3099fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3100fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3101fd4e5da5Sopenharmony_ci      2, true),
3102fd4e5da5Sopenharmony_ci  // Test case 7: fold 1.0 != 1.0
3103fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3104fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3105fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3106fd4e5da5Sopenharmony_ci          "%2 = OpFOrdNotEqual %bool %float_1 %float_1\n" +
3107fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3108fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3109fd4e5da5Sopenharmony_ci      2, false),
3110fd4e5da5Sopenharmony_ci  // Test case 8: fold 1.0 < 1.0
3111fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3112fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3113fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3114fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThan %bool %float_1 %float_1\n" +
3115fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3116fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3117fd4e5da5Sopenharmony_ci      2, false),
3118fd4e5da5Sopenharmony_ci  // Test case 9: fold 1.0 > 1.0
3119fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3120fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3121fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3122fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThan %bool %float_1 %float_1\n" +
3123fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3124fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3125fd4e5da5Sopenharmony_ci      2, false),
3126fd4e5da5Sopenharmony_ci  // Test case 10: fold 1.0 <= 1.0
3127fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3128fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3129fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3130fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThanEqual %bool %float_1 %float_1\n" +
3131fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3132fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3133fd4e5da5Sopenharmony_ci      2, true),
3134fd4e5da5Sopenharmony_ci  // Test case 11: fold 1.0 >= 1.0
3135fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3136fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3137fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3138fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThanEqual %bool %float_1 %float_1\n" +
3139fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3140fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3141fd4e5da5Sopenharmony_ci      2, true),
3142fd4e5da5Sopenharmony_ci  // Test case 12: fold 2.0 < 1.0
3143fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3144fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3145fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3146fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThan %bool %float_2 %float_1\n" +
3147fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3148fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3149fd4e5da5Sopenharmony_ci      2, false),
3150fd4e5da5Sopenharmony_ci  // Test case 13: fold 2.0 > 1.0
3151fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3152fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3153fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3154fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThan %bool %float_2 %float_1\n" +
3155fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3156fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3157fd4e5da5Sopenharmony_ci      2, true),
3158fd4e5da5Sopenharmony_ci  // Test case 14: fold 2.0 <= 1.0
3159fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3160fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3161fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3162fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThanEqual %bool %float_2 %float_1\n" +
3163fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3164fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3165fd4e5da5Sopenharmony_ci      2, false),
3166fd4e5da5Sopenharmony_ci  // Test case 15: fold 2.0 >= 1.0
3167fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3168fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3169fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3170fd4e5da5Sopenharmony_ci          "%2 = OpFOrdGreaterThanEqual %bool %float_2 %float_1\n" +
3171fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3172fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3173fd4e5da5Sopenharmony_ci      2, true)
3174fd4e5da5Sopenharmony_ci));
3175fd4e5da5Sopenharmony_ci
3176fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FloatUnorderedCompareConstantFoldingTest, BooleanInstructionFoldingTest,
3177fd4e5da5Sopenharmony_ci                        ::testing::Values(
3178fd4e5da5Sopenharmony_ci  // Test case 0: fold 1.0 == 2.0
3179fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3180fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3181fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3182fd4e5da5Sopenharmony_ci          "%2 = OpFUnordEqual %bool %float_1 %float_2\n" +
3183fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3184fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3185fd4e5da5Sopenharmony_ci      2, false),
3186fd4e5da5Sopenharmony_ci  // Test case 1: fold 1.0 != 2.0
3187fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3188fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3189fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3190fd4e5da5Sopenharmony_ci          "%2 = OpFUnordNotEqual %bool %float_1 %float_2\n" +
3191fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3192fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3193fd4e5da5Sopenharmony_ci      2, true),
3194fd4e5da5Sopenharmony_ci  // Test case 2: fold 1.0 < 2.0
3195fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3196fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3197fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3198fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThan %bool %float_1 %float_2\n" +
3199fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3200fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3201fd4e5da5Sopenharmony_ci      2, true),
3202fd4e5da5Sopenharmony_ci  // Test case 3: fold 1.0 > 2.0
3203fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3204fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3205fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3206fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThan %bool %float_1 %float_2\n" +
3207fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3208fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3209fd4e5da5Sopenharmony_ci      2, false),
3210fd4e5da5Sopenharmony_ci  // Test case 4: fold 1.0 <= 2.0
3211fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3212fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3213fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3214fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThanEqual %bool %float_1 %float_2\n" +
3215fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3216fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3217fd4e5da5Sopenharmony_ci      2, true),
3218fd4e5da5Sopenharmony_ci  // Test case 5: fold 1.0 >= 2.0
3219fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3220fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3221fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3222fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThanEqual %bool %float_1 %float_2\n" +
3223fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3224fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3225fd4e5da5Sopenharmony_ci      2, false),
3226fd4e5da5Sopenharmony_ci  // Test case 6: fold 1.0 == 1.0
3227fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3228fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3229fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3230fd4e5da5Sopenharmony_ci          "%2 = OpFUnordEqual %bool %float_1 %float_1\n" +
3231fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3232fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3233fd4e5da5Sopenharmony_ci      2, true),
3234fd4e5da5Sopenharmony_ci  // Test case 7: fold 1.0 != 1.0
3235fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3236fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3237fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3238fd4e5da5Sopenharmony_ci          "%2 = OpFUnordNotEqual %bool %float_1 %float_1\n" +
3239fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3240fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3241fd4e5da5Sopenharmony_ci      2, false),
3242fd4e5da5Sopenharmony_ci  // Test case 8: fold 1.0 < 1.0
3243fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3244fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3245fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3246fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThan %bool %float_1 %float_1\n" +
3247fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3248fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3249fd4e5da5Sopenharmony_ci      2, false),
3250fd4e5da5Sopenharmony_ci  // Test case 9: fold 1.0 > 1.0
3251fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3252fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3253fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3254fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThan %bool %float_1 %float_1\n" +
3255fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3256fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3257fd4e5da5Sopenharmony_ci      2, false),
3258fd4e5da5Sopenharmony_ci  // Test case 10: fold 1.0 <= 1.0
3259fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3260fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3261fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3262fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThanEqual %bool %float_1 %float_1\n" +
3263fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3264fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3265fd4e5da5Sopenharmony_ci      2, true),
3266fd4e5da5Sopenharmony_ci  // Test case 11: fold 1.0 >= 1.0
3267fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3268fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3269fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3270fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThanEqual %bool %float_1 %float_1\n" +
3271fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3272fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3273fd4e5da5Sopenharmony_ci      2, true),
3274fd4e5da5Sopenharmony_ci  // Test case 12: fold 2.0 < 1.0
3275fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3276fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3277fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3278fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThan %bool %float_2 %float_1\n" +
3279fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3280fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3281fd4e5da5Sopenharmony_ci      2, false),
3282fd4e5da5Sopenharmony_ci  // Test case 13: fold 2.0 > 1.0
3283fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3284fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3285fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3286fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThan %bool %float_2 %float_1\n" +
3287fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3288fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3289fd4e5da5Sopenharmony_ci      2, true),
3290fd4e5da5Sopenharmony_ci  // Test case 14: fold 2.0 <= 1.0
3291fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3292fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3293fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3294fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThanEqual %bool %float_2 %float_1\n" +
3295fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3296fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3297fd4e5da5Sopenharmony_ci      2, false),
3298fd4e5da5Sopenharmony_ci  // Test case 15: fold 2.0 >= 1.0
3299fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3300fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
3301fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3302fd4e5da5Sopenharmony_ci          "%2 = OpFUnordGreaterThanEqual %bool %float_2 %float_1\n" +
3303fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3304fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3305fd4e5da5Sopenharmony_ci      2, true)
3306fd4e5da5Sopenharmony_ci));
3307fd4e5da5Sopenharmony_ci
3308fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(DoubleNaNCompareConstantFoldingTest, BooleanInstructionFoldingTest,
3309fd4e5da5Sopenharmony_ci                        ::testing::Values(
3310fd4e5da5Sopenharmony_ci  // Test case 0: fold NaN == 0 (ord)
3311fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3312fd4e5da5Sopenharmony_ci      HeaderWithNaN() + "%main = OpFunction %void None %void_func\n" +
3313fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3314fd4e5da5Sopenharmony_ci          "%2 = OpFOrdEqual %bool %double_nan %double_0\n" +
3315fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3316fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3317fd4e5da5Sopenharmony_ci      2, false),
3318fd4e5da5Sopenharmony_ci  // Test case 1: fold NaN == NaN (unord)
3319fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3320fd4e5da5Sopenharmony_ci      HeaderWithNaN() + "%main = OpFunction %void None %void_func\n" +
3321fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3322fd4e5da5Sopenharmony_ci          "%2 = OpFUnordEqual %bool %double_nan %double_0\n" +
3323fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3324fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3325fd4e5da5Sopenharmony_ci      2, true),
3326fd4e5da5Sopenharmony_ci  // Test case 2: fold NaN != NaN (ord)
3327fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3328fd4e5da5Sopenharmony_ci      HeaderWithNaN() + "%main = OpFunction %void None %void_func\n" +
3329fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3330fd4e5da5Sopenharmony_ci          "%2 = OpFOrdNotEqual %bool %double_nan %double_0\n" +
3331fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3332fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3333fd4e5da5Sopenharmony_ci      2, false),
3334fd4e5da5Sopenharmony_ci  // Test case 3: fold NaN != NaN (unord)
3335fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3336fd4e5da5Sopenharmony_ci      HeaderWithNaN() + "%main = OpFunction %void None %void_func\n" +
3337fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3338fd4e5da5Sopenharmony_ci          "%2 = OpFUnordNotEqual %bool %double_nan %double_0\n" +
3339fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3340fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3341fd4e5da5Sopenharmony_ci      2, true)
3342fd4e5da5Sopenharmony_ci));
3343fd4e5da5Sopenharmony_ci
3344fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FloatNaNCompareConstantFoldingTest, BooleanInstructionFoldingTest,
3345fd4e5da5Sopenharmony_ci                        ::testing::Values(
3346fd4e5da5Sopenharmony_ci  // Test case 0: fold NaN == 0 (ord)
3347fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3348fd4e5da5Sopenharmony_ci      HeaderWithNaN() + "%main = OpFunction %void None %void_func\n" +
3349fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3350fd4e5da5Sopenharmony_ci          "%2 = OpFOrdEqual %bool %float_nan %float_0\n" +
3351fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3352fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3353fd4e5da5Sopenharmony_ci      2, false),
3354fd4e5da5Sopenharmony_ci  // Test case 1: fold NaN == NaN (unord)
3355fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3356fd4e5da5Sopenharmony_ci      HeaderWithNaN() + "%main = OpFunction %void None %void_func\n" +
3357fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3358fd4e5da5Sopenharmony_ci          "%2 = OpFUnordEqual %bool %float_nan %float_0\n" +
3359fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3360fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3361fd4e5da5Sopenharmony_ci      2, true),
3362fd4e5da5Sopenharmony_ci  // Test case 2: fold NaN != NaN (ord)
3363fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3364fd4e5da5Sopenharmony_ci      HeaderWithNaN() + "%main = OpFunction %void None %void_func\n" +
3365fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3366fd4e5da5Sopenharmony_ci          "%2 = OpFOrdNotEqual %bool %float_nan %float_0\n" +
3367fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3368fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3369fd4e5da5Sopenharmony_ci      2, false),
3370fd4e5da5Sopenharmony_ci  // Test case 3: fold NaN != NaN (unord)
3371fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
3372fd4e5da5Sopenharmony_ci      HeaderWithNaN() + "%main = OpFunction %void None %void_func\n" +
3373fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3374fd4e5da5Sopenharmony_ci          "%2 = OpFUnordNotEqual %bool %float_nan %float_0\n" +
3375fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3376fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3377fd4e5da5Sopenharmony_ci      2, true)
3378fd4e5da5Sopenharmony_ci));
3379fd4e5da5Sopenharmony_ci// clang-format on
3380fd4e5da5Sopenharmony_ci
3381fd4e5da5Sopenharmony_citemplate <class ResultType>
3382fd4e5da5Sopenharmony_cistruct InstructionFoldingCaseWithMap {
3383fd4e5da5Sopenharmony_ci  InstructionFoldingCaseWithMap(const std::string& tb, uint32_t id,
3384fd4e5da5Sopenharmony_ci                                ResultType result,
3385fd4e5da5Sopenharmony_ci                                std::function<uint32_t(uint32_t)> map)
3386fd4e5da5Sopenharmony_ci      : test_body(tb), id_to_fold(id), expected_result(result), id_map(map) {}
3387fd4e5da5Sopenharmony_ci
3388fd4e5da5Sopenharmony_ci  std::string test_body;
3389fd4e5da5Sopenharmony_ci  uint32_t id_to_fold;
3390fd4e5da5Sopenharmony_ci  ResultType expected_result;
3391fd4e5da5Sopenharmony_ci  std::function<uint32_t(uint32_t)> id_map;
3392fd4e5da5Sopenharmony_ci};
3393fd4e5da5Sopenharmony_ci
3394fd4e5da5Sopenharmony_ciusing IntegerInstructionFoldingTestWithMap =
3395fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCaseWithMap<uint32_t>>;
3396fd4e5da5Sopenharmony_ci
3397fd4e5da5Sopenharmony_ciTEST_P(IntegerInstructionFoldingTestWithMap, Case) {
3398fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
3399fd4e5da5Sopenharmony_ci
3400fd4e5da5Sopenharmony_ci  // Build module.
3401fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
3402fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
3403fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3404fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
3405fd4e5da5Sopenharmony_ci
3406fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
3407fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
3408fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
3409fd4e5da5Sopenharmony_ci  inst = context->get_instruction_folder().FoldInstructionToConstant(inst,
3410fd4e5da5Sopenharmony_ci                                                                     tc.id_map);
3411fd4e5da5Sopenharmony_ci
3412fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
3413fd4e5da5Sopenharmony_ci  EXPECT_NE(inst, nullptr);
3414fd4e5da5Sopenharmony_ci  if (inst != nullptr) {
3415fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpConstant);
3416fd4e5da5Sopenharmony_ci    analysis::ConstantManager* const_mrg = context->get_constant_mgr();
3417fd4e5da5Sopenharmony_ci    const analysis::IntConstant* result =
3418fd4e5da5Sopenharmony_ci        const_mrg->GetConstantFromInst(inst)->AsIntConstant();
3419fd4e5da5Sopenharmony_ci    EXPECT_NE(result, nullptr);
3420fd4e5da5Sopenharmony_ci    if (result != nullptr) {
3421fd4e5da5Sopenharmony_ci      EXPECT_EQ(result->GetU32BitValue(), tc.expected_result);
3422fd4e5da5Sopenharmony_ci    }
3423fd4e5da5Sopenharmony_ci  }
3424fd4e5da5Sopenharmony_ci}
3425fd4e5da5Sopenharmony_ci// clang-format off
3426fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(TestCase, IntegerInstructionFoldingTestWithMap,
3427fd4e5da5Sopenharmony_ci  ::testing::Values(
3428fd4e5da5Sopenharmony_ci      // Test case 0: fold %3 = 0; %3 * n
3429fd4e5da5Sopenharmony_ci      InstructionFoldingCaseWithMap<uint32_t>(
3430fd4e5da5Sopenharmony_ci          Header() + "%main = OpFunction %void None %void_func\n" +
3431fd4e5da5Sopenharmony_ci              "%main_lab = OpLabel\n" +
3432fd4e5da5Sopenharmony_ci              "%n = OpVariable %_ptr_int Function\n" +
3433fd4e5da5Sopenharmony_ci              "%load = OpLoad %int %n\n" +
3434fd4e5da5Sopenharmony_ci              "%3 = OpCopyObject %int %int_0\n"
3435fd4e5da5Sopenharmony_ci              "%2 = OpIMul %int %3 %load\n" +
3436fd4e5da5Sopenharmony_ci              "OpReturn\n" +
3437fd4e5da5Sopenharmony_ci              "OpFunctionEnd",
3438fd4e5da5Sopenharmony_ci          2, 0, [](uint32_t id) {return (id == 3 ? INT_0_ID : id);})
3439fd4e5da5Sopenharmony_ci  ));
3440fd4e5da5Sopenharmony_ci// clang-format on
3441fd4e5da5Sopenharmony_ci
3442fd4e5da5Sopenharmony_ciusing BooleanInstructionFoldingTestWithMap =
3443fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCaseWithMap<bool>>;
3444fd4e5da5Sopenharmony_ci
3445fd4e5da5Sopenharmony_ciTEST_P(BooleanInstructionFoldingTestWithMap, Case) {
3446fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
3447fd4e5da5Sopenharmony_ci
3448fd4e5da5Sopenharmony_ci  // Build module.
3449fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
3450fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
3451fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3452fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
3453fd4e5da5Sopenharmony_ci
3454fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
3455fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
3456fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
3457fd4e5da5Sopenharmony_ci  inst = context->get_instruction_folder().FoldInstructionToConstant(inst,
3458fd4e5da5Sopenharmony_ci                                                                     tc.id_map);
3459fd4e5da5Sopenharmony_ci
3460fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
3461fd4e5da5Sopenharmony_ci  EXPECT_NE(inst, nullptr);
3462fd4e5da5Sopenharmony_ci  if (inst != nullptr) {
3463fd4e5da5Sopenharmony_ci    std::vector<spv::Op> bool_opcodes = {spv::Op::OpConstantTrue,
3464fd4e5da5Sopenharmony_ci                                         spv::Op::OpConstantFalse};
3465fd4e5da5Sopenharmony_ci    EXPECT_THAT(bool_opcodes, Contains(inst->opcode()));
3466fd4e5da5Sopenharmony_ci    analysis::ConstantManager* const_mrg = context->get_constant_mgr();
3467fd4e5da5Sopenharmony_ci    const analysis::BoolConstant* result =
3468fd4e5da5Sopenharmony_ci        const_mrg->GetConstantFromInst(inst)->AsBoolConstant();
3469fd4e5da5Sopenharmony_ci    EXPECT_NE(result, nullptr);
3470fd4e5da5Sopenharmony_ci    if (result != nullptr) {
3471fd4e5da5Sopenharmony_ci      EXPECT_EQ(result->value(), tc.expected_result);
3472fd4e5da5Sopenharmony_ci    }
3473fd4e5da5Sopenharmony_ci  }
3474fd4e5da5Sopenharmony_ci}
3475fd4e5da5Sopenharmony_ci
3476fd4e5da5Sopenharmony_ci// clang-format off
3477fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(TestCase, BooleanInstructionFoldingTestWithMap,
3478fd4e5da5Sopenharmony_ci  ::testing::Values(
3479fd4e5da5Sopenharmony_ci      // Test case 0: fold %3 = true; %3 || n
3480fd4e5da5Sopenharmony_ci      InstructionFoldingCaseWithMap<bool>(
3481fd4e5da5Sopenharmony_ci          Header() + "%main = OpFunction %void None %void_func\n" +
3482fd4e5da5Sopenharmony_ci              "%main_lab = OpLabel\n" +
3483fd4e5da5Sopenharmony_ci              "%n = OpVariable %_ptr_bool Function\n" +
3484fd4e5da5Sopenharmony_ci              "%load = OpLoad %bool %n\n" +
3485fd4e5da5Sopenharmony_ci              "%3 = OpCopyObject %bool %true\n" +
3486fd4e5da5Sopenharmony_ci              "%2 = OpLogicalOr %bool %3 %load\n" +
3487fd4e5da5Sopenharmony_ci              "OpReturn\n" +
3488fd4e5da5Sopenharmony_ci              "OpFunctionEnd",
3489fd4e5da5Sopenharmony_ci          2, true, [](uint32_t id) {return (id == 3 ? TRUE_ID : id);})
3490fd4e5da5Sopenharmony_ci  ));
3491fd4e5da5Sopenharmony_ci// clang-format on
3492fd4e5da5Sopenharmony_ci
3493fd4e5da5Sopenharmony_ciusing GeneralInstructionFoldingTest =
3494fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCase<uint32_t>>;
3495fd4e5da5Sopenharmony_ci
3496fd4e5da5Sopenharmony_ciTEST_P(GeneralInstructionFoldingTest, Case) {
3497fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
3498fd4e5da5Sopenharmony_ci
3499fd4e5da5Sopenharmony_ci  // Build module.
3500fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
3501fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
3502fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
3503fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
3504fd4e5da5Sopenharmony_ci
3505fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
3506fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
3507fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
3508fd4e5da5Sopenharmony_ci  std::unique_ptr<Instruction> original_inst(inst->Clone(context.get()));
3509fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
3510fd4e5da5Sopenharmony_ci
3511fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
3512fd4e5da5Sopenharmony_ci  EXPECT_EQ(inst->result_id(), original_inst->result_id());
3513fd4e5da5Sopenharmony_ci  EXPECT_EQ(inst->type_id(), original_inst->type_id());
3514fd4e5da5Sopenharmony_ci  EXPECT_TRUE((!succeeded) == (tc.expected_result == 0));
3515fd4e5da5Sopenharmony_ci  if (succeeded) {
3516fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpCopyObject);
3517fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->GetSingleWordInOperand(0), tc.expected_result);
3518fd4e5da5Sopenharmony_ci  } else {
3519fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->NumInOperands(), original_inst->NumInOperands());
3520fd4e5da5Sopenharmony_ci    for (uint32_t i = 0; i < inst->NumInOperands(); ++i) {
3521fd4e5da5Sopenharmony_ci      EXPECT_EQ(inst->GetOperand(i), original_inst->GetOperand(i));
3522fd4e5da5Sopenharmony_ci    }
3523fd4e5da5Sopenharmony_ci  }
3524fd4e5da5Sopenharmony_ci}
3525fd4e5da5Sopenharmony_ci
3526fd4e5da5Sopenharmony_ci// clang-format off
3527fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(IntegerArithmeticTestCases, GeneralInstructionFoldingTest,
3528fd4e5da5Sopenharmony_ci                        ::testing::Values(
3529fd4e5da5Sopenharmony_ci    // Test case 0: Don't fold n * m
3530fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3531fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3532fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3533fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3534fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_int Function\n" +
3535fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3536fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %int %m\n" +
3537fd4e5da5Sopenharmony_ci            "%2 = OpIMul %int %load_n %load_m\n" +
3538fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3539fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3540fd4e5da5Sopenharmony_ci        2, 0),
3541fd4e5da5Sopenharmony_ci    // Test case 1: Don't fold n / m (unsigned)
3542fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3543fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3544fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3545fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3546fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_uint Function\n" +
3547fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3548fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %uint %m\n" +
3549fd4e5da5Sopenharmony_ci            "%2 = OpUDiv %uint %load_n %load_m\n" +
3550fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3551fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3552fd4e5da5Sopenharmony_ci        2, 0),
3553fd4e5da5Sopenharmony_ci    // Test case 2: Don't fold n / m (signed)
3554fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3555fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3556fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3557fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3558fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_int Function\n" +
3559fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3560fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %int %m\n" +
3561fd4e5da5Sopenharmony_ci            "%2 = OpSDiv %int %load_n %load_m\n" +
3562fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3563fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3564fd4e5da5Sopenharmony_ci        2, 0),
3565fd4e5da5Sopenharmony_ci    // Test case 3: Don't fold n remainder m
3566fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3567fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3568fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3569fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3570fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_int Function\n" +
3571fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3572fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %int %m\n" +
3573fd4e5da5Sopenharmony_ci            "%2 = OpSRem %int %load_n %load_m\n" +
3574fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3575fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3576fd4e5da5Sopenharmony_ci        2, 0),
3577fd4e5da5Sopenharmony_ci    // Test case 4: Don't fold n % m (signed)
3578fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3579fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3580fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3581fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3582fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_int Function\n" +
3583fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3584fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %int %m\n" +
3585fd4e5da5Sopenharmony_ci            "%2 = OpSMod %int %load_n %load_m\n" +
3586fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3587fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3588fd4e5da5Sopenharmony_ci        2, 0),
3589fd4e5da5Sopenharmony_ci    // Test case 5: Don't fold n % m (unsigned)
3590fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3591fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3592fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3593fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3594fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_uint Function\n" +
3595fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3596fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %uint %m\n" +
3597fd4e5da5Sopenharmony_ci            "%2 = OpUMod %int %load_n %load_m\n" +
3598fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3599fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3600fd4e5da5Sopenharmony_ci        2, 0),
3601fd4e5da5Sopenharmony_ci    // Test case 6: Don't fold n << m
3602fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3603fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3604fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3605fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3606fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_uint Function\n" +
3607fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3608fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %uint %m\n" +
3609fd4e5da5Sopenharmony_ci            "%2 = OpShiftRightLogical %int %load_n %load_m\n" +
3610fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3611fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3612fd4e5da5Sopenharmony_ci        2, 0),
3613fd4e5da5Sopenharmony_ci    // Test case 7: Don't fold n >> m
3614fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3615fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3616fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3617fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3618fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_uint Function\n" +
3619fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3620fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %uint %m\n" +
3621fd4e5da5Sopenharmony_ci            "%2 = OpShiftLeftLogical %int %load_n %load_m\n" +
3622fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3623fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3624fd4e5da5Sopenharmony_ci        2, 0),
3625fd4e5da5Sopenharmony_ci    // Test case 8: Don't fold n | m
3626fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3627fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3628fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3629fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3630fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_uint Function\n" +
3631fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3632fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %uint %m\n" +
3633fd4e5da5Sopenharmony_ci            "%2 = OpBitwiseOr %int %load_n %load_m\n" +
3634fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3635fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3636fd4e5da5Sopenharmony_ci        2, 0),
3637fd4e5da5Sopenharmony_ci    // Test case 9: Don't fold n & m
3638fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3639fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3640fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3641fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3642fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_uint Function\n" +
3643fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3644fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %uint %m\n" +
3645fd4e5da5Sopenharmony_ci            "%2 = OpBitwiseAnd %int %load_n %load_m\n" +
3646fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3647fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3648fd4e5da5Sopenharmony_ci        2, 0),
3649fd4e5da5Sopenharmony_ci    // Test case 10: Don't fold n < m (unsigned)
3650fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3651fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3652fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3653fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3654fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_uint Function\n" +
3655fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3656fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %uint %m\n" +
3657fd4e5da5Sopenharmony_ci            "%2 = OpULessThan %bool %load_n %load_m\n" +
3658fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3659fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3660fd4e5da5Sopenharmony_ci        2, 0),
3661fd4e5da5Sopenharmony_ci    // Test case 11: Don't fold n > m (unsigned)
3662fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3663fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3664fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3665fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3666fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_uint Function\n" +
3667fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3668fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %uint %m\n" +
3669fd4e5da5Sopenharmony_ci            "%2 = OpUGreaterThan %bool %load_n %load_m\n" +
3670fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3671fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3672fd4e5da5Sopenharmony_ci        2, 0),
3673fd4e5da5Sopenharmony_ci    // Test case 12: Don't fold n <= m (unsigned)
3674fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3675fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3676fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3677fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3678fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_uint Function\n" +
3679fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3680fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %uint %m\n" +
3681fd4e5da5Sopenharmony_ci            "%2 = OpULessThanEqual %bool %load_n %load_m\n" +
3682fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3683fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3684fd4e5da5Sopenharmony_ci        2, 0),
3685fd4e5da5Sopenharmony_ci    // Test case 13: Don't fold n >= m (unsigned)
3686fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3687fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3688fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3689fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3690fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_uint Function\n" +
3691fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3692fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %uint %m\n" +
3693fd4e5da5Sopenharmony_ci            "%2 = OpUGreaterThanEqual %bool %load_n %load_m\n" +
3694fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3695fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3696fd4e5da5Sopenharmony_ci        2, 0),
3697fd4e5da5Sopenharmony_ci    // Test case 14: Don't fold n < m (signed)
3698fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3699fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3700fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3701fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3702fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_int Function\n" +
3703fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3704fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %int %m\n" +
3705fd4e5da5Sopenharmony_ci            "%2 = OpULessThan %bool %load_n %load_m\n" +
3706fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3707fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3708fd4e5da5Sopenharmony_ci        2, 0),
3709fd4e5da5Sopenharmony_ci    // Test case 15: Don't fold n > m (signed)
3710fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3711fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3712fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3713fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3714fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_int Function\n" +
3715fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3716fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %int %m\n" +
3717fd4e5da5Sopenharmony_ci            "%2 = OpUGreaterThan %bool %load_n %load_m\n" +
3718fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3719fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3720fd4e5da5Sopenharmony_ci        2, 0),
3721fd4e5da5Sopenharmony_ci    // Test case 16: Don't fold n <= m (signed)
3722fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3723fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3724fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3725fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3726fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_int Function\n" +
3727fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3728fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %int %m\n" +
3729fd4e5da5Sopenharmony_ci            "%2 = OpULessThanEqual %bool %load_n %load_m\n" +
3730fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3731fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3732fd4e5da5Sopenharmony_ci        2, 0),
3733fd4e5da5Sopenharmony_ci    // Test case 17: Don't fold n >= m (signed)
3734fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3735fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3736fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3737fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3738fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_int Function\n" +
3739fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3740fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %int %m\n" +
3741fd4e5da5Sopenharmony_ci            "%2 = OpUGreaterThanEqual %bool %load_n %load_m\n" +
3742fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3743fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3744fd4e5da5Sopenharmony_ci        2, 0),
3745fd4e5da5Sopenharmony_ci    // Test case 18: Don't fold n || m
3746fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3747fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3748fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3749fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_bool Function\n" +
3750fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_bool Function\n" +
3751fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %bool %n\n" +
3752fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %bool %m\n" +
3753fd4e5da5Sopenharmony_ci            "%2 = OpLogicalOr %bool %load_n %load_m\n" +
3754fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3755fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3756fd4e5da5Sopenharmony_ci        2, 0),
3757fd4e5da5Sopenharmony_ci    // Test case 19: Don't fold n && m
3758fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3759fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3760fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3761fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_bool Function\n" +
3762fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_bool Function\n" +
3763fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %bool %n\n" +
3764fd4e5da5Sopenharmony_ci            "%load_m = OpLoad %bool %m\n" +
3765fd4e5da5Sopenharmony_ci            "%2 = OpLogicalAnd %bool %load_n %load_m\n" +
3766fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3767fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3768fd4e5da5Sopenharmony_ci        2, 0),
3769fd4e5da5Sopenharmony_ci    // Test case 20: Don't fold n * 3
3770fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3771fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3772fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3773fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3774fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3775fd4e5da5Sopenharmony_ci            "%2 = OpIMul %int %load_n %int_3\n" +
3776fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3777fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3778fd4e5da5Sopenharmony_ci        2, 0),
3779fd4e5da5Sopenharmony_ci    // Test case 21: Don't fold n / 3 (unsigned)
3780fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3781fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3782fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3783fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3784fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3785fd4e5da5Sopenharmony_ci            "%2 = OpUDiv %uint %load_n %uint_3\n" +
3786fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3787fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3788fd4e5da5Sopenharmony_ci        2, 0),
3789fd4e5da5Sopenharmony_ci    // Test case 22: Don't fold n / 3 (signed)
3790fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3791fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3792fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3793fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3794fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3795fd4e5da5Sopenharmony_ci            "%2 = OpSDiv %int %load_n %int_3\n" +
3796fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3797fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3798fd4e5da5Sopenharmony_ci        2, 0),
3799fd4e5da5Sopenharmony_ci    // Test case 23: Don't fold n remainder 3
3800fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3801fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3802fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3803fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3804fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3805fd4e5da5Sopenharmony_ci            "%2 = OpSRem %int %load_n %int_3\n" +
3806fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3807fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3808fd4e5da5Sopenharmony_ci        2, 0),
3809fd4e5da5Sopenharmony_ci    // Test case 24: Don't fold n % 3 (signed)
3810fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3811fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3812fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3813fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3814fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3815fd4e5da5Sopenharmony_ci            "%2 = OpSMod %int %load_n %int_3\n" +
3816fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3817fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3818fd4e5da5Sopenharmony_ci        2, 0),
3819fd4e5da5Sopenharmony_ci    // Test case 25: Don't fold n % 3 (unsigned)
3820fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3821fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3822fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3823fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3824fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3825fd4e5da5Sopenharmony_ci            "%2 = OpUMod %int %load_n %int_3\n" +
3826fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3827fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3828fd4e5da5Sopenharmony_ci        2, 0),
3829fd4e5da5Sopenharmony_ci    // Test case 26: Don't fold n << 3
3830fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3831fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3832fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3833fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3834fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3835fd4e5da5Sopenharmony_ci            "%2 = OpShiftRightLogical %int %load_n %int_3\n" +
3836fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3837fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3838fd4e5da5Sopenharmony_ci        2, 0),
3839fd4e5da5Sopenharmony_ci    // Test case 27: Don't fold n >> 3
3840fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3841fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3842fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3843fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3844fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3845fd4e5da5Sopenharmony_ci            "%2 = OpShiftLeftLogical %int %load_n %int_3\n" +
3846fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3847fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3848fd4e5da5Sopenharmony_ci        2, 0),
3849fd4e5da5Sopenharmony_ci    // Test case 28: Don't fold n | 3
3850fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3851fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3852fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3853fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3854fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3855fd4e5da5Sopenharmony_ci            "%2 = OpBitwiseOr %int %load_n %int_3\n" +
3856fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3857fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3858fd4e5da5Sopenharmony_ci        2, 0),
3859fd4e5da5Sopenharmony_ci    // Test case 29: Don't fold n & 3
3860fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3861fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3862fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3863fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3864fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3865fd4e5da5Sopenharmony_ci            "%2 = OpBitwiseAnd %uint %load_n %uint_3\n" +
3866fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3867fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3868fd4e5da5Sopenharmony_ci        2, 0),
3869fd4e5da5Sopenharmony_ci    // Test case 30: Don't fold n < 3 (unsigned)
3870fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3871fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3872fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3873fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3874fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3875fd4e5da5Sopenharmony_ci            "%2 = OpULessThan %bool %load_n %uint_3\n" +
3876fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3877fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3878fd4e5da5Sopenharmony_ci        2, 0),
3879fd4e5da5Sopenharmony_ci    // Test case 31: Don't fold n > 3 (unsigned)
3880fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3881fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3882fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3883fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3884fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3885fd4e5da5Sopenharmony_ci            "%2 = OpUGreaterThan %bool %load_n %uint_3\n" +
3886fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3887fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3888fd4e5da5Sopenharmony_ci        2, 0),
3889fd4e5da5Sopenharmony_ci    // Test case 32: Don't fold n <= 3 (unsigned)
3890fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3891fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3892fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3893fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3894fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3895fd4e5da5Sopenharmony_ci            "%2 = OpULessThanEqual %bool %load_n %uint_3\n" +
3896fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3897fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3898fd4e5da5Sopenharmony_ci        2, 0),
3899fd4e5da5Sopenharmony_ci    // Test case 33: Don't fold n >= 3 (unsigned)
3900fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3901fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3902fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3903fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
3904fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %uint %n\n" +
3905fd4e5da5Sopenharmony_ci            "%2 = OpUGreaterThanEqual %bool %load_n %uint_3\n" +
3906fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3907fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3908fd4e5da5Sopenharmony_ci        2, 0),
3909fd4e5da5Sopenharmony_ci    // Test case 34: Don't fold n < 3 (signed)
3910fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3911fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3912fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3913fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3914fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3915fd4e5da5Sopenharmony_ci            "%2 = OpULessThan %bool %load_n %int_3\n" +
3916fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3917fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3918fd4e5da5Sopenharmony_ci        2, 0),
3919fd4e5da5Sopenharmony_ci    // Test case 35: Don't fold n > 3 (signed)
3920fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3921fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3922fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3923fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3924fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3925fd4e5da5Sopenharmony_ci            "%2 = OpUGreaterThan %bool %load_n %int_3\n" +
3926fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3927fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3928fd4e5da5Sopenharmony_ci        2, 0),
3929fd4e5da5Sopenharmony_ci    // Test case 36: Don't fold n <= 3 (signed)
3930fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3931fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3932fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3933fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3934fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3935fd4e5da5Sopenharmony_ci            "%2 = OpULessThanEqual %bool %load_n %int_3\n" +
3936fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3937fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3938fd4e5da5Sopenharmony_ci        2, 0),
3939fd4e5da5Sopenharmony_ci    // Test case 37: Don't fold n >= 3 (signed)
3940fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3941fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3942fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3943fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3944fd4e5da5Sopenharmony_ci            "%load_n = OpLoad %int %n\n" +
3945fd4e5da5Sopenharmony_ci            "%2 = OpUGreaterThanEqual %bool %load_n %int_3\n" +
3946fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3947fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3948fd4e5da5Sopenharmony_ci        2, 0),
3949fd4e5da5Sopenharmony_ci    // Test case 38: Don't fold 2 + 3 (long), bad length
3950fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3951fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3952fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3953fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %long %long_2 %long_3\n" +
3954fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3955fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3956fd4e5da5Sopenharmony_ci        2, 0),
3957fd4e5da5Sopenharmony_ci    // Test case 39: Don't fold 2 + 3 (short), bad length
3958fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3959fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3960fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3961fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %short %short_2 %short_3\n" +
3962fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3963fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3964fd4e5da5Sopenharmony_ci        2, 0),
3965fd4e5da5Sopenharmony_ci    // Test case 40: fold 1*n
3966fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3967fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3968fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3969fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3970fd4e5da5Sopenharmony_ci            "%3 = OpLoad %int %n\n" +
3971fd4e5da5Sopenharmony_ci            "%2 = OpIMul %int %int_1 %3\n" +
3972fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3973fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3974fd4e5da5Sopenharmony_ci        2, 3),
3975fd4e5da5Sopenharmony_ci    // Test case 41: fold n*1
3976fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3977fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3978fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
3979fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
3980fd4e5da5Sopenharmony_ci            "%3 = OpLoad %int %n\n" +
3981fd4e5da5Sopenharmony_ci            "%2 = OpIMul %int %3 %int_1\n" +
3982fd4e5da5Sopenharmony_ci            "OpReturn\n" +
3983fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
3984fd4e5da5Sopenharmony_ci        2, 3),
3985fd4e5da5Sopenharmony_ci    // Test case 42: Don't fold comparisons of 64-bit types
3986fd4e5da5Sopenharmony_ci    // (https://github.com/KhronosGroup/SPIRV-Tools/issues/3343).
3987fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
3988fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
3989fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
3990fd4e5da5Sopenharmony_ci          "%2 = OpSLessThan %bool %long_0 %long_2\n" +
3991fd4e5da5Sopenharmony_ci          "OpReturn\n" +
3992fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
3993fd4e5da5Sopenharmony_ci        2, 0)
3994fd4e5da5Sopenharmony_ci));
3995fd4e5da5Sopenharmony_ci
3996fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(CompositeExtractFoldingTest, GeneralInstructionFoldingTest,
3997fd4e5da5Sopenharmony_ci::testing::Values(
3998fd4e5da5Sopenharmony_ci    // Test case 0: fold Insert feeding extract
3999fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4000fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4001fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4002fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
4003fd4e5da5Sopenharmony_ci            "%2 = OpLoad %int %n\n" +
4004fd4e5da5Sopenharmony_ci            "%3 = OpCompositeInsert %v4int %2 %v4int_0_0_0_0 0\n" +
4005fd4e5da5Sopenharmony_ci            "%4 = OpCompositeInsert %v4int %int_1 %3 1\n" +
4006fd4e5da5Sopenharmony_ci            "%5 = OpCompositeInsert %v4int %int_1 %4 2\n" +
4007fd4e5da5Sopenharmony_ci            "%6 = OpCompositeInsert %v4int %int_1 %5 3\n" +
4008fd4e5da5Sopenharmony_ci            "%7 = OpCompositeExtract %int %6 0\n" +
4009fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4010fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4011fd4e5da5Sopenharmony_ci        7, 2),
4012fd4e5da5Sopenharmony_ci    // Test case 1: fold Composite construct feeding extract (position 0)
4013fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4014fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4015fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4016fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
4017fd4e5da5Sopenharmony_ci            "%2 = OpLoad %int %n\n" +
4018fd4e5da5Sopenharmony_ci            "%3 = OpCompositeConstruct %v4int %2 %int_0 %int_0 %int_0\n" +
4019fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %3 0\n" +
4020fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4021fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4022fd4e5da5Sopenharmony_ci        4, 2),
4023fd4e5da5Sopenharmony_ci    // Test case 2: fold Composite construct feeding extract (position 3)
4024fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4025fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4026fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4027fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
4028fd4e5da5Sopenharmony_ci            "%2 = OpLoad %int %n\n" +
4029fd4e5da5Sopenharmony_ci            "%3 = OpCompositeConstruct %v4int %2 %int_0 %int_0 %100\n" +
4030fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %3 3\n" +
4031fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4032fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4033fd4e5da5Sopenharmony_ci        4, INT_0_ID),
4034fd4e5da5Sopenharmony_ci    // Test case 3: fold Composite construct with vectors feeding extract (scalar element)
4035fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4036fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4037fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4038fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
4039fd4e5da5Sopenharmony_ci            "%2 = OpLoad %int %n\n" +
4040fd4e5da5Sopenharmony_ci            "%3 = OpCompositeConstruct %v2int %2 %int_0\n" +
4041fd4e5da5Sopenharmony_ci            "%4 = OpCompositeConstruct %v4int %3 %int_0 %100\n" +
4042fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %int %4 3\n" +
4043fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4044fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4045fd4e5da5Sopenharmony_ci        5, INT_0_ID),
4046fd4e5da5Sopenharmony_ci    // Test case 4: fold Composite construct with vectors feeding extract (start of vector element)
4047fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4048fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4049fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4050fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
4051fd4e5da5Sopenharmony_ci            "%2 = OpLoad %int %n\n" +
4052fd4e5da5Sopenharmony_ci            "%3 = OpCompositeConstruct %v2int %2 %int_0\n" +
4053fd4e5da5Sopenharmony_ci            "%4 = OpCompositeConstruct %v4int %3 %int_0 %100\n" +
4054fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %int %4 0\n" +
4055fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4056fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4057fd4e5da5Sopenharmony_ci        5, 2),
4058fd4e5da5Sopenharmony_ci    // Test case 5: fold Composite construct with vectors feeding extract (middle of vector element)
4059fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4060fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4061fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4062fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
4063fd4e5da5Sopenharmony_ci            "%2 = OpLoad %int %n\n" +
4064fd4e5da5Sopenharmony_ci            "%3 = OpCompositeConstruct %v2int %int_0 %2\n" +
4065fd4e5da5Sopenharmony_ci            "%4 = OpCompositeConstruct %v4int %3 %int_0 %100\n" +
4066fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %int %4 1\n" +
4067fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4068fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4069fd4e5da5Sopenharmony_ci        5, 2),
4070fd4e5da5Sopenharmony_ci    // Test case 6: fold Composite construct with multiple indices.
4071fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4072fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4073fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4074fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
4075fd4e5da5Sopenharmony_ci            "%2 = OpLoad %int %n\n" +
4076fd4e5da5Sopenharmony_ci            "%3 = OpCompositeConstruct %v2int %int_0 %2\n" +
4077fd4e5da5Sopenharmony_ci            "%4 = OpCompositeConstruct %struct_v2int_int_int %3 %int_0 %100\n" +
4078fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %int %4 0 1\n" +
4079fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4080fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4081fd4e5da5Sopenharmony_ci        5, 2),
4082fd4e5da5Sopenharmony_ci    // Test case 7: fold constant extract.
4083fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4084fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4085fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4086fd4e5da5Sopenharmony_ci            "%2 = OpCompositeExtract %int %102 1\n" +
4087fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4088fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4089fd4e5da5Sopenharmony_ci        2, INT_7_ID),
4090fd4e5da5Sopenharmony_ci    // Test case 8: constant struct has OpUndef
4091fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4092fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4093fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4094fd4e5da5Sopenharmony_ci            "%2 = OpCompositeExtract %int %struct_undef_0_0 0 1\n" +
4095fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4096fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4097fd4e5da5Sopenharmony_ci        2, 0),
4098fd4e5da5Sopenharmony_ci    // Test case 9: Extracting a member of element inserted via Insert
4099fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4100fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4101fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4102fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_struct_v2int_int_int Function\n" +
4103fd4e5da5Sopenharmony_ci            "%2 = OpLoad %struct_v2int_int_int %n\n" +
4104fd4e5da5Sopenharmony_ci            "%3 = OpCompositeInsert %struct_v2int_int_int %102 %2 0\n" +
4105fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %3 0 1\n" +
4106fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4107fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4108fd4e5da5Sopenharmony_ci        4, 103),
4109fd4e5da5Sopenharmony_ci    // Test case 10: Extracting a element that is partially changed by Insert. (Don't fold)
4110fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4111fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4112fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4113fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_struct_v2int_int_int Function\n" +
4114fd4e5da5Sopenharmony_ci            "%2 = OpLoad %struct_v2int_int_int %n\n" +
4115fd4e5da5Sopenharmony_ci            "%3 = OpCompositeInsert %struct_v2int_int_int %int_0 %2 0 1\n" +
4116fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %v2int %3 0\n" +
4117fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4118fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4119fd4e5da5Sopenharmony_ci        4, 0),
4120fd4e5da5Sopenharmony_ci    // Test case 11: Extracting from result of vector shuffle (first input)
4121fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4122fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4123fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4124fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v2int Function\n" +
4125fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v2int %n\n" +
4126fd4e5da5Sopenharmony_ci            "%3 = OpVectorShuffle %v2int %102 %2 3 0\n" +
4127fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %3 1\n" +
4128fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4129fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4130fd4e5da5Sopenharmony_ci        4, INT_7_ID),
4131fd4e5da5Sopenharmony_ci    // Test case 12: Extracting from result of vector shuffle (second input)
4132fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4133fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4134fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4135fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v2int Function\n" +
4136fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v2int %n\n" +
4137fd4e5da5Sopenharmony_ci            "%3 = OpVectorShuffle %v2int %2 %102 2 0\n" +
4138fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %3 0\n" +
4139fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4140fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4141fd4e5da5Sopenharmony_ci        4, INT_7_ID),
4142fd4e5da5Sopenharmony_ci    // Test case 13: https://github.com/KhronosGroup/SPIRV-Tools/issues/2608
4143fd4e5da5Sopenharmony_ci    // Out of bounds access.  Do not fold.
4144fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4145fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4146fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4147fd4e5da5Sopenharmony_ci            "%2 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1\n" +
4148fd4e5da5Sopenharmony_ci            "%3 = OpCompositeExtract %float %2 4\n" +
4149fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4150fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4151fd4e5da5Sopenharmony_ci        3, 0),
4152fd4e5da5Sopenharmony_ci    // Test case 14: https://github.com/KhronosGroup/SPIRV-Tools/issues/3631
4153fd4e5da5Sopenharmony_ci    // Extract the component right after the vector constituent.
4154fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4155fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4156fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4157fd4e5da5Sopenharmony_ci            "%2 = OpCompositeConstruct %v2int %int_0 %int_0\n" +
4158fd4e5da5Sopenharmony_ci            "%3 = OpCompositeConstruct %v4int %2 %100 %int_0\n" +
4159fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %3 2\n" +
4160fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4161fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4162fd4e5da5Sopenharmony_ci        4, INT_0_ID),
4163fd4e5da5Sopenharmony_ci    // Test case 15:
4164fd4e5da5Sopenharmony_ci    // Don't fold extract fed by construct with vector result if the index is
4165fd4e5da5Sopenharmony_ci    // past the last element.
4166fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4167fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4168fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4169fd4e5da5Sopenharmony_ci            "%2 = OpCompositeConstruct %v2int %int_0 %int_0\n" +
4170fd4e5da5Sopenharmony_ci            "%3 = OpCompositeConstruct %v4int %2 %100 %int_0\n" +
4171fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %3 4\n" +
4172fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4173fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4174fd4e5da5Sopenharmony_ci        4, 0)
4175fd4e5da5Sopenharmony_ci));
4176fd4e5da5Sopenharmony_ci
4177fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(CompositeConstructFoldingTest, GeneralInstructionFoldingTest,
4178fd4e5da5Sopenharmony_ci::testing::Values(
4179fd4e5da5Sopenharmony_ci    // Test case 0: fold Extracts feeding construct
4180fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4181fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4182fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4183fd4e5da5Sopenharmony_ci            "%2 = OpCopyObject %v4int %v4int_0_0_0_0\n" +
4184fd4e5da5Sopenharmony_ci            "%3 = OpCompositeExtract %int %2 0\n" +
4185fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %2 1\n" +
4186fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %int %2 2\n" +
4187fd4e5da5Sopenharmony_ci            "%6 = OpCompositeExtract %int %2 3\n" +
4188fd4e5da5Sopenharmony_ci            "%7 = OpCompositeConstruct %v4int %3 %4 %5 %6\n" +
4189fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4190fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4191fd4e5da5Sopenharmony_ci        7, 2),
4192fd4e5da5Sopenharmony_ci    // Test case 1: Don't fold Extracts feeding construct (Different source)
4193fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4194fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4195fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4196fd4e5da5Sopenharmony_ci            "%2 = OpCopyObject %v4int %v4int_0_0_0_0\n" +
4197fd4e5da5Sopenharmony_ci            "%3 = OpCompositeExtract %int %2 0\n" +
4198fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %2 1\n" +
4199fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %int %2 2\n" +
4200fd4e5da5Sopenharmony_ci            "%6 = OpCompositeExtract %int %v4int_0_0_0_0 3\n" +
4201fd4e5da5Sopenharmony_ci            "%7 = OpCompositeConstruct %v4int %3 %4 %5 %6\n" +
4202fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4203fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4204fd4e5da5Sopenharmony_ci        7, 0),
4205fd4e5da5Sopenharmony_ci    // Test case 2: Don't fold Extracts feeding construct (bad indices)
4206fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4207fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4208fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4209fd4e5da5Sopenharmony_ci            "%2 = OpCopyObject %v4int %v4int_0_0_0_0\n" +
4210fd4e5da5Sopenharmony_ci            "%3 = OpCompositeExtract %int %2 0\n" +
4211fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %2 0\n" +
4212fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %int %2 2\n" +
4213fd4e5da5Sopenharmony_ci            "%6 = OpCompositeExtract %int %2 3\n" +
4214fd4e5da5Sopenharmony_ci            "%7 = OpCompositeConstruct %v4int %3 %4 %5 %6\n" +
4215fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4216fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4217fd4e5da5Sopenharmony_ci        7, 0),
4218fd4e5da5Sopenharmony_ci    // Test case 3: Don't fold Extracts feeding construct (different type)
4219fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4220fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4221fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4222fd4e5da5Sopenharmony_ci            "%2 = OpCopyObject %struct_v2int_int_int %struct_v2int_int_int_null\n" +
4223fd4e5da5Sopenharmony_ci            "%3 = OpCompositeExtract %v2int %2 0\n" +
4224fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %2 1\n" +
4225fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %int %2 2\n" +
4226fd4e5da5Sopenharmony_ci            "%7 = OpCompositeConstruct %v4int %3 %4 %5\n" +
4227fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4228fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4229fd4e5da5Sopenharmony_ci        7, 0),
4230fd4e5da5Sopenharmony_ci    // Test case 4: Fold construct with constants to constant.
4231fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4232fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4233fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4234fd4e5da5Sopenharmony_ci            "%2 = OpCompositeConstruct %v2int %103 %103\n" +
4235fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4236fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4237fd4e5da5Sopenharmony_ci        2, VEC2_0_ID),
4238fd4e5da5Sopenharmony_ci    // Test case 5: Don't segfault when trying to fold an OpCompositeConstruct
4239fd4e5da5Sopenharmony_ci    // for an empty struct, and we reached the id limit.
4240fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4241fd4e5da5Sopenharmony_ci        Header() + "%empty_struct = OpTypeStruct\n" +
4242fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
4243fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4244fd4e5da5Sopenharmony_ci            "%4194303 = OpCompositeConstruct %empty_struct\n" +
4245fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4246fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4247fd4e5da5Sopenharmony_ci        4194303, 0)
4248fd4e5da5Sopenharmony_ci));
4249fd4e5da5Sopenharmony_ci
4250fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(PhiFoldingTest, GeneralInstructionFoldingTest,
4251fd4e5da5Sopenharmony_ci::testing::Values(
4252fd4e5da5Sopenharmony_ci  // Test case 0: Fold phi with the same values for all edges.
4253fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
4254fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
4255fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
4256fd4e5da5Sopenharmony_ci          "            OpBranchConditional %true %l1 %l2\n" +
4257fd4e5da5Sopenharmony_ci          "%l1 = OpLabel\n" +
4258fd4e5da5Sopenharmony_ci          "      OpBranch %merge_lab\n" +
4259fd4e5da5Sopenharmony_ci          "%l2 = OpLabel\n" +
4260fd4e5da5Sopenharmony_ci          "      OpBranch %merge_lab\n" +
4261fd4e5da5Sopenharmony_ci          "%merge_lab = OpLabel\n" +
4262fd4e5da5Sopenharmony_ci          "%2 = OpPhi %int %100 %l1 %100 %l2\n" +
4263fd4e5da5Sopenharmony_ci          "OpReturn\n" +
4264fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
4265fd4e5da5Sopenharmony_ci      2, INT_0_ID),
4266fd4e5da5Sopenharmony_ci  // Test case 1: Fold phi in pass through loop.
4267fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
4268fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
4269fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
4270fd4e5da5Sopenharmony_ci          "            OpBranch %l1\n" +
4271fd4e5da5Sopenharmony_ci          "%l1 = OpLabel\n" +
4272fd4e5da5Sopenharmony_ci          "%2 = OpPhi %int %100 %main_lab %2 %l1\n" +
4273fd4e5da5Sopenharmony_ci          "      OpBranchConditional %true %l1 %merge_lab\n" +
4274fd4e5da5Sopenharmony_ci          "%merge_lab = OpLabel\n" +
4275fd4e5da5Sopenharmony_ci          "OpReturn\n" +
4276fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
4277fd4e5da5Sopenharmony_ci      2, INT_0_ID),
4278fd4e5da5Sopenharmony_ci  // Test case 2: Don't Fold phi because of different values.
4279fd4e5da5Sopenharmony_ci  InstructionFoldingCase<uint32_t>(
4280fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
4281fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
4282fd4e5da5Sopenharmony_ci          "            OpBranch %l1\n" +
4283fd4e5da5Sopenharmony_ci          "%l1 = OpLabel\n" +
4284fd4e5da5Sopenharmony_ci          "%2 = OpPhi %int %int_0 %main_lab %int_3 %l1\n" +
4285fd4e5da5Sopenharmony_ci          "      OpBranchConditional %true %l1 %merge_lab\n" +
4286fd4e5da5Sopenharmony_ci          "%merge_lab = OpLabel\n" +
4287fd4e5da5Sopenharmony_ci          "OpReturn\n" +
4288fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
4289fd4e5da5Sopenharmony_ci      2, 0)
4290fd4e5da5Sopenharmony_ci));
4291fd4e5da5Sopenharmony_ci
4292fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FloatRedundantFoldingTest, GeneralInstructionFoldingTest,
4293fd4e5da5Sopenharmony_ci                        ::testing::Values(
4294fd4e5da5Sopenharmony_ci    // Test case 0: Don't fold n + 1.0
4295fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4296fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4297fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4298fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4299fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4300fd4e5da5Sopenharmony_ci            "%2 = OpFAdd %float %3 %float_2\n" +
4301fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4302fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4303fd4e5da5Sopenharmony_ci        2, 0),
4304fd4e5da5Sopenharmony_ci    // Test case 1: Don't fold n - 1.0
4305fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4306fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4307fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4308fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4309fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4310fd4e5da5Sopenharmony_ci            "%2 = OpFSub %float %3 %float_2\n" +
4311fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4312fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4313fd4e5da5Sopenharmony_ci        2, 0),
4314fd4e5da5Sopenharmony_ci    // Test case 2: Don't fold n * 2.0
4315fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4316fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4317fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4318fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4319fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4320fd4e5da5Sopenharmony_ci            "%2 = OpFMul %float %3 %float_2\n" +
4321fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4322fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4323fd4e5da5Sopenharmony_ci        2, 0),
4324fd4e5da5Sopenharmony_ci    // Test case 3: Fold n + 0.0
4325fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4326fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4327fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4328fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4329fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4330fd4e5da5Sopenharmony_ci            "%2 = OpFAdd %float %3 %float_0\n" +
4331fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4332fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4333fd4e5da5Sopenharmony_ci        2, 3),
4334fd4e5da5Sopenharmony_ci    // Test case 4: Fold 0.0 + n
4335fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4336fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4337fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4338fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4339fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4340fd4e5da5Sopenharmony_ci            "%2 = OpFAdd %float %float_0 %3\n" +
4341fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4342fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4343fd4e5da5Sopenharmony_ci        2, 3),
4344fd4e5da5Sopenharmony_ci    // Test case 5: Fold n - 0.0
4345fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4346fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4347fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4348fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4349fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4350fd4e5da5Sopenharmony_ci            "%2 = OpFSub %float %3 %float_0\n" +
4351fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4352fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4353fd4e5da5Sopenharmony_ci        2, 3),
4354fd4e5da5Sopenharmony_ci    // Test case 6: Fold n * 1.0
4355fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4356fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4357fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4358fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4359fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4360fd4e5da5Sopenharmony_ci            "%2 = OpFMul %float %3 %float_1\n" +
4361fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4362fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4363fd4e5da5Sopenharmony_ci        2, 3),
4364fd4e5da5Sopenharmony_ci    // Test case 7: Fold 1.0 * n
4365fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4366fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4367fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4368fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4369fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4370fd4e5da5Sopenharmony_ci            "%2 = OpFMul %float %float_1 %3\n" +
4371fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4372fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4373fd4e5da5Sopenharmony_ci        2, 3),
4374fd4e5da5Sopenharmony_ci    // Test case 8: Fold n / 1.0
4375fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4376fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4377fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4378fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4379fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4380fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %float %3 %float_1\n" +
4381fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4382fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4383fd4e5da5Sopenharmony_ci        2, 3),
4384fd4e5da5Sopenharmony_ci    // Test case 9: Fold n * 0.0
4385fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4386fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4387fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4388fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4389fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4390fd4e5da5Sopenharmony_ci            "%2 = OpFMul %float %3 %104\n" +
4391fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4392fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4393fd4e5da5Sopenharmony_ci        2, FLOAT_0_ID),
4394fd4e5da5Sopenharmony_ci    // Test case 10: Fold 0.0 * n
4395fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4396fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4397fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4398fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4399fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4400fd4e5da5Sopenharmony_ci            "%2 = OpFMul %float %104 %3\n" +
4401fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4402fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4403fd4e5da5Sopenharmony_ci        2, FLOAT_0_ID),
4404fd4e5da5Sopenharmony_ci    // Test case 11: Fold 0.0 / n
4405fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4406fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4407fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4408fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4409fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
4410fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %float %104 %3\n" +
4411fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4412fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4413fd4e5da5Sopenharmony_ci        2, FLOAT_0_ID),
4414fd4e5da5Sopenharmony_ci    // Test case 12: Don't fold mix(a, b, 2.0)
4415fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4416fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4417fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4418fd4e5da5Sopenharmony_ci            "%a = OpVariable %_ptr_float Function\n" +
4419fd4e5da5Sopenharmony_ci            "%b = OpVariable %_ptr_float Function\n" +
4420fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %a\n" +
4421fd4e5da5Sopenharmony_ci            "%4 = OpLoad %float %b\n" +
4422fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FMix %3 %4 %float_2\n" +
4423fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4424fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4425fd4e5da5Sopenharmony_ci        2, 0),
4426fd4e5da5Sopenharmony_ci    // Test case 13: Fold mix(a, b, 0.0)
4427fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4428fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4429fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4430fd4e5da5Sopenharmony_ci            "%a = OpVariable %_ptr_float Function\n" +
4431fd4e5da5Sopenharmony_ci            "%b = OpVariable %_ptr_float Function\n" +
4432fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %a\n" +
4433fd4e5da5Sopenharmony_ci            "%4 = OpLoad %float %b\n" +
4434fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FMix %3 %4 %float_0\n" +
4435fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4436fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4437fd4e5da5Sopenharmony_ci        2, 3),
4438fd4e5da5Sopenharmony_ci    // Test case 14: Fold mix(a, b, 1.0)
4439fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4440fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4441fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4442fd4e5da5Sopenharmony_ci            "%a = OpVariable %_ptr_float Function\n" +
4443fd4e5da5Sopenharmony_ci            "%b = OpVariable %_ptr_float Function\n" +
4444fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %a\n" +
4445fd4e5da5Sopenharmony_ci            "%4 = OpLoad %float %b\n" +
4446fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %float %1 FMix %3 %4 %float_1\n" +
4447fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4448fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4449fd4e5da5Sopenharmony_ci        2, 4),
4450fd4e5da5Sopenharmony_ci    // Test case 15: Fold vector fadd with null
4451fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4452fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4453fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4454fd4e5da5Sopenharmony_ci            "%a = OpVariable %_ptr_v2float Function\n" +
4455fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v2float %a\n" +
4456fd4e5da5Sopenharmony_ci            "%3 = OpFAdd %v2float %2 %v2float_null\n" +
4457fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4458fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4459fd4e5da5Sopenharmony_ci        3, 2),
4460fd4e5da5Sopenharmony_ci    // Test case 16: Fold vector fadd with null
4461fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4462fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4463fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4464fd4e5da5Sopenharmony_ci            "%a = OpVariable %_ptr_v2float Function\n" +
4465fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v2float %a\n" +
4466fd4e5da5Sopenharmony_ci            "%3 = OpFAdd %v2float %v2float_null %2\n" +
4467fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4468fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4469fd4e5da5Sopenharmony_ci        3, 2),
4470fd4e5da5Sopenharmony_ci    // Test case 17: Fold vector fsub with null
4471fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4472fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4473fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4474fd4e5da5Sopenharmony_ci            "%a = OpVariable %_ptr_v2float Function\n" +
4475fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v2float %a\n" +
4476fd4e5da5Sopenharmony_ci            "%3 = OpFSub %v2float %2 %v2float_null\n" +
4477fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4478fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4479fd4e5da5Sopenharmony_ci        3, 2),
4480fd4e5da5Sopenharmony_ci    // Test case 18: Fold 0.0(half) * n
4481fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4482fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4483fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4484fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_half Function\n" +
4485fd4e5da5Sopenharmony_ci            "%3 = OpLoad %half %n\n" +
4486fd4e5da5Sopenharmony_ci            "%2 = OpFMul %half %108 %3\n" +
4487fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4488fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4489fd4e5da5Sopenharmony_ci        2, HALF_0_ID),
4490fd4e5da5Sopenharmony_ci    // Test case 19: Don't fold 1.0(half) * n
4491fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4492fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4493fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4494fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_half Function\n" +
4495fd4e5da5Sopenharmony_ci            "%3 = OpLoad %half %n\n" +
4496fd4e5da5Sopenharmony_ci            "%2 = OpFMul %half %half_1 %3\n" +
4497fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4498fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4499fd4e5da5Sopenharmony_ci        2, 0),
4500fd4e5da5Sopenharmony_ci    // Test case 20: Don't fold 1.0 * 1.0 (half)
4501fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4502fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4503fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4504fd4e5da5Sopenharmony_ci            "%2 = OpFMul %half %half_1 %half_1\n" +
4505fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4506fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4507fd4e5da5Sopenharmony_ci        2, 0),
4508fd4e5da5Sopenharmony_ci    // Test case 21: Don't fold (0.0, 1.0) * (0.0, 1.0) (half)
4509fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4510fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4511fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4512fd4e5da5Sopenharmony_ci            "%2 = OpFMul %v2half %half_0_1 %half_0_1\n" +
4513fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4514fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4515fd4e5da5Sopenharmony_ci        2, 0),
4516fd4e5da5Sopenharmony_ci    // Test case 22: Don't fold (0.0, 1.0) dotp (0.0, 1.0) (half)
4517fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4518fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4519fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4520fd4e5da5Sopenharmony_ci            "%2 = OpDot %half %half_0_1 %half_0_1\n" +
4521fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4522fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4523fd4e5da5Sopenharmony_ci        2, 0),
4524fd4e5da5Sopenharmony_ci    // Test case 23: Don't fold 1.0(half) / 2.0(half)
4525fd4e5da5Sopenharmony_ci    // We do not have to code to emulate 16-bit float operations. Just make sure we do not crash.
4526fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4527fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4528fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4529fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_half Function\n" +
4530fd4e5da5Sopenharmony_ci            "%3 = OpLoad %half %n\n" +
4531fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %half %half_1 %half_2\n" +
4532fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4533fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4534fd4e5da5Sopenharmony_ci        2, 0)
4535fd4e5da5Sopenharmony_ci));
4536fd4e5da5Sopenharmony_ci
4537fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(DoubleRedundantFoldingTest, GeneralInstructionFoldingTest,
4538fd4e5da5Sopenharmony_ci                        ::testing::Values(
4539fd4e5da5Sopenharmony_ci    // Test case 0: Don't fold n + 1.0
4540fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4541fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4542fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4543fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4544fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4545fd4e5da5Sopenharmony_ci            "%2 = OpFAdd %double %3 %double_2\n" +
4546fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4547fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4548fd4e5da5Sopenharmony_ci        2, 0),
4549fd4e5da5Sopenharmony_ci    // Test case 1: Don't fold n - 1.0
4550fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4551fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4552fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4553fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4554fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4555fd4e5da5Sopenharmony_ci            "%2 = OpFSub %double %3 %double_2\n" +
4556fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4557fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4558fd4e5da5Sopenharmony_ci        2, 0),
4559fd4e5da5Sopenharmony_ci    // Test case 2: Don't fold n * 2.0
4560fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4561fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4562fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4563fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4564fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4565fd4e5da5Sopenharmony_ci            "%2 = OpFMul %double %3 %double_2\n" +
4566fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4567fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4568fd4e5da5Sopenharmony_ci        2, 0),
4569fd4e5da5Sopenharmony_ci    // Test case 3: Fold n + 0.0
4570fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4571fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4572fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4573fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4574fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4575fd4e5da5Sopenharmony_ci            "%2 = OpFAdd %double %3 %double_0\n" +
4576fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4577fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4578fd4e5da5Sopenharmony_ci        2, 3),
4579fd4e5da5Sopenharmony_ci    // Test case 4: Fold 0.0 + n
4580fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4581fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4582fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4583fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4584fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4585fd4e5da5Sopenharmony_ci            "%2 = OpFAdd %double %double_0 %3\n" +
4586fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4587fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4588fd4e5da5Sopenharmony_ci        2, 3),
4589fd4e5da5Sopenharmony_ci    // Test case 5: Fold n - 0.0
4590fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4591fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4592fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4593fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4594fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4595fd4e5da5Sopenharmony_ci            "%2 = OpFSub %double %3 %double_0\n" +
4596fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4597fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4598fd4e5da5Sopenharmony_ci        2, 3),
4599fd4e5da5Sopenharmony_ci    // Test case 6: Fold n * 1.0
4600fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4601fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4602fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4603fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4604fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4605fd4e5da5Sopenharmony_ci            "%2 = OpFMul %double %3 %double_1\n" +
4606fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4607fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4608fd4e5da5Sopenharmony_ci        2, 3),
4609fd4e5da5Sopenharmony_ci    // Test case 7: Fold 1.0 * n
4610fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4611fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4612fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4613fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4614fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4615fd4e5da5Sopenharmony_ci            "%2 = OpFMul %double %double_1 %3\n" +
4616fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4617fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4618fd4e5da5Sopenharmony_ci        2, 3),
4619fd4e5da5Sopenharmony_ci    // Test case 8: Fold n / 1.0
4620fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4621fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4622fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4623fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4624fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4625fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %double %3 %double_1\n" +
4626fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4627fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4628fd4e5da5Sopenharmony_ci        2, 3),
4629fd4e5da5Sopenharmony_ci    // Test case 9: Fold n * 0.0
4630fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4631fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4632fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4633fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4634fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4635fd4e5da5Sopenharmony_ci            "%2 = OpFMul %double %3 %105\n" +
4636fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4637fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4638fd4e5da5Sopenharmony_ci        2, DOUBLE_0_ID),
4639fd4e5da5Sopenharmony_ci    // Test case 10: Fold 0.0 * n
4640fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4641fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4642fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4643fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4644fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4645fd4e5da5Sopenharmony_ci            "%2 = OpFMul %double %105 %3\n" +
4646fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4647fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4648fd4e5da5Sopenharmony_ci        2, DOUBLE_0_ID),
4649fd4e5da5Sopenharmony_ci    // Test case 11: Fold 0.0 / n
4650fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4651fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4652fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4653fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
4654fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
4655fd4e5da5Sopenharmony_ci            "%2 = OpFDiv %double %105 %3\n" +
4656fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4657fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4658fd4e5da5Sopenharmony_ci        2, DOUBLE_0_ID),
4659fd4e5da5Sopenharmony_ci    // Test case 12: Don't fold mix(a, b, 2.0)
4660fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4661fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4662fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4663fd4e5da5Sopenharmony_ci            "%a = OpVariable %_ptr_double Function\n" +
4664fd4e5da5Sopenharmony_ci            "%b = OpVariable %_ptr_double Function\n" +
4665fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %a\n" +
4666fd4e5da5Sopenharmony_ci            "%4 = OpLoad %double %b\n" +
4667fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %double %1 FMix %3 %4 %double_2\n" +
4668fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4669fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4670fd4e5da5Sopenharmony_ci        2, 0),
4671fd4e5da5Sopenharmony_ci    // Test case 13: Fold mix(a, b, 0.0)
4672fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4673fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4674fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4675fd4e5da5Sopenharmony_ci            "%a = OpVariable %_ptr_double Function\n" +
4676fd4e5da5Sopenharmony_ci            "%b = OpVariable %_ptr_double Function\n" +
4677fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %a\n" +
4678fd4e5da5Sopenharmony_ci            "%4 = OpLoad %double %b\n" +
4679fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %double %1 FMix %3 %4 %double_0\n" +
4680fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4681fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4682fd4e5da5Sopenharmony_ci        2, 3),
4683fd4e5da5Sopenharmony_ci    // Test case 14: Fold mix(a, b, 1.0)
4684fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4685fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4686fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4687fd4e5da5Sopenharmony_ci            "%a = OpVariable %_ptr_double Function\n" +
4688fd4e5da5Sopenharmony_ci            "%b = OpVariable %_ptr_double Function\n" +
4689fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %a\n" +
4690fd4e5da5Sopenharmony_ci            "%4 = OpLoad %double %b\n" +
4691fd4e5da5Sopenharmony_ci            "%2 = OpExtInst %double %1 FMix %3 %4 %double_1\n" +
4692fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4693fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4694fd4e5da5Sopenharmony_ci        2, 4)
4695fd4e5da5Sopenharmony_ci));
4696fd4e5da5Sopenharmony_ci
4697fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FloatVectorRedundantFoldingTest, GeneralInstructionFoldingTest,
4698fd4e5da5Sopenharmony_ci                        ::testing::Values(
4699fd4e5da5Sopenharmony_ci    // Test case 0: Don't fold a * vec4(0.0, 0.0, 0.0, 1.0)
4700fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4701fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4702fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4703fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4float Function\n" +
4704fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4float %n\n" +
4705fd4e5da5Sopenharmony_ci            "%2 = OpFMul %v4float %3 %v4float_0_0_0_1\n" +
4706fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4707fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4708fd4e5da5Sopenharmony_ci        2, 0),
4709fd4e5da5Sopenharmony_ci    // Test case 1: Fold a * vec4(0.0, 0.0, 0.0, 0.0)
4710fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4711fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4712fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4713fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4float Function\n" +
4714fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4float %n\n" +
4715fd4e5da5Sopenharmony_ci            "%2 = OpFMul %v4float %3 %106\n" +
4716fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4717fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4718fd4e5da5Sopenharmony_ci        2, VEC4_0_ID),
4719fd4e5da5Sopenharmony_ci    // Test case 2: Fold a * vec4(1.0, 1.0, 1.0, 1.0)
4720fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4721fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4722fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4723fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4float Function\n" +
4724fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4float %n\n" +
4725fd4e5da5Sopenharmony_ci            "%2 = OpFMul %v4float %3 %v4float_1_1_1_1\n" +
4726fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4727fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4728fd4e5da5Sopenharmony_ci        2, 3)
4729fd4e5da5Sopenharmony_ci));
4730fd4e5da5Sopenharmony_ci
4731fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(DoubleVectorRedundantFoldingTest, GeneralInstructionFoldingTest,
4732fd4e5da5Sopenharmony_ci                        ::testing::Values(
4733fd4e5da5Sopenharmony_ci    // Test case 0: Don't fold a * vec4(0.0, 0.0, 0.0, 1.0)
4734fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4735fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4736fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4737fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
4738fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4double %n\n" +
4739fd4e5da5Sopenharmony_ci            "%2 = OpFMul %v4double %3 %v4double_0_0_0_1\n" +
4740fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4741fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4742fd4e5da5Sopenharmony_ci        2, 0),
4743fd4e5da5Sopenharmony_ci    // Test case 1: Fold a * vec4(0.0, 0.0, 0.0, 0.0)
4744fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4745fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4746fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4747fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
4748fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4double %n\n" +
4749fd4e5da5Sopenharmony_ci            "%2 = OpFMul %v4double %3 %106\n" +
4750fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4751fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4752fd4e5da5Sopenharmony_ci        2, DVEC4_0_ID),
4753fd4e5da5Sopenharmony_ci    // Test case 2: Fold a * vec4(1.0, 1.0, 1.0, 1.0)
4754fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4755fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4756fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4757fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
4758fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4double %n\n" +
4759fd4e5da5Sopenharmony_ci            "%2 = OpFMul %v4double %3 %v4double_1_1_1_1\n" +
4760fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4761fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4762fd4e5da5Sopenharmony_ci        2, 3)
4763fd4e5da5Sopenharmony_ci));
4764fd4e5da5Sopenharmony_ci
4765fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(IntegerRedundantFoldingTest, GeneralInstructionFoldingTest,
4766fd4e5da5Sopenharmony_ci                        ::testing::Values(
4767fd4e5da5Sopenharmony_ci    // Test case 0: Don't fold n + 1
4768fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4769fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4770fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4771fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
4772fd4e5da5Sopenharmony_ci            "%3 = OpLoad %uint %n\n" +
4773fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %uint %3 %uint_1\n" +
4774fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4775fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4776fd4e5da5Sopenharmony_ci        2, 0),
4777fd4e5da5Sopenharmony_ci    // Test case 1: Don't fold 1 + n
4778fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4779fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4780fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4781fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
4782fd4e5da5Sopenharmony_ci            "%3 = OpLoad %uint %n\n" +
4783fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %uint %uint_1 %3\n" +
4784fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4785fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4786fd4e5da5Sopenharmony_ci        2, 0),
4787fd4e5da5Sopenharmony_ci    // Test case 2: Fold n + 0
4788fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4789fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4790fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4791fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
4792fd4e5da5Sopenharmony_ci            "%3 = OpLoad %uint %n\n" +
4793fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %uint %3 %uint_0\n" +
4794fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4795fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4796fd4e5da5Sopenharmony_ci        2, 3),
4797fd4e5da5Sopenharmony_ci    // Test case 3: Fold 0 + n
4798fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4799fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4800fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4801fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_uint Function\n" +
4802fd4e5da5Sopenharmony_ci            "%3 = OpLoad %uint %n\n" +
4803fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %uint %uint_0 %3\n" +
4804fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4805fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4806fd4e5da5Sopenharmony_ci        2, 3),
4807fd4e5da5Sopenharmony_ci    // Test case 4: Don't fold n + (1,0)
4808fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4809fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4810fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4811fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v2int Function\n" +
4812fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v2int %n\n" +
4813fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %v2int %3 %v2int_1_0\n" +
4814fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4815fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4816fd4e5da5Sopenharmony_ci        2, 0),
4817fd4e5da5Sopenharmony_ci    // Test case 5: Don't fold (1,0) + n
4818fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4819fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4820fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4821fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v2int Function\n" +
4822fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v2int %n\n" +
4823fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %v2int %v2int_1_0 %3\n" +
4824fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4825fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4826fd4e5da5Sopenharmony_ci        2, 0),
4827fd4e5da5Sopenharmony_ci    // Test case 6: Fold n + (0,0)
4828fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4829fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4830fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4831fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v2int Function\n" +
4832fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v2int %n\n" +
4833fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %v2int %3 %v2int_0_0\n" +
4834fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4835fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4836fd4e5da5Sopenharmony_ci        2, 3),
4837fd4e5da5Sopenharmony_ci    // Test case 7: Fold (0,0) + n
4838fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4839fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4840fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4841fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v2int Function\n" +
4842fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v2int %n\n" +
4843fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %v2int %v2int_0_0 %3\n" +
4844fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4845fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4846fd4e5da5Sopenharmony_ci        2, 3)
4847fd4e5da5Sopenharmony_ci));
4848fd4e5da5Sopenharmony_ci
4849fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(ClampAndCmpLHS, GeneralInstructionFoldingTest,
4850fd4e5da5Sopenharmony_ci::testing::Values(
4851fd4e5da5Sopenharmony_ci    // Test case 0: Don't Fold 0.0 < clamp(-1, 1)
4852fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4853fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4854fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4855fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4856fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4857fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
4858fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThan %bool %float_0 %clamp\n" +
4859fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4860fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4861fd4e5da5Sopenharmony_ci        2, 0),
4862fd4e5da5Sopenharmony_ci    // Test case 1: Don't Fold 0.0 < clamp(-1, 1)
4863fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4864fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4865fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4866fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4867fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4868fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
4869fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThan %bool %float_0 %clamp\n" +
4870fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4871fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4872fd4e5da5Sopenharmony_ci        2, 0),
4873fd4e5da5Sopenharmony_ci    // Test case 2: Don't Fold 0.0 <= clamp(-1, 1)
4874fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4875fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4876fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4877fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4878fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4879fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
4880fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThanEqual %bool %float_0 %clamp\n" +
4881fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4882fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4883fd4e5da5Sopenharmony_ci        2, 0),
4884fd4e5da5Sopenharmony_ci    // Test case 3: Don't Fold 0.0 <= clamp(-1, 1)
4885fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4886fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4887fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4888fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4889fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4890fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
4891fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThanEqual %bool %float_0 %clamp\n" +
4892fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4893fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4894fd4e5da5Sopenharmony_ci        2, 0),
4895fd4e5da5Sopenharmony_ci    // Test case 4: Don't Fold 0.0 > clamp(-1, 1)
4896fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4897fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4898fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4899fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4900fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4901fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
4902fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThan %bool %float_0 %clamp\n" +
4903fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4904fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4905fd4e5da5Sopenharmony_ci        2, 0),
4906fd4e5da5Sopenharmony_ci    // Test case 5: Don't Fold 0.0 > clamp(-1, 1)
4907fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4908fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4909fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4910fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4911fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4912fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
4913fd4e5da5Sopenharmony_ci            "%2 = OpFOrdGreaterThan %bool %float_0 %clamp\n" +
4914fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4915fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4916fd4e5da5Sopenharmony_ci        2, 0),
4917fd4e5da5Sopenharmony_ci    // Test case 6: Don't Fold 0.0 >= clamp(-1, 1)
4918fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4919fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4920fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4921fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4922fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4923fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
4924fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThanEqual %bool %float_0 %clamp\n" +
4925fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4926fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4927fd4e5da5Sopenharmony_ci        2, 0),
4928fd4e5da5Sopenharmony_ci    // Test case 7: Don't Fold 0.0 >= clamp(-1, 1)
4929fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4930fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4931fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4932fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4933fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4934fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
4935fd4e5da5Sopenharmony_ci            "%2 = OpFOrdGreaterThanEqual %bool %float_0 %clamp\n" +
4936fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4937fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4938fd4e5da5Sopenharmony_ci        2, 0),
4939fd4e5da5Sopenharmony_ci    // Test case 8: Don't Fold 0.0 < clamp(0, 1)
4940fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4941fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4942fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4943fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4944fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4945fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_0 %float_1\n" +
4946fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThan %bool %float_0 %clamp\n" +
4947fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4948fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4949fd4e5da5Sopenharmony_ci        2, 0),
4950fd4e5da5Sopenharmony_ci    // Test case 9: Don't Fold 0.0 < clamp(0, 1)
4951fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4952fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4953fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4954fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4955fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4956fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_0 %float_1\n" +
4957fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThan %bool %float_0 %clamp\n" +
4958fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4959fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4960fd4e5da5Sopenharmony_ci        2, 0),
4961fd4e5da5Sopenharmony_ci    // Test case 10: Don't Fold 0.0 > clamp(-1, 0)
4962fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4963fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4964fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4965fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4966fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4967fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
4968fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThan %bool %float_0 %clamp\n" +
4969fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4970fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4971fd4e5da5Sopenharmony_ci        2, 0),
4972fd4e5da5Sopenharmony_ci    // Test case 11: Don't Fold 0.0 > clamp(-1, 0)
4973fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4974fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
4975fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
4976fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
4977fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
4978fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
4979fd4e5da5Sopenharmony_ci            "%2 = OpFOrdGreaterThan %bool %float_0 %clamp\n" +
4980fd4e5da5Sopenharmony_ci            "OpReturn\n" +
4981fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
4982fd4e5da5Sopenharmony_ci        2, 0)
4983fd4e5da5Sopenharmony_ci));
4984fd4e5da5Sopenharmony_ci
4985fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(ClampAndCmpRHS, GeneralInstructionFoldingTest,
4986fd4e5da5Sopenharmony_ci::testing::Values(
4987fd4e5da5Sopenharmony_ci    // Test case 0: Don't Fold clamp(-1, 1) < 0.0
4988fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
4989fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
4990fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
4991fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_float Function\n" +
4992fd4e5da5Sopenharmony_ci          "%ld = OpLoad %float %n\n" +
4993fd4e5da5Sopenharmony_ci          "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
4994fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThan %bool %clamp %float_0\n" +
4995fd4e5da5Sopenharmony_ci          "OpReturn\n" +
4996fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
4997fd4e5da5Sopenharmony_ci      2, 0),
4998fd4e5da5Sopenharmony_ci    // Test case 1: Don't Fold clamp(-1, 1) < 0.0
4999fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5000fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
5001fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
5002fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_float Function\n" +
5003fd4e5da5Sopenharmony_ci          "%ld = OpLoad %float %n\n" +
5004fd4e5da5Sopenharmony_ci          "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
5005fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThan %bool %clamp %float_0\n" +
5006fd4e5da5Sopenharmony_ci          "OpReturn\n" +
5007fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
5008fd4e5da5Sopenharmony_ci      2, 0),
5009fd4e5da5Sopenharmony_ci    // Test case 2: Don't Fold clamp(-1, 1) <= 0.0
5010fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5011fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
5012fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
5013fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_float Function\n" +
5014fd4e5da5Sopenharmony_ci          "%ld = OpLoad %float %n\n" +
5015fd4e5da5Sopenharmony_ci          "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
5016fd4e5da5Sopenharmony_ci          "%2 = OpFUnordLessThanEqual %bool %clamp %float_0\n" +
5017fd4e5da5Sopenharmony_ci          "OpReturn\n" +
5018fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
5019fd4e5da5Sopenharmony_ci      2, 0),
5020fd4e5da5Sopenharmony_ci    // Test case 3: Don't Fold clamp(-1, 1) <= 0.0
5021fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5022fd4e5da5Sopenharmony_ci      Header() + "%main = OpFunction %void None %void_func\n" +
5023fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
5024fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_float Function\n" +
5025fd4e5da5Sopenharmony_ci          "%ld = OpLoad %float %n\n" +
5026fd4e5da5Sopenharmony_ci          "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
5027fd4e5da5Sopenharmony_ci          "%2 = OpFOrdLessThanEqual %bool %clamp %float_0\n" +
5028fd4e5da5Sopenharmony_ci          "OpReturn\n" +
5029fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
5030fd4e5da5Sopenharmony_ci      2, 0),
5031fd4e5da5Sopenharmony_ci    // Test case 4: Don't Fold clamp(-1, 1) > 0.0
5032fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5033fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5034fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5035fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
5036fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
5037fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
5038fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThan %bool %clamp %float_0\n" +
5039fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5040fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5041fd4e5da5Sopenharmony_ci        2, 0),
5042fd4e5da5Sopenharmony_ci    // Test case 5: Don't Fold clamp(-1, 1) > 0.0
5043fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5044fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5045fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5046fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
5047fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
5048fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
5049fd4e5da5Sopenharmony_ci            "%2 = OpFOrdGreaterThan %bool %clamp %float_0\n" +
5050fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5051fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5052fd4e5da5Sopenharmony_ci        2, 0),
5053fd4e5da5Sopenharmony_ci    // Test case 6: Don't Fold clamp(-1, 1) >= 0.0
5054fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5055fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5056fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5057fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
5058fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
5059fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
5060fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThanEqual %bool %clamp %float_0\n" +
5061fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5062fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5063fd4e5da5Sopenharmony_ci        2, 0),
5064fd4e5da5Sopenharmony_ci    // Test case 7: Don't Fold clamp(-1, 1) >= 0.0
5065fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5066fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5067fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5068fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
5069fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
5070fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_1\n" +
5071fd4e5da5Sopenharmony_ci            "%2 = OpFOrdGreaterThanEqual %bool %clamp %float_0\n" +
5072fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5073fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5074fd4e5da5Sopenharmony_ci        2, 0),
5075fd4e5da5Sopenharmony_ci    // Test case 8: Don't Fold clamp(-1, 0) < 0.0
5076fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5077fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5078fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5079fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
5080fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
5081fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
5082fd4e5da5Sopenharmony_ci            "%2 = OpFUnordLessThan %bool %clamp %float_0\n" +
5083fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5084fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5085fd4e5da5Sopenharmony_ci        2, 0),
5086fd4e5da5Sopenharmony_ci    // Test case 9: Don't Fold clamp(0, 1) < 1
5087fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5088fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5089fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5090fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
5091fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
5092fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_0 %float_1\n" +
5093fd4e5da5Sopenharmony_ci            "%2 = OpFOrdLessThan %bool %clamp %float_1\n" +
5094fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5095fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5096fd4e5da5Sopenharmony_ci        2, 0),
5097fd4e5da5Sopenharmony_ci    // Test case 10: Don't Fold clamp(-1, 0) > -1
5098fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5099fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5100fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5101fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
5102fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
5103fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
5104fd4e5da5Sopenharmony_ci            "%2 = OpFUnordGreaterThan %bool %clamp %float_n1\n" +
5105fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5106fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5107fd4e5da5Sopenharmony_ci        2, 0),
5108fd4e5da5Sopenharmony_ci    // Test case 11: Don't Fold clamp(-1, 0) > -1
5109fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5110fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5111fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5112fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
5113fd4e5da5Sopenharmony_ci            "%ld = OpLoad %float %n\n" +
5114fd4e5da5Sopenharmony_ci            "%clamp = OpExtInst %float %1 FClamp %ld %float_n1 %float_0\n" +
5115fd4e5da5Sopenharmony_ci            "%2 = OpFOrdGreaterThan %bool %clamp %float_n1\n" +
5116fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5117fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5118fd4e5da5Sopenharmony_ci        2, 0)
5119fd4e5da5Sopenharmony_ci));
5120fd4e5da5Sopenharmony_ci
5121fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FToIConstantFoldingTest, IntegerInstructionFoldingTest,
5122fd4e5da5Sopenharmony_ci                        ::testing::Values(
5123fd4e5da5Sopenharmony_ci    // Test case 0: Fold int(3.0)
5124fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5125fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5126fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5127fd4e5da5Sopenharmony_ci            "%2 = OpConvertFToS %int %float_3\n" +
5128fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5129fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5130fd4e5da5Sopenharmony_ci        2, 3),
5131fd4e5da5Sopenharmony_ci    // Test case 1: Fold uint(3.0)
5132fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5133fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5134fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5135fd4e5da5Sopenharmony_ci            "%2 = OpConvertFToU %int %float_3\n" +
5136fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5137fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5138fd4e5da5Sopenharmony_ci        2, 3)
5139fd4e5da5Sopenharmony_ci));
5140fd4e5da5Sopenharmony_ci
5141fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(IToFConstantFoldingTest, FloatInstructionFoldingTest,
5142fd4e5da5Sopenharmony_ci                        ::testing::Values(
5143fd4e5da5Sopenharmony_ci    // Test case 0: Fold float(3)
5144fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
5145fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5146fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5147fd4e5da5Sopenharmony_ci            "%2 = OpConvertSToF %float %int_3\n" +
5148fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5149fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5150fd4e5da5Sopenharmony_ci        2, 3.0),
5151fd4e5da5Sopenharmony_ci    // Test case 1: Fold float(3u)
5152fd4e5da5Sopenharmony_ci    InstructionFoldingCase<float>(
5153fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5154fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5155fd4e5da5Sopenharmony_ci            "%2 = OpConvertUToF %float %uint_3\n" +
5156fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5157fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5158fd4e5da5Sopenharmony_ci        2, 3.0)
5159fd4e5da5Sopenharmony_ci));
5160fd4e5da5Sopenharmony_ci// clang-format on
5161fd4e5da5Sopenharmony_ci
5162fd4e5da5Sopenharmony_ciusing ToNegateFoldingTest =
5163fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCase<uint32_t>>;
5164fd4e5da5Sopenharmony_ci
5165fd4e5da5Sopenharmony_ciTEST_P(ToNegateFoldingTest, Case) {
5166fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
5167fd4e5da5Sopenharmony_ci
5168fd4e5da5Sopenharmony_ci  // Build module.
5169fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
5170fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
5171fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5172fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
5173fd4e5da5Sopenharmony_ci
5174fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
5175fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
5176fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
5177fd4e5da5Sopenharmony_ci  std::unique_ptr<Instruction> original_inst(inst->Clone(context.get()));
5178fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
5179fd4e5da5Sopenharmony_ci
5180fd4e5da5Sopenharmony_ci  // Make sure the instruction folded as expected.
5181fd4e5da5Sopenharmony_ci  EXPECT_EQ(inst->result_id(), original_inst->result_id());
5182fd4e5da5Sopenharmony_ci  EXPECT_EQ(inst->type_id(), original_inst->type_id());
5183fd4e5da5Sopenharmony_ci  EXPECT_TRUE((!succeeded) == (tc.expected_result == 0));
5184fd4e5da5Sopenharmony_ci  if (succeeded) {
5185fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->opcode(), spv::Op::OpFNegate);
5186fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->GetSingleWordInOperand(0), tc.expected_result);
5187fd4e5da5Sopenharmony_ci  } else {
5188fd4e5da5Sopenharmony_ci    EXPECT_EQ(inst->NumInOperands(), original_inst->NumInOperands());
5189fd4e5da5Sopenharmony_ci    for (uint32_t i = 0; i < inst->NumInOperands(); ++i) {
5190fd4e5da5Sopenharmony_ci      EXPECT_EQ(inst->GetOperand(i), original_inst->GetOperand(i));
5191fd4e5da5Sopenharmony_ci    }
5192fd4e5da5Sopenharmony_ci  }
5193fd4e5da5Sopenharmony_ci}
5194fd4e5da5Sopenharmony_ci
5195fd4e5da5Sopenharmony_ci// clang-format off
5196fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FloatRedundantSubFoldingTest, ToNegateFoldingTest,
5197fd4e5da5Sopenharmony_ci                        ::testing::Values(
5198fd4e5da5Sopenharmony_ci    // Test case 0: Don't fold 1.0 - n
5199fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5200fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5201fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5202fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
5203fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
5204fd4e5da5Sopenharmony_ci            "%2 = OpFSub %float %float_1 %3\n" +
5205fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5206fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5207fd4e5da5Sopenharmony_ci        2, 0),
5208fd4e5da5Sopenharmony_ci    // Test case 1: Fold 0.0 - n
5209fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5210fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5211fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5212fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_float Function\n" +
5213fd4e5da5Sopenharmony_ci            "%3 = OpLoad %float %n\n" +
5214fd4e5da5Sopenharmony_ci            "%2 = OpFSub %float %float_0 %3\n" +
5215fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5216fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5217fd4e5da5Sopenharmony_ci        2, 3),
5218fd4e5da5Sopenharmony_ci	// Test case 2: Don't fold (0,0,0,1) - n
5219fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5220fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5221fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5222fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4float Function\n" +
5223fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4float %n\n" +
5224fd4e5da5Sopenharmony_ci            "%2 = OpFSub %v4float %v4float_0_0_0_1 %3\n" +
5225fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5226fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5227fd4e5da5Sopenharmony_ci        2, 0),
5228fd4e5da5Sopenharmony_ci	// Test case 3: Fold (0,0,0,0) - n
5229fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5230fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5231fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5232fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4float Function\n" +
5233fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4float %n\n" +
5234fd4e5da5Sopenharmony_ci            "%2 = OpFSub %v4float %v4float_0_0_0_0 %3\n" +
5235fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5236fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5237fd4e5da5Sopenharmony_ci        2, 3)
5238fd4e5da5Sopenharmony_ci));
5239fd4e5da5Sopenharmony_ci
5240fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(DoubleRedundantSubFoldingTest, ToNegateFoldingTest,
5241fd4e5da5Sopenharmony_ci                        ::testing::Values(
5242fd4e5da5Sopenharmony_ci    // Test case 0: Don't fold 1.0 - n
5243fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5244fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5245fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5246fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
5247fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
5248fd4e5da5Sopenharmony_ci            "%2 = OpFSub %double %double_1 %3\n" +
5249fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5250fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5251fd4e5da5Sopenharmony_ci        2, 0),
5252fd4e5da5Sopenharmony_ci    // Test case 1: Fold 0.0 - n
5253fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5254fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5255fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5256fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_double Function\n" +
5257fd4e5da5Sopenharmony_ci            "%3 = OpLoad %double %n\n" +
5258fd4e5da5Sopenharmony_ci            "%2 = OpFSub %double %double_0 %3\n" +
5259fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5260fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5261fd4e5da5Sopenharmony_ci        2, 3),
5262fd4e5da5Sopenharmony_ci	// Test case 2: Don't fold (0,0,0,1) - n
5263fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5264fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5265fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5266fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
5267fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4double %n\n" +
5268fd4e5da5Sopenharmony_ci            "%2 = OpFSub %v4double %v4double_0_0_0_1 %3\n" +
5269fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5270fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5271fd4e5da5Sopenharmony_ci        2, 0),
5272fd4e5da5Sopenharmony_ci	// Test case 3: Fold (0,0,0,0) - n
5273fd4e5da5Sopenharmony_ci    InstructionFoldingCase<uint32_t>(
5274fd4e5da5Sopenharmony_ci        Header() + "%main = OpFunction %void None %void_func\n" +
5275fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5276fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
5277fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4double %n\n" +
5278fd4e5da5Sopenharmony_ci            "%2 = OpFSub %v4double %v4double_0_0_0_0 %3\n" +
5279fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5280fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5281fd4e5da5Sopenharmony_ci        2, 3)
5282fd4e5da5Sopenharmony_ci));
5283fd4e5da5Sopenharmony_ci
5284fd4e5da5Sopenharmony_ciusing MatchingInstructionFoldingTest =
5285fd4e5da5Sopenharmony_ci    ::testing::TestWithParam<InstructionFoldingCase<bool>>;
5286fd4e5da5Sopenharmony_ci
5287fd4e5da5Sopenharmony_ciTEST_P(MatchingInstructionFoldingTest, Case) {
5288fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
5289fd4e5da5Sopenharmony_ci
5290fd4e5da5Sopenharmony_ci  // Build module.
5291fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
5292fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
5293fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
5294fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
5295fd4e5da5Sopenharmony_ci
5296fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
5297fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
5298fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
5299fd4e5da5Sopenharmony_ci  std::unique_ptr<Instruction> original_inst(inst->Clone(context.get()));
5300fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
5301fd4e5da5Sopenharmony_ci  EXPECT_EQ(succeeded, tc.expected_result);
5302fd4e5da5Sopenharmony_ci  if (succeeded) {
5303fd4e5da5Sopenharmony_ci    Match(tc.test_body, context.get());
5304fd4e5da5Sopenharmony_ci  }
5305fd4e5da5Sopenharmony_ci}
5306fd4e5da5Sopenharmony_ci
5307fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(RedundantIntegerMatching, MatchingInstructionFoldingTest,
5308fd4e5da5Sopenharmony_ci::testing::Values(
5309fd4e5da5Sopenharmony_ci    // Test case 0: Fold 0 + n (change sign)
5310fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
5311fd4e5da5Sopenharmony_ci        Header() +
5312fd4e5da5Sopenharmony_ci            "; CHECK: [[uint:%\\w+]] = OpTypeInt 32 0\n" +
5313fd4e5da5Sopenharmony_ci            "; CHECK: %2 = OpBitcast [[uint]] %3\n" +
5314fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
5315fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5316fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
5317fd4e5da5Sopenharmony_ci            "%3 = OpLoad %uint %n\n" +
5318fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %uint %int_0 %3\n" +
5319fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5320fd4e5da5Sopenharmony_ci            "OpFunctionEnd\n",
5321fd4e5da5Sopenharmony_ci        2, true),
5322fd4e5da5Sopenharmony_ci    // Test case 0: Fold 0 + n (change sign)
5323fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
5324fd4e5da5Sopenharmony_ci        Header() +
5325fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
5326fd4e5da5Sopenharmony_ci            "; CHECK: %2 = OpBitcast [[int]] %3\n" +
5327fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
5328fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5329fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
5330fd4e5da5Sopenharmony_ci            "%3 = OpLoad %int %n\n" +
5331fd4e5da5Sopenharmony_ci            "%2 = OpIAdd %int %uint_0 %3\n" +
5332fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5333fd4e5da5Sopenharmony_ci            "OpFunctionEnd\n",
5334fd4e5da5Sopenharmony_ci        2, true)
5335fd4e5da5Sopenharmony_ci));
5336fd4e5da5Sopenharmony_ci
5337fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(MergeNegateTest, MatchingInstructionFoldingTest,
5338fd4e5da5Sopenharmony_ci::testing::Values(
5339fd4e5da5Sopenharmony_ci  // Test case 0: fold consecutive fnegate
5340fd4e5da5Sopenharmony_ci  // -(-x) = x
5341fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5342fd4e5da5Sopenharmony_ci    Header() +
5343fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float:%\\w+]]\n" +
5344fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpCopyObject [[float]] [[ld]]\n" +
5345fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5346fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5347fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5348fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5349fd4e5da5Sopenharmony_ci      "%3 = OpFNegate %float %2\n" +
5350fd4e5da5Sopenharmony_ci      "%4 = OpFNegate %float %3\n" +
5351fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5352fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5353fd4e5da5Sopenharmony_ci    4, true),
5354fd4e5da5Sopenharmony_ci  // Test case 1: fold fnegate(fmul with const).
5355fd4e5da5Sopenharmony_ci  // -(x * 2.0) = x * -2.0
5356fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5357fd4e5da5Sopenharmony_ci    Header() +
5358fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5359fd4e5da5Sopenharmony_ci      "; CHECK: [[float_n2:%\\w+]] = OpConstant [[float]] -2{{[[:space:]]}}\n" +
5360fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5361fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFMul [[float]] [[ld]] [[float_n2]]\n" +
5362fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5363fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5364fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5365fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5366fd4e5da5Sopenharmony_ci      "%3 = OpFMul %float %2 %float_2\n" +
5367fd4e5da5Sopenharmony_ci      "%4 = OpFNegate %float %3\n" +
5368fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5369fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5370fd4e5da5Sopenharmony_ci    4, true),
5371fd4e5da5Sopenharmony_ci  // Test case 2: fold fnegate(fmul with const).
5372fd4e5da5Sopenharmony_ci  // -(2.0 * x) = x * 2.0
5373fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5374fd4e5da5Sopenharmony_ci    Header() +
5375fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5376fd4e5da5Sopenharmony_ci      "; CHECK: [[float_n2:%\\w+]] = OpConstant [[float]] -2{{[[:space:]]}}\n" +
5377fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5378fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFMul [[float]] [[ld]] [[float_n2]]\n" +
5379fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5380fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5381fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5382fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5383fd4e5da5Sopenharmony_ci      "%3 = OpFMul %float %float_2 %2\n" +
5384fd4e5da5Sopenharmony_ci      "%4 = OpFNegate %float %3\n" +
5385fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5386fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5387fd4e5da5Sopenharmony_ci    4, true),
5388fd4e5da5Sopenharmony_ci  // Test case 3: fold fnegate(fdiv with const).
5389fd4e5da5Sopenharmony_ci  // -(x / 2.0) = x * -0.5
5390fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5391fd4e5da5Sopenharmony_ci    Header() +
5392fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5393fd4e5da5Sopenharmony_ci      "; CHECK: [[float_n0p5:%\\w+]] = OpConstant [[float]] -0.5\n" +
5394fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5395fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFMul [[float]] [[ld]] [[float_n0p5]]\n" +
5396fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5397fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5398fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5399fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5400fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %float %2 %float_2\n" +
5401fd4e5da5Sopenharmony_ci      "%4 = OpFNegate %float %3\n" +
5402fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5403fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5404fd4e5da5Sopenharmony_ci    4, true),
5405fd4e5da5Sopenharmony_ci  // Test case 4: fold fnegate(fdiv with const).
5406fd4e5da5Sopenharmony_ci  // -(2.0 / x) = -2.0 / x
5407fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5408fd4e5da5Sopenharmony_ci    Header() +
5409fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5410fd4e5da5Sopenharmony_ci      "; CHECK: [[float_n2:%\\w+]] = OpConstant [[float]] -2{{[[:space:]]}}\n" +
5411fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5412fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFDiv [[float]] [[float_n2]] [[ld]]\n" +
5413fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5414fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5415fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5416fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5417fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %float %float_2 %2\n" +
5418fd4e5da5Sopenharmony_ci      "%4 = OpFNegate %float %3\n" +
5419fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5420fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5421fd4e5da5Sopenharmony_ci    4, true),
5422fd4e5da5Sopenharmony_ci  // Test case 5: fold fnegate(fadd with const).
5423fd4e5da5Sopenharmony_ci  // -(2.0 + x) = -2.0 - x
5424fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5425fd4e5da5Sopenharmony_ci    Header() +
5426fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5427fd4e5da5Sopenharmony_ci      "; CHECK: [[float_n2:%\\w+]] = OpConstant [[float]] -2{{[[:space:]]}}\n" +
5428fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5429fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_n2]] [[ld]]\n" +
5430fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5431fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5432fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5433fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5434fd4e5da5Sopenharmony_ci      "%3 = OpFAdd %float %float_2 %2\n" +
5435fd4e5da5Sopenharmony_ci      "%4 = OpFNegate %float %3\n" +
5436fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5437fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5438fd4e5da5Sopenharmony_ci    4, true),
5439fd4e5da5Sopenharmony_ci  // Test case 6: fold fnegate(fadd with const).
5440fd4e5da5Sopenharmony_ci  // -(x + 2.0) = -2.0 - x
5441fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5442fd4e5da5Sopenharmony_ci    Header() +
5443fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5444fd4e5da5Sopenharmony_ci      "; CHECK: [[float_n2:%\\w+]] = OpConstant [[float]] -2{{[[:space:]]}}\n" +
5445fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5446fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_n2]] [[ld]]\n" +
5447fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5448fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5449fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5450fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5451fd4e5da5Sopenharmony_ci      "%3 = OpFAdd %float %2 %float_2\n" +
5452fd4e5da5Sopenharmony_ci      "%4 = OpFNegate %float %3\n" +
5453fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5454fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5455fd4e5da5Sopenharmony_ci    4, true),
5456fd4e5da5Sopenharmony_ci  // Test case 7: fold fnegate(fsub with const).
5457fd4e5da5Sopenharmony_ci  // -(2.0 - x) = x - 2.0
5458fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5459fd4e5da5Sopenharmony_ci    Header() +
5460fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5461fd4e5da5Sopenharmony_ci      "; CHECK: [[float_2:%\\w+]] = OpConstant [[float]] 2\n" +
5462fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5463fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[ld]] [[float_2]]\n" +
5464fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5465fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5466fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5467fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5468fd4e5da5Sopenharmony_ci      "%3 = OpFSub %float %float_2 %2\n" +
5469fd4e5da5Sopenharmony_ci      "%4 = OpFNegate %float %3\n" +
5470fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5471fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5472fd4e5da5Sopenharmony_ci    4, true),
5473fd4e5da5Sopenharmony_ci  // Test case 8: fold fnegate(fsub with const).
5474fd4e5da5Sopenharmony_ci  // -(x - 2.0) = 2.0 - x
5475fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5476fd4e5da5Sopenharmony_ci    Header() +
5477fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5478fd4e5da5Sopenharmony_ci      "; CHECK: [[float_2:%\\w+]] = OpConstant [[float]] 2\n" +
5479fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5480fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_2]] [[ld]]\n" +
5481fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5482fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5483fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5484fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5485fd4e5da5Sopenharmony_ci      "%3 = OpFSub %float %2 %float_2\n" +
5486fd4e5da5Sopenharmony_ci      "%4 = OpFNegate %float %3\n" +
5487fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5488fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5489fd4e5da5Sopenharmony_ci    4, true),
5490fd4e5da5Sopenharmony_ci  // Test case 9: fold consecutive snegate
5491fd4e5da5Sopenharmony_ci  // -(-x) = x
5492fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5493fd4e5da5Sopenharmony_ci    Header() +
5494fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int:%\\w+]]\n" +
5495fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpCopyObject [[int]] [[ld]]\n" +
5496fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5497fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5498fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
5499fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
5500fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %int %2\n" +
5501fd4e5da5Sopenharmony_ci      "%4 = OpSNegate %int %3\n" +
5502fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5503fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5504fd4e5da5Sopenharmony_ci    4, true),
5505fd4e5da5Sopenharmony_ci  // Test case 10: fold consecutive vector negate
5506fd4e5da5Sopenharmony_ci  // -(-x) = x
5507fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5508fd4e5da5Sopenharmony_ci    Header() +
5509fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[v2float:%\\w+]]\n" +
5510fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpCopyObject [[v2float]] [[ld]]\n" +
5511fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5512fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5513fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_v2float Function\n" +
5514fd4e5da5Sopenharmony_ci      "%2 = OpLoad %v2float %var\n" +
5515fd4e5da5Sopenharmony_ci      "%3 = OpFNegate %v2float %2\n" +
5516fd4e5da5Sopenharmony_ci      "%4 = OpFNegate %v2float %3\n" +
5517fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5518fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5519fd4e5da5Sopenharmony_ci    4, true),
5520fd4e5da5Sopenharmony_ci  // Test case 11: fold snegate(iadd with const).
5521fd4e5da5Sopenharmony_ci  // -(2 + x) = -2 - x
5522fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5523fd4e5da5Sopenharmony_ci    Header() +
5524fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
5525fd4e5da5Sopenharmony_ci      "; CHECK: OpConstant [[int]] -2147483648\n" +
5526fd4e5da5Sopenharmony_ci      "; CHECK: [[int_n2:%\\w+]] = OpConstant [[int]] -2{{[[:space:]]}}\n" +
5527fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int]]\n" +
5528fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[int]] [[int_n2]] [[ld]]\n" +
5529fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5530fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5531fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
5532fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
5533fd4e5da5Sopenharmony_ci      "%3 = OpIAdd %int %int_2 %2\n" +
5534fd4e5da5Sopenharmony_ci      "%4 = OpSNegate %int %3\n" +
5535fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5536fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5537fd4e5da5Sopenharmony_ci    4, true),
5538fd4e5da5Sopenharmony_ci  // Test case 12: fold snegate(iadd with const).
5539fd4e5da5Sopenharmony_ci  // -(x + 2) = -2 - x
5540fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5541fd4e5da5Sopenharmony_ci    Header() +
5542fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
5543fd4e5da5Sopenharmony_ci      "; CHECK: OpConstant [[int]] -2147483648\n" +
5544fd4e5da5Sopenharmony_ci      "; CHECK: [[int_n2:%\\w+]] = OpConstant [[int]] -2{{[[:space:]]}}\n" +
5545fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int]]\n" +
5546fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[int]] [[int_n2]] [[ld]]\n" +
5547fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5548fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5549fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
5550fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
5551fd4e5da5Sopenharmony_ci      "%3 = OpIAdd %int %2 %int_2\n" +
5552fd4e5da5Sopenharmony_ci      "%4 = OpSNegate %int %3\n" +
5553fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5554fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5555fd4e5da5Sopenharmony_ci    4, true),
5556fd4e5da5Sopenharmony_ci  // Test case 13: fold snegate(isub with const).
5557fd4e5da5Sopenharmony_ci  // -(2 - x) = x - 2
5558fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5559fd4e5da5Sopenharmony_ci    Header() +
5560fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
5561fd4e5da5Sopenharmony_ci      "; CHECK: [[int_2:%\\w+]] = OpConstant [[int]] 2\n" +
5562fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int]]\n" +
5563fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[int]] [[ld]] [[int_2]]\n" +
5564fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5565fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5566fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
5567fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
5568fd4e5da5Sopenharmony_ci      "%3 = OpISub %int %int_2 %2\n" +
5569fd4e5da5Sopenharmony_ci      "%4 = OpSNegate %int %3\n" +
5570fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5571fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5572fd4e5da5Sopenharmony_ci    4, true),
5573fd4e5da5Sopenharmony_ci  // Test case 14: fold snegate(isub with const).
5574fd4e5da5Sopenharmony_ci  // -(x - 2) = 2 - x
5575fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5576fd4e5da5Sopenharmony_ci    Header() +
5577fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
5578fd4e5da5Sopenharmony_ci      "; CHECK: [[int_2:%\\w+]] = OpConstant [[int]] 2\n" +
5579fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int]]\n" +
5580fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[int]] [[int_2]] [[ld]]\n" +
5581fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5582fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5583fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
5584fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
5585fd4e5da5Sopenharmony_ci      "%3 = OpISub %int %2 %int_2\n" +
5586fd4e5da5Sopenharmony_ci      "%4 = OpSNegate %int %3\n" +
5587fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5588fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5589fd4e5da5Sopenharmony_ci    4, true),
5590fd4e5da5Sopenharmony_ci  // Test case 15: fold snegate(iadd with const).
5591fd4e5da5Sopenharmony_ci  // -(x + 2) = -2 - x
5592fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5593fd4e5da5Sopenharmony_ci    Header() +
5594fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64 1\n" +
5595fd4e5da5Sopenharmony_ci      "; CHECK: [[long_n2:%\\w+]] = OpConstant [[long]] -2{{[[:space:]]}}\n" +
5596fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
5597fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[long]] [[long_n2]] [[ld]]\n" +
5598fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5599fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5600fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
5601fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
5602fd4e5da5Sopenharmony_ci      "%3 = OpIAdd %long %2 %long_2\n" +
5603fd4e5da5Sopenharmony_ci      "%4 = OpSNegate %long %3\n" +
5604fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5605fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5606fd4e5da5Sopenharmony_ci    4, true),
5607fd4e5da5Sopenharmony_ci  // Test case 16: fold snegate(isub with const).
5608fd4e5da5Sopenharmony_ci  // -(2 - x) = x - 2
5609fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5610fd4e5da5Sopenharmony_ci    Header() +
5611fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64 1\n" +
5612fd4e5da5Sopenharmony_ci      "; CHECK: [[long_2:%\\w+]] = OpConstant [[long]] 2\n" +
5613fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
5614fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[long]] [[ld]] [[long_2]]\n" +
5615fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5616fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5617fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
5618fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
5619fd4e5da5Sopenharmony_ci      "%3 = OpISub %long %long_2 %2\n" +
5620fd4e5da5Sopenharmony_ci      "%4 = OpSNegate %long %3\n" +
5621fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5622fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5623fd4e5da5Sopenharmony_ci    4, true),
5624fd4e5da5Sopenharmony_ci  // Test case 17: fold snegate(isub with const).
5625fd4e5da5Sopenharmony_ci  // -(x - 2) = 2 - x
5626fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5627fd4e5da5Sopenharmony_ci    Header() +
5628fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64 1\n" +
5629fd4e5da5Sopenharmony_ci      "; CHECK: [[long_2:%\\w+]] = OpConstant [[long]] 2\n" +
5630fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
5631fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[long]] [[long_2]] [[ld]]\n" +
5632fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5633fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5634fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
5635fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
5636fd4e5da5Sopenharmony_ci      "%3 = OpISub %long %2 %long_2\n" +
5637fd4e5da5Sopenharmony_ci      "%4 = OpSNegate %long %3\n" +
5638fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5639fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
5640fd4e5da5Sopenharmony_ci    4, true),
5641fd4e5da5Sopenharmony_ci    // Test case 18: fold -vec4(-1.0, 2.0, 1.0, 3.0)
5642fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
5643fd4e5da5Sopenharmony_ci        Header() +
5644fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5645fd4e5da5Sopenharmony_ci      "; CHECK: [[v4float:%\\w+]] = OpTypeVector [[float]] 4{{[[:space:]]}}\n" +
5646fd4e5da5Sopenharmony_ci      "; CHECK: [[float_n1:%\\w+]] = OpConstant [[float]] -1{{[[:space:]]}}\n" +
5647fd4e5da5Sopenharmony_ci      "; CHECK: [[float_1:%\\w+]] = OpConstant [[float]] 1{{[[:space:]]}}\n" +
5648fd4e5da5Sopenharmony_ci      "; CHECK: [[float_n2:%\\w+]] = OpConstant [[float]] -2{{[[:space:]]}}\n" +
5649fd4e5da5Sopenharmony_ci      "; CHECK: [[float_n3:%\\w+]] = OpConstant [[float]] -3{{[[:space:]]}}\n" +
5650fd4e5da5Sopenharmony_ci      "; CHECK: [[v4float_1_n2_n1_n3:%\\w+]] = OpConstantComposite [[v4float]] [[float_1]] [[float_n2]] [[float_n1]] [[float_n3]]\n" +
5651fd4e5da5Sopenharmony_ci      "; CHECK: %2 = OpCopyObject [[v4float]] [[v4float_1_n2_n1_n3]]\n" +
5652fd4e5da5Sopenharmony_ci        "%main = OpFunction %void None %void_func\n" +
5653fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5654fd4e5da5Sopenharmony_ci            "%2 = OpFNegate %v4float %v4float_n1_2_1_3\n" +
5655fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5656fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5657fd4e5da5Sopenharmony_ci        2, true),
5658fd4e5da5Sopenharmony_ci    // Test case 19: fold vector fnegate with null
5659fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
5660fd4e5da5Sopenharmony_ci        Header() +
5661fd4e5da5Sopenharmony_ci      "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
5662fd4e5da5Sopenharmony_ci      "; CHECK: [[v2double:%\\w+]] = OpTypeVector [[double]] 2\n" +
5663fd4e5da5Sopenharmony_ci      "; CHECK: [[double_n0:%\\w+]] = OpConstant [[double]] -0\n" +
5664fd4e5da5Sopenharmony_ci      "; CHECK: [[v2double_0_0:%\\w+]] = OpConstantComposite [[v2double]] [[double_n0]] [[double_n0]]\n" +
5665fd4e5da5Sopenharmony_ci      "; CHECK: %2 = OpCopyObject [[v2double]] [[v2double_0_0]]\n" +
5666fd4e5da5Sopenharmony_ci        "%main = OpFunction %void None %void_func\n" +
5667fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
5668fd4e5da5Sopenharmony_ci            "%2 = OpFNegate %v2double %v2double_null\n" +
5669fd4e5da5Sopenharmony_ci            "OpReturn\n" +
5670fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
5671fd4e5da5Sopenharmony_ci        2, true)
5672fd4e5da5Sopenharmony_ci));
5673fd4e5da5Sopenharmony_ci
5674fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(ReciprocalFDivTest, MatchingInstructionFoldingTest,
5675fd4e5da5Sopenharmony_ci::testing::Values(
5676fd4e5da5Sopenharmony_ci  // Test case 0: scalar reicprocal
5677fd4e5da5Sopenharmony_ci  // x / 0.5 = x * 2.0
5678fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5679fd4e5da5Sopenharmony_ci    Header() +
5680fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5681fd4e5da5Sopenharmony_ci      "; CHECK: [[float_2:%\\w+]] = OpConstant [[float]] 2\n" +
5682fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5683fd4e5da5Sopenharmony_ci      "; CHECK: %3 = OpFMul [[float]] [[ld]] [[float_2]]\n" +
5684fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5685fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5686fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5687fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5688fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %float %2 %float_0p5\n" +
5689fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5690fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5691fd4e5da5Sopenharmony_ci    3, true),
5692fd4e5da5Sopenharmony_ci  // Test case 1: Unfoldable
5693fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5694fd4e5da5Sopenharmony_ci    Header() +
5695fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5696fd4e5da5Sopenharmony_ci      "; CHECK: [[float_0:%\\w+]] = OpConstant [[float]] 0\n" +
5697fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5698fd4e5da5Sopenharmony_ci      "; CHECK: %3 = OpFDiv [[float]] [[ld]] [[float_0]]\n" +
5699fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5700fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5701fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5702fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5703fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %float %2 %104\n" +
5704fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5705fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5706fd4e5da5Sopenharmony_ci    3, false),
5707fd4e5da5Sopenharmony_ci  // Test case 2: Vector reciprocal
5708fd4e5da5Sopenharmony_ci  // x / {2.0, 0.5} = x * {0.5, 2.0}
5709fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5710fd4e5da5Sopenharmony_ci    Header() +
5711fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5712fd4e5da5Sopenharmony_ci      "; CHECK: [[v2float:%\\w+]] = OpTypeVector [[float]] 2\n" +
5713fd4e5da5Sopenharmony_ci      "; CHECK: [[float_2:%\\w+]] = OpConstant [[float]] 2\n" +
5714fd4e5da5Sopenharmony_ci      "; CHECK: [[float_0p5:%\\w+]] = OpConstant [[float]] 0.5\n" +
5715fd4e5da5Sopenharmony_ci      "; CHECK: [[v2float_0p5_2:%\\w+]] = OpConstantComposite [[v2float]] [[float_0p5]] [[float_2]]\n" +
5716fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[v2float]]\n" +
5717fd4e5da5Sopenharmony_ci      "; CHECK: %3 = OpFMul [[v2float]] [[ld]] [[v2float_0p5_2]]\n" +
5718fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5719fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5720fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_v2float Function\n" +
5721fd4e5da5Sopenharmony_ci      "%2 = OpLoad %v2float %var\n" +
5722fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %v2float %2 %v2float_2_0p5\n" +
5723fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5724fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5725fd4e5da5Sopenharmony_ci    3, true),
5726fd4e5da5Sopenharmony_ci  // Test case 3: double reciprocal
5727fd4e5da5Sopenharmony_ci  // x / 2.0 = x * 0.5
5728fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5729fd4e5da5Sopenharmony_ci    Header() +
5730fd4e5da5Sopenharmony_ci      "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
5731fd4e5da5Sopenharmony_ci      "; CHECK: [[double_0p5:%\\w+]] = OpConstant [[double]] 0.5\n" +
5732fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[double]]\n" +
5733fd4e5da5Sopenharmony_ci      "; CHECK: %3 = OpFMul [[double]] [[ld]] [[double_0p5]]\n" +
5734fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5735fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5736fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_double Function\n" +
5737fd4e5da5Sopenharmony_ci      "%2 = OpLoad %double %var\n" +
5738fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %double %2 %double_2\n" +
5739fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5740fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5741fd4e5da5Sopenharmony_ci    3, true),
5742fd4e5da5Sopenharmony_ci  // Test case 4: don't fold x / 0.
5743fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5744fd4e5da5Sopenharmony_ci    Header() +
5745fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5746fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5747fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_v2float Function\n" +
5748fd4e5da5Sopenharmony_ci      "%2 = OpLoad %v2float %var\n" +
5749fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %v2float %2 %v2float_null\n" +
5750fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5751fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5752fd4e5da5Sopenharmony_ci    3, false)
5753fd4e5da5Sopenharmony_ci));
5754fd4e5da5Sopenharmony_ci
5755fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(MergeMulTest, MatchingInstructionFoldingTest,
5756fd4e5da5Sopenharmony_ci::testing::Values(
5757fd4e5da5Sopenharmony_ci  // Test case 0: fold consecutive fmuls
5758fd4e5da5Sopenharmony_ci  // (x * 3.0) * 2.0 = x * 6.0
5759fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5760fd4e5da5Sopenharmony_ci    Header() +
5761fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5762fd4e5da5Sopenharmony_ci      "; CHECK: [[float_6:%\\w+]] = OpConstant [[float]] 6\n" +
5763fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5764fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFMul [[float]] [[ld]] [[float_6]]\n" +
5765fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5766fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5767fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5768fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5769fd4e5da5Sopenharmony_ci      "%3 = OpFMul %float %2 %float_3\n" +
5770fd4e5da5Sopenharmony_ci      "%4 = OpFMul %float %3 %float_2\n" +
5771fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5772fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5773fd4e5da5Sopenharmony_ci    4, true),
5774fd4e5da5Sopenharmony_ci  // Test case 1: fold consecutive fmuls
5775fd4e5da5Sopenharmony_ci  // 2.0 * (x * 3.0) = x * 6.0
5776fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5777fd4e5da5Sopenharmony_ci    Header() +
5778fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5779fd4e5da5Sopenharmony_ci      "; CHECK: [[float_6:%\\w+]] = OpConstant [[float]] 6\n" +
5780fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5781fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFMul [[float]] [[ld]] [[float_6]]\n" +
5782fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5783fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5784fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5785fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5786fd4e5da5Sopenharmony_ci      "%3 = OpFMul %float %2 %float_3\n" +
5787fd4e5da5Sopenharmony_ci      "%4 = OpFMul %float %float_2 %3\n" +
5788fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5789fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5790fd4e5da5Sopenharmony_ci    4, true),
5791fd4e5da5Sopenharmony_ci  // Test case 2: fold consecutive fmuls
5792fd4e5da5Sopenharmony_ci  // (3.0 * x) * 2.0 = x * 6.0
5793fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5794fd4e5da5Sopenharmony_ci    Header() +
5795fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5796fd4e5da5Sopenharmony_ci      "; CHECK: [[float_6:%\\w+]] = OpConstant [[float]] 6\n" +
5797fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5798fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFMul [[float]] [[ld]] [[float_6]]\n" +
5799fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5800fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5801fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5802fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5803fd4e5da5Sopenharmony_ci      "%3 = OpFMul %float %float_3 %2\n" +
5804fd4e5da5Sopenharmony_ci      "%4 = OpFMul %float %float_2 %3\n" +
5805fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5806fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5807fd4e5da5Sopenharmony_ci    4, true),
5808fd4e5da5Sopenharmony_ci  // Test case 3: fold vector fmul
5809fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5810fd4e5da5Sopenharmony_ci    Header() +
5811fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5812fd4e5da5Sopenharmony_ci      "; CHECK: [[v2float:%\\w+]] = OpTypeVector [[float]] 2\n" +
5813fd4e5da5Sopenharmony_ci      "; CHECK: [[float_6:%\\w+]] = OpConstant [[float]] 6\n" +
5814fd4e5da5Sopenharmony_ci      "; CHECK: [[v2float_6_6:%\\w+]] = OpConstantComposite [[v2float]] [[float_6]] [[float_6]]\n" +
5815fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[v2float]]\n" +
5816fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFMul [[v2float]] [[ld]] [[v2float_6_6]]\n" +
5817fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5818fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5819fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_v2float Function\n" +
5820fd4e5da5Sopenharmony_ci      "%2 = OpLoad %v2float %var\n" +
5821fd4e5da5Sopenharmony_ci      "%3 = OpFMul %v2float %2 %v2float_2_3\n" +
5822fd4e5da5Sopenharmony_ci      "%4 = OpFMul %v2float %3 %v2float_3_2\n" +
5823fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5824fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5825fd4e5da5Sopenharmony_ci    4, true),
5826fd4e5da5Sopenharmony_ci  // Test case 4: fold double fmuls
5827fd4e5da5Sopenharmony_ci  // (x * 3.0) * 2.0 = x * 6.0
5828fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5829fd4e5da5Sopenharmony_ci    Header() +
5830fd4e5da5Sopenharmony_ci      "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
5831fd4e5da5Sopenharmony_ci      "; CHECK: [[double_6:%\\w+]] = OpConstant [[double]] 6\n" +
5832fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[double]]\n" +
5833fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFMul [[double]] [[ld]] [[double_6]]\n" +
5834fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5835fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5836fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_double Function\n" +
5837fd4e5da5Sopenharmony_ci      "%2 = OpLoad %double %var\n" +
5838fd4e5da5Sopenharmony_ci      "%3 = OpFMul %double %2 %double_3\n" +
5839fd4e5da5Sopenharmony_ci      "%4 = OpFMul %double %3 %double_2\n" +
5840fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5841fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5842fd4e5da5Sopenharmony_ci    4, true),
5843fd4e5da5Sopenharmony_ci  // Test case 5: fold 32 bit imuls
5844fd4e5da5Sopenharmony_ci  // (x * 3) * 2 = x * 6
5845fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5846fd4e5da5Sopenharmony_ci    Header() +
5847fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
5848fd4e5da5Sopenharmony_ci      "; CHECK: [[int_6:%\\w+]] = OpConstant [[int]] 6\n" +
5849fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int]]\n" +
5850fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIMul [[int]] [[ld]] [[int_6]]\n" +
5851fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5852fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5853fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
5854fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
5855fd4e5da5Sopenharmony_ci      "%3 = OpIMul %int %2 %int_3\n" +
5856fd4e5da5Sopenharmony_ci      "%4 = OpIMul %int %3 %int_2\n" +
5857fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5858fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5859fd4e5da5Sopenharmony_ci    4, true),
5860fd4e5da5Sopenharmony_ci  // Test case 6: fold 64 bit imuls
5861fd4e5da5Sopenharmony_ci  // (x * 3) * 2 = x * 6
5862fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5863fd4e5da5Sopenharmony_ci    Header() +
5864fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64\n" +
5865fd4e5da5Sopenharmony_ci      "; CHECK: [[long_6:%\\w+]] = OpConstant [[long]] 6\n" +
5866fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
5867fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIMul [[long]] [[ld]] [[long_6]]\n" +
5868fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5869fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5870fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
5871fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
5872fd4e5da5Sopenharmony_ci      "%3 = OpIMul %long %2 %long_3\n" +
5873fd4e5da5Sopenharmony_ci      "%4 = OpIMul %long %3 %long_2\n" +
5874fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5875fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5876fd4e5da5Sopenharmony_ci    4, true),
5877fd4e5da5Sopenharmony_ci  // Test case 7: merge vector integer mults
5878fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5879fd4e5da5Sopenharmony_ci    Header() +
5880fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
5881fd4e5da5Sopenharmony_ci      "; CHECK: [[v2int:%\\w+]] = OpTypeVector [[int]] 2\n" +
5882fd4e5da5Sopenharmony_ci      "; CHECK: [[int_6:%\\w+]] = OpConstant [[int]] 6\n" +
5883fd4e5da5Sopenharmony_ci      "; CHECK: [[v2int_6_6:%\\w+]] = OpConstantComposite [[v2int]] [[int_6]] [[int_6]]\n" +
5884fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[v2int]]\n" +
5885fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIMul [[v2int]] [[ld]] [[v2int_6_6]]\n" +
5886fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5887fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5888fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_v2int Function\n" +
5889fd4e5da5Sopenharmony_ci      "%2 = OpLoad %v2int %var\n" +
5890fd4e5da5Sopenharmony_ci      "%3 = OpIMul %v2int %2 %v2int_2_3\n" +
5891fd4e5da5Sopenharmony_ci      "%4 = OpIMul %v2int %3 %v2int_3_2\n" +
5892fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5893fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5894fd4e5da5Sopenharmony_ci    4, true),
5895fd4e5da5Sopenharmony_ci  // Test case 8: merge fmul of fdiv
5896fd4e5da5Sopenharmony_ci  // 2.0 * (2.0 / x) = 4.0 / x
5897fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5898fd4e5da5Sopenharmony_ci    Header() +
5899fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5900fd4e5da5Sopenharmony_ci      "; CHECK: [[float_4:%\\w+]] = OpConstant [[float]] 4\n" +
5901fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5902fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFDiv [[float]] [[float_4]] [[ld]]\n" +
5903fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5904fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5905fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5906fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5907fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %float %float_2 %2\n" +
5908fd4e5da5Sopenharmony_ci      "%4 = OpFMul %float %float_2 %3\n" +
5909fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5910fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5911fd4e5da5Sopenharmony_ci    4, true),
5912fd4e5da5Sopenharmony_ci  // Test case 9: merge fmul of fdiv
5913fd4e5da5Sopenharmony_ci  // (2.0 / x) * 2.0 = 4.0 / x
5914fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5915fd4e5da5Sopenharmony_ci    Header() +
5916fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5917fd4e5da5Sopenharmony_ci      "; CHECK: [[float_4:%\\w+]] = OpConstant [[float]] 4\n" +
5918fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
5919fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFDiv [[float]] [[float_4]] [[ld]]\n" +
5920fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5921fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5922fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
5923fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
5924fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %float %float_2 %2\n" +
5925fd4e5da5Sopenharmony_ci      "%4 = OpFMul %float %3 %float_2\n" +
5926fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5927fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5928fd4e5da5Sopenharmony_ci    4, true),
5929fd4e5da5Sopenharmony_ci  // Test case 10: Do not merge imul of sdiv
5930fd4e5da5Sopenharmony_ci  // 4 * (x / 2)
5931fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5932fd4e5da5Sopenharmony_ci    Header() +
5933fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5934fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5935fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
5936fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
5937fd4e5da5Sopenharmony_ci      "%3 = OpSDiv %int %2 %int_2\n" +
5938fd4e5da5Sopenharmony_ci      "%4 = OpIMul %int %int_4 %3\n" +
5939fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5940fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5941fd4e5da5Sopenharmony_ci    4, false),
5942fd4e5da5Sopenharmony_ci  // Test case 11: Do not merge imul of sdiv
5943fd4e5da5Sopenharmony_ci  // (x / 2) * 4
5944fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5945fd4e5da5Sopenharmony_ci    Header() +
5946fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5947fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5948fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
5949fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
5950fd4e5da5Sopenharmony_ci      "%3 = OpSDiv %int %2 %int_2\n" +
5951fd4e5da5Sopenharmony_ci      "%4 = OpIMul %int %3 %int_4\n" +
5952fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5953fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5954fd4e5da5Sopenharmony_ci    4, false),
5955fd4e5da5Sopenharmony_ci  // Test case 12: Do not merge imul of udiv
5956fd4e5da5Sopenharmony_ci  // 4 * (x / 2)
5957fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5958fd4e5da5Sopenharmony_ci    Header() +
5959fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5960fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5961fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_uint Function\n" +
5962fd4e5da5Sopenharmony_ci      "%2 = OpLoad %uint %var\n" +
5963fd4e5da5Sopenharmony_ci      "%3 = OpUDiv %uint %2 %uint_2\n" +
5964fd4e5da5Sopenharmony_ci      "%4 = OpIMul %uint %uint_4 %3\n" +
5965fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5966fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5967fd4e5da5Sopenharmony_ci    4, false),
5968fd4e5da5Sopenharmony_ci  // Test case 13: Do not merge imul of udiv
5969fd4e5da5Sopenharmony_ci  // (x / 2) * 4
5970fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5971fd4e5da5Sopenharmony_ci    Header() +
5972fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5973fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5974fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_uint Function\n" +
5975fd4e5da5Sopenharmony_ci      "%2 = OpLoad %uint %var\n" +
5976fd4e5da5Sopenharmony_ci      "%3 = OpUDiv %uint %2 %uint_2\n" +
5977fd4e5da5Sopenharmony_ci      "%4 = OpIMul %uint %3 %uint_4\n" +
5978fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5979fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5980fd4e5da5Sopenharmony_ci    4, false),
5981fd4e5da5Sopenharmony_ci  // Test case 14: Don't fold
5982fd4e5da5Sopenharmony_ci  // (x / 3) * 4
5983fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5984fd4e5da5Sopenharmony_ci    Header() +
5985fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
5986fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
5987fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_uint Function\n" +
5988fd4e5da5Sopenharmony_ci      "%2 = OpLoad %uint %var\n" +
5989fd4e5da5Sopenharmony_ci      "%3 = OpUDiv %uint %2 %uint_3\n" +
5990fd4e5da5Sopenharmony_ci      "%4 = OpIMul %uint %3 %uint_4\n" +
5991fd4e5da5Sopenharmony_ci      "OpReturn\n" +
5992fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
5993fd4e5da5Sopenharmony_ci    4, false),
5994fd4e5da5Sopenharmony_ci  // Test case 15: merge vector fmul of fdiv
5995fd4e5da5Sopenharmony_ci  // (x / {2,2}) * {4,4} = x * {2,2}
5996fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
5997fd4e5da5Sopenharmony_ci    Header() +
5998fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
5999fd4e5da5Sopenharmony_ci      "; CHECK: [[v2float:%\\w+]] = OpTypeVector [[float]] 2\n" +
6000fd4e5da5Sopenharmony_ci      "; CHECK: [[float_2:%\\w+]] = OpConstant [[float]] 2\n" +
6001fd4e5da5Sopenharmony_ci      "; CHECK: [[v2float_2_2:%\\w+]] = OpConstantComposite [[v2float]] [[float_2]] [[float_2]]\n" +
6002fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[v2float]]\n" +
6003fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFMul [[v2float]] [[ld]] [[v2float_2_2]]\n" +
6004fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6005fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6006fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_v2float Function\n" +
6007fd4e5da5Sopenharmony_ci      "%2 = OpLoad %v2float %var\n" +
6008fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %v2float %2 %v2float_2_2\n" +
6009fd4e5da5Sopenharmony_ci      "%4 = OpFMul %v2float %3 %v2float_4_4\n" +
6010fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6011fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6012fd4e5da5Sopenharmony_ci    4, true),
6013fd4e5da5Sopenharmony_ci  // Test case 16: merge vector imul of snegate
6014fd4e5da5Sopenharmony_ci  // (-x) * {2,2} = x * {-2,-2}
6015fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6016fd4e5da5Sopenharmony_ci    Header() +
6017fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
6018fd4e5da5Sopenharmony_ci      "; CHECK: [[v2int:%\\w+]] = OpTypeVector [[int]] 2{{[[:space:]]}}\n" +
6019fd4e5da5Sopenharmony_ci      "; CHECK: OpConstant [[int]] -2147483648{{[[:space:]]}}\n" +
6020fd4e5da5Sopenharmony_ci      "; CHECK: [[int_n2:%\\w+]] = OpConstant [[int]] -2{{[[:space:]]}}\n" +
6021fd4e5da5Sopenharmony_ci      "; CHECK: [[v2int_n2_n2:%\\w+]] = OpConstantComposite [[v2int]] [[int_n2]] [[int_n2]]\n" +
6022fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[v2int]]\n" +
6023fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIMul [[v2int]] [[ld]] [[v2int_n2_n2]]\n" +
6024fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6025fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6026fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_v2int Function\n" +
6027fd4e5da5Sopenharmony_ci      "%2 = OpLoad %v2int %var\n" +
6028fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %v2int %2\n" +
6029fd4e5da5Sopenharmony_ci      "%4 = OpIMul %v2int %3 %v2int_2_2\n" +
6030fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6031fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6032fd4e5da5Sopenharmony_ci    4, true),
6033fd4e5da5Sopenharmony_ci  // Test case 17: merge vector imul of snegate
6034fd4e5da5Sopenharmony_ci  // {2,2} * (-x) = x * {-2,-2}
6035fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6036fd4e5da5Sopenharmony_ci    Header() +
6037fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
6038fd4e5da5Sopenharmony_ci      "; CHECK: [[v2int:%\\w+]] = OpTypeVector [[int]] 2{{[[:space:]]}}\n" +
6039fd4e5da5Sopenharmony_ci      "; CHECK: OpConstant [[int]] -2147483648{{[[:space:]]}}\n" +
6040fd4e5da5Sopenharmony_ci      "; CHECK: [[int_n2:%\\w+]] = OpConstant [[int]] -2{{[[:space:]]}}\n" +
6041fd4e5da5Sopenharmony_ci      "; CHECK: [[v2int_n2_n2:%\\w+]] = OpConstantComposite [[v2int]] [[int_n2]] [[int_n2]]\n" +
6042fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[v2int]]\n" +
6043fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIMul [[v2int]] [[ld]] [[v2int_n2_n2]]\n" +
6044fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6045fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6046fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_v2int Function\n" +
6047fd4e5da5Sopenharmony_ci      "%2 = OpLoad %v2int %var\n" +
6048fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %v2int %2\n" +
6049fd4e5da5Sopenharmony_ci      "%4 = OpIMul %v2int %v2int_2_2 %3\n" +
6050fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6051fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6052fd4e5da5Sopenharmony_ci    4, true),
6053fd4e5da5Sopenharmony_ci  // Test case 18: Fold OpVectorTimesScalar
6054fd4e5da5Sopenharmony_ci  // {4,4} = OpVectorTimesScalar v2float {2,2} 2
6055fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6056fd4e5da5Sopenharmony_ci    Header() +
6057fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6058fd4e5da5Sopenharmony_ci      "; CHECK: [[v2float:%\\w+]] = OpTypeVector [[float]] 2\n" +
6059fd4e5da5Sopenharmony_ci      "; CHECK: [[float_4:%\\w+]] = OpConstant [[float]] 4\n" +
6060fd4e5da5Sopenharmony_ci      "; CHECK: [[v2float_4_4:%\\w+]] = OpConstantComposite [[v2float]] [[float_4]] [[float_4]]\n" +
6061fd4e5da5Sopenharmony_ci      "; CHECK: %2 = OpCopyObject [[v2float]] [[v2float_4_4]]\n" +
6062fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6063fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6064fd4e5da5Sopenharmony_ci      "%2 = OpVectorTimesScalar %v2float %v2float_2_2 %float_2\n" +
6065fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6066fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
6067fd4e5da5Sopenharmony_ci    2, true),
6068fd4e5da5Sopenharmony_ci  // Test case 19: Fold OpVectorTimesScalar
6069fd4e5da5Sopenharmony_ci  // {0,0} = OpVectorTimesScalar v2float v2float_null -1
6070fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6071fd4e5da5Sopenharmony_ci    Header() +
6072fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6073fd4e5da5Sopenharmony_ci      "; CHECK: [[v2float:%\\w+]] = OpTypeVector [[float]] 2\n" +
6074fd4e5da5Sopenharmony_ci      "; CHECK: [[v2float_null:%\\w+]] = OpConstantNull [[v2float]]\n" +
6075fd4e5da5Sopenharmony_ci      "; CHECK: %2 = OpCopyObject [[v2float]] [[v2float_null]]\n" +
6076fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6077fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6078fd4e5da5Sopenharmony_ci      "%2 = OpVectorTimesScalar %v2float %v2float_null %float_n1\n" +
6079fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6080fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
6081fd4e5da5Sopenharmony_ci    2, true),
6082fd4e5da5Sopenharmony_ci  // Test case 20: Fold OpVectorTimesScalar
6083fd4e5da5Sopenharmony_ci  // {4,4} = OpVectorTimesScalar v2double {2,2} 2
6084fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6085fd4e5da5Sopenharmony_ci    Header() +
6086fd4e5da5Sopenharmony_ci      "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
6087fd4e5da5Sopenharmony_ci      "; CHECK: [[v2double:%\\w+]] = OpTypeVector [[double]] 2\n" +
6088fd4e5da5Sopenharmony_ci      "; CHECK: [[double_4:%\\w+]] = OpConstant [[double]] 4\n" +
6089fd4e5da5Sopenharmony_ci      "; CHECK: [[v2double_4_4:%\\w+]] = OpConstantComposite [[v2double]] [[double_4]] [[double_4]]\n" +
6090fd4e5da5Sopenharmony_ci      "; CHECK: %2 = OpCopyObject [[v2double]] [[v2double_4_4]]\n" +
6091fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6092fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6093fd4e5da5Sopenharmony_ci      "%2 = OpVectorTimesScalar %v2double %v2double_2_2 %double_2\n" +
6094fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6095fd4e5da5Sopenharmony_ci      "OpFunctionEnd",
6096fd4e5da5Sopenharmony_ci    2, true),
6097fd4e5da5Sopenharmony_ci  // Test case 21: Fold OpVectorTimesScalar
6098fd4e5da5Sopenharmony_ci  // {0,0} = OpVectorTimesScalar v2double {0,0} n
6099fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6100fd4e5da5Sopenharmony_ci    Header() +
6101fd4e5da5Sopenharmony_ci        "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
6102fd4e5da5Sopenharmony_ci        "; CHECK: [[v2double:%\\w+]] = OpTypeVector [[double]] 2\n" +
6103fd4e5da5Sopenharmony_ci        "; CHECK: {{%\\w+}} = OpConstant [[double]] 0\n" +
6104fd4e5da5Sopenharmony_ci        "; CHECK: [[double_0:%\\w+]] = OpConstant [[double]] 0\n" +
6105fd4e5da5Sopenharmony_ci        "; CHECK: [[v2double_0_0:%\\w+]] = OpConstantComposite [[v2double]] [[double_0]] [[double_0]]\n" +
6106fd4e5da5Sopenharmony_ci        "; CHECK: %2 = OpCopyObject [[v2double]] [[v2double_0_0]]\n" +
6107fd4e5da5Sopenharmony_ci        "%main = OpFunction %void None %void_func\n" +
6108fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
6109fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_double Function\n" +
6110fd4e5da5Sopenharmony_ci        "%load = OpLoad %double %n\n" +
6111fd4e5da5Sopenharmony_ci        "%2 = OpVectorTimesScalar %v2double %v2double_0_0 %load\n" +
6112fd4e5da5Sopenharmony_ci        "OpReturn\n" +
6113fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
6114fd4e5da5Sopenharmony_ci    2, true),
6115fd4e5da5Sopenharmony_ci  // Test case 22: Fold OpVectorTimesScalar
6116fd4e5da5Sopenharmony_ci  // {0,0} = OpVectorTimesScalar v2double n 0
6117fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6118fd4e5da5Sopenharmony_ci    Header() +
6119fd4e5da5Sopenharmony_ci        "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
6120fd4e5da5Sopenharmony_ci        "; CHECK: [[v2double:%\\w+]] = OpTypeVector [[double]] 2\n" +
6121fd4e5da5Sopenharmony_ci        "; CHECK: [[v2double_null:%\\w+]] = OpConstantNull [[v2double]]\n" +
6122fd4e5da5Sopenharmony_ci        "; CHECK: %2 = OpCopyObject [[v2double]] [[v2double_null]]\n" +
6123fd4e5da5Sopenharmony_ci        "%main = OpFunction %void None %void_func\n" +
6124fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
6125fd4e5da5Sopenharmony_ci        "%n = OpVariable %_ptr_v2double Function\n" +
6126fd4e5da5Sopenharmony_ci        "%load = OpLoad %v2double %n\n" +
6127fd4e5da5Sopenharmony_ci        "%2 = OpVectorTimesScalar %v2double %load %double_0\n" +
6128fd4e5da5Sopenharmony_ci        "OpReturn\n" +
6129fd4e5da5Sopenharmony_ci        "OpFunctionEnd",
6130fd4e5da5Sopenharmony_ci    2, true),
6131fd4e5da5Sopenharmony_ci  // Test case 23: merge fmul of fdiv
6132fd4e5da5Sopenharmony_ci  // x * (y / x) = y
6133fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6134fd4e5da5Sopenharmony_ci    Header() +
6135fd4e5da5Sopenharmony_ci        "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6136fd4e5da5Sopenharmony_ci        "; CHECK: [[ldx:%\\w+]] = OpLoad [[float]]\n" +
6137fd4e5da5Sopenharmony_ci        "; CHECK: [[ldy:%\\w+]] = OpLoad [[float]] [[y:%\\w+]]\n" +
6138fd4e5da5Sopenharmony_ci        "; CHECK: %5 = OpCopyObject [[float]] [[ldy]]\n" +
6139fd4e5da5Sopenharmony_ci        "%main = OpFunction %void None %void_func\n" +
6140fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
6141fd4e5da5Sopenharmony_ci        "%x = OpVariable %_ptr_float Function\n" +
6142fd4e5da5Sopenharmony_ci        "%y = OpVariable %_ptr_float Function\n" +
6143fd4e5da5Sopenharmony_ci        "%2 = OpLoad %float %x\n" +
6144fd4e5da5Sopenharmony_ci        "%3 = OpLoad %float %y\n" +
6145fd4e5da5Sopenharmony_ci        "%4 = OpFDiv %float %3 %2\n" +
6146fd4e5da5Sopenharmony_ci        "%5 = OpFMul %float %2 %4\n" +
6147fd4e5da5Sopenharmony_ci        "OpReturn\n" +
6148fd4e5da5Sopenharmony_ci        "OpFunctionEnd\n",
6149fd4e5da5Sopenharmony_ci    5, true),
6150fd4e5da5Sopenharmony_ci  // Test case 24: merge fmul of fdiv
6151fd4e5da5Sopenharmony_ci  // (y / x) * x = y
6152fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6153fd4e5da5Sopenharmony_ci    Header() +
6154fd4e5da5Sopenharmony_ci        "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6155fd4e5da5Sopenharmony_ci        "; CHECK: [[ldx:%\\w+]] = OpLoad [[float]]\n" +
6156fd4e5da5Sopenharmony_ci        "; CHECK: [[ldy:%\\w+]] = OpLoad [[float]] [[y:%\\w+]]\n" +
6157fd4e5da5Sopenharmony_ci        "; CHECK: %5 = OpCopyObject [[float]] [[ldy]]\n" +
6158fd4e5da5Sopenharmony_ci        "%main = OpFunction %void None %void_func\n" +
6159fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
6160fd4e5da5Sopenharmony_ci        "%x = OpVariable %_ptr_float Function\n" +
6161fd4e5da5Sopenharmony_ci        "%y = OpVariable %_ptr_float Function\n" +
6162fd4e5da5Sopenharmony_ci        "%2 = OpLoad %float %x\n" +
6163fd4e5da5Sopenharmony_ci        "%3 = OpLoad %float %y\n" +
6164fd4e5da5Sopenharmony_ci        "%4 = OpFDiv %float %3 %2\n" +
6165fd4e5da5Sopenharmony_ci        "%5 = OpFMul %float %4 %2\n" +
6166fd4e5da5Sopenharmony_ci        "OpReturn\n" +
6167fd4e5da5Sopenharmony_ci        "OpFunctionEnd\n",
6168fd4e5da5Sopenharmony_ci    5, true),
6169fd4e5da5Sopenharmony_ci  // Test case 25: fold overflowing signed 32 bit imuls
6170fd4e5da5Sopenharmony_ci  // (x * 1073741824) * 2 = x * int_min
6171fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6172fd4e5da5Sopenharmony_ci    Header() +
6173fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32\n" +
6174fd4e5da5Sopenharmony_ci      "; CHECK: [[int_min:%\\w+]] = OpConstant [[int]] -2147483648\n" +
6175fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int]]\n" +
6176fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIMul [[int]] [[ld]] [[int_min]]\n" +
6177fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6178fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6179fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6180fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6181fd4e5da5Sopenharmony_ci      "%3 = OpIMul %int %2 %int_1073741824\n" +
6182fd4e5da5Sopenharmony_ci      "%4 = OpIMul %int %3 %int_2\n" +
6183fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6184fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6185fd4e5da5Sopenharmony_ci    4, true),
6186fd4e5da5Sopenharmony_ci  // Test case 26: fold overflowing signed 64 bit imuls
6187fd4e5da5Sopenharmony_ci  // (x * 4611686018427387904) * 2 = x * long_min
6188fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6189fd4e5da5Sopenharmony_ci    Header() +
6190fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64\n" +
6191fd4e5da5Sopenharmony_ci      "; CHECK: [[long_min:%\\w+]] = OpConstant [[long]] -9223372036854775808\n" +
6192fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
6193fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIMul [[long]] [[ld]] [[long_min]]\n" +
6194fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6195fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6196fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
6197fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
6198fd4e5da5Sopenharmony_ci      "%3 = OpIMul %long %2 %long_4611686018427387904\n" +
6199fd4e5da5Sopenharmony_ci      "%4 = OpIMul %long %3 %long_2\n" +
6200fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6201fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6202fd4e5da5Sopenharmony_ci    4, true),
6203fd4e5da5Sopenharmony_ci  // Test case 27: fold overflowing 32 bit unsigned imuls
6204fd4e5da5Sopenharmony_ci  // (x * 2147483649) * 2 = x * 2
6205fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6206fd4e5da5Sopenharmony_ci    Header() +
6207fd4e5da5Sopenharmony_ci      "; CHECK: [[uint:%\\w+]] = OpTypeInt 32 0\n" +
6208fd4e5da5Sopenharmony_ci      "; CHECK: [[uint_2:%\\w+]] = OpConstant [[uint]] 2\n" +
6209fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[uint]]\n" +
6210fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIMul [[uint]] [[ld]] [[uint_2]]\n" +
6211fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6212fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6213fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_uint Function\n" +
6214fd4e5da5Sopenharmony_ci      "%2 = OpLoad %uint %var\n" +
6215fd4e5da5Sopenharmony_ci      "%3 = OpIMul %uint %2 %uint_2147483649\n" +
6216fd4e5da5Sopenharmony_ci      "%4 = OpIMul %uint %3 %uint_2\n" +
6217fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6218fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6219fd4e5da5Sopenharmony_ci    4, true),
6220fd4e5da5Sopenharmony_ci  // Test case 28: fold overflowing 64 bit unsigned imuls
6221fd4e5da5Sopenharmony_ci  // (x * 9223372036854775809) * 2 = x * 2
6222fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6223fd4e5da5Sopenharmony_ci    Header() +
6224fd4e5da5Sopenharmony_ci      "; CHECK: [[ulong:%\\w+]] = OpTypeInt 64 0\n" +
6225fd4e5da5Sopenharmony_ci      "; CHECK: [[ulong_2:%\\w+]] = OpConstant [[ulong]] 2\n" +
6226fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[ulong]]\n" +
6227fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIMul [[ulong]] [[ld]] [[ulong_2]]\n" +
6228fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6229fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6230fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_ulong Function\n" +
6231fd4e5da5Sopenharmony_ci      "%2 = OpLoad %ulong %var\n" +
6232fd4e5da5Sopenharmony_ci      "%3 = OpIMul %ulong %2 %ulong_9223372036854775809\n" +
6233fd4e5da5Sopenharmony_ci      "%4 = OpIMul %ulong %3 %ulong_2\n" +
6234fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6235fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6236fd4e5da5Sopenharmony_ci    4, true),
6237fd4e5da5Sopenharmony_ci  // Test case 29: fold underflowing signed 32 bit imuls
6238fd4e5da5Sopenharmony_ci  // (x * (-858993459)) * 10 = x * 2
6239fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6240fd4e5da5Sopenharmony_ci    Header() +
6241fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32\n" +
6242fd4e5da5Sopenharmony_ci      "; CHECK: [[int_2:%\\w+]] = OpConstant [[int]] 2\n" +
6243fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int]]\n" +
6244fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIMul [[int]] [[ld]] [[int_2]]\n" +
6245fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6246fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6247fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6248fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6249fd4e5da5Sopenharmony_ci      "%3 = OpIMul %int %2 %int_n858993459\n" +
6250fd4e5da5Sopenharmony_ci      "%4 = OpIMul %int %3 %int_10\n" +
6251fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6252fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6253fd4e5da5Sopenharmony_ci    4, true),
6254fd4e5da5Sopenharmony_ci  // Test case 30: fold underflowing signed 64 bit imuls
6255fd4e5da5Sopenharmony_ci  // (x * (-3689348814741910323)) * 10 = x * 2
6256fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6257fd4e5da5Sopenharmony_ci    Header() +
6258fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64\n" +
6259fd4e5da5Sopenharmony_ci      "; CHECK: [[long_2:%\\w+]] = OpConstant [[long]] 2\n" +
6260fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
6261fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIMul [[long]] [[ld]] [[long_2]]\n" +
6262fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6263fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6264fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
6265fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
6266fd4e5da5Sopenharmony_ci      "%3 = OpIMul %long %2 %long_n3689348814741910323\n" +
6267fd4e5da5Sopenharmony_ci      "%4 = OpIMul %long %3 %long_10\n" +
6268fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6269fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6270fd4e5da5Sopenharmony_ci    4, true)
6271fd4e5da5Sopenharmony_ci));
6272fd4e5da5Sopenharmony_ci
6273fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(MergeDivTest, MatchingInstructionFoldingTest,
6274fd4e5da5Sopenharmony_ci::testing::Values(
6275fd4e5da5Sopenharmony_ci  // Test case 0: merge consecutive fdiv
6276fd4e5da5Sopenharmony_ci  // 4.0 / (2.0 / x) = 2.0 * x
6277fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6278fd4e5da5Sopenharmony_ci    Header() +
6279fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6280fd4e5da5Sopenharmony_ci      "; CHECK: [[float_2:%\\w+]] = OpConstant [[float]] 2\n" +
6281fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6282fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFMul [[float]] [[float_2]] [[ld]]\n" +
6283fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6284fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6285fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6286fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6287fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %float %float_2 %2\n" +
6288fd4e5da5Sopenharmony_ci      "%4 = OpFDiv %float %float_4 %3\n" +
6289fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6290fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6291fd4e5da5Sopenharmony_ci    4, true),
6292fd4e5da5Sopenharmony_ci  // Test case 1: merge consecutive fdiv
6293fd4e5da5Sopenharmony_ci  // 4.0 / (x / 2.0) = 8.0 / x
6294fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6295fd4e5da5Sopenharmony_ci    Header() +
6296fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6297fd4e5da5Sopenharmony_ci      "; CHECK: [[float_8:%\\w+]] = OpConstant [[float]] 8\n" +
6298fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6299fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFDiv [[float]] [[float_8]] [[ld]]\n" +
6300fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6301fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6302fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6303fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6304fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %float %2 %float_2\n" +
6305fd4e5da5Sopenharmony_ci      "%4 = OpFDiv %float %float_4 %3\n" +
6306fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6307fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6308fd4e5da5Sopenharmony_ci    4, true),
6309fd4e5da5Sopenharmony_ci  // Test case 2: merge consecutive fdiv
6310fd4e5da5Sopenharmony_ci  // (4.0 / x) / 2.0 = 2.0 / x
6311fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6312fd4e5da5Sopenharmony_ci    Header() +
6313fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6314fd4e5da5Sopenharmony_ci      "; CHECK: [[float_2:%\\w+]] = OpConstant [[float]] 2\n" +
6315fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6316fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFDiv [[float]] [[float_2]] [[ld]]\n" +
6317fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6318fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6319fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6320fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6321fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %float %float_4 %2\n" +
6322fd4e5da5Sopenharmony_ci      "%4 = OpFDiv %float %3 %float_2\n" +
6323fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6324fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6325fd4e5da5Sopenharmony_ci    4, true),
6326fd4e5da5Sopenharmony_ci  // Test case 3: Do not merge consecutive sdiv
6327fd4e5da5Sopenharmony_ci  // 4 / (2 / x)
6328fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6329fd4e5da5Sopenharmony_ci    Header() +
6330fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6331fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6332fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6333fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6334fd4e5da5Sopenharmony_ci      "%3 = OpSDiv %int %int_2 %2\n" +
6335fd4e5da5Sopenharmony_ci      "%4 = OpSDiv %int %int_4 %3\n" +
6336fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6337fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6338fd4e5da5Sopenharmony_ci    4, false),
6339fd4e5da5Sopenharmony_ci  // Test case 4: Do not merge consecutive sdiv
6340fd4e5da5Sopenharmony_ci  // 4 / (x / 2)
6341fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6342fd4e5da5Sopenharmony_ci    Header() +
6343fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6344fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6345fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6346fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6347fd4e5da5Sopenharmony_ci      "%3 = OpSDiv %int %2 %int_2\n" +
6348fd4e5da5Sopenharmony_ci      "%4 = OpSDiv %int %int_4 %3\n" +
6349fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6350fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6351fd4e5da5Sopenharmony_ci    4, false),
6352fd4e5da5Sopenharmony_ci  // Test case 5: Do not merge consecutive sdiv
6353fd4e5da5Sopenharmony_ci  // (4 / x) / 2
6354fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6355fd4e5da5Sopenharmony_ci    Header() +
6356fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6357fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6358fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6359fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6360fd4e5da5Sopenharmony_ci      "%3 = OpSDiv %int %int_4 %2\n" +
6361fd4e5da5Sopenharmony_ci      "%4 = OpSDiv %int %3 %int_2\n" +
6362fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6363fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6364fd4e5da5Sopenharmony_ci    4, false),
6365fd4e5da5Sopenharmony_ci  // Test case 6: Do not merge consecutive sdiv
6366fd4e5da5Sopenharmony_ci  // (x / 4) / 2
6367fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6368fd4e5da5Sopenharmony_ci    Header() +
6369fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6370fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6371fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6372fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6373fd4e5da5Sopenharmony_ci      "%3 = OpSDiv %int %2 %int_4\n" +
6374fd4e5da5Sopenharmony_ci      "%4 = OpSDiv %int %3 %int_2\n" +
6375fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6376fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6377fd4e5da5Sopenharmony_ci    4, false),
6378fd4e5da5Sopenharmony_ci  // Test case 7: Do not merge sdiv of imul
6379fd4e5da5Sopenharmony_ci  // 4 / (2 * x)
6380fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6381fd4e5da5Sopenharmony_ci    Header() +
6382fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6383fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6384fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6385fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6386fd4e5da5Sopenharmony_ci      "%3 = OpIMul %int %int_2 %2\n" +
6387fd4e5da5Sopenharmony_ci      "%4 = OpSDiv %int %int_4 %3\n" +
6388fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6389fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6390fd4e5da5Sopenharmony_ci    4, false),
6391fd4e5da5Sopenharmony_ci  // Test case 8: Do not merge sdiv of imul
6392fd4e5da5Sopenharmony_ci  // 4 / (x * 2)
6393fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6394fd4e5da5Sopenharmony_ci    Header() +
6395fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6396fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6397fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6398fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6399fd4e5da5Sopenharmony_ci      "%3 = OpIMul %int %2 %int_2\n" +
6400fd4e5da5Sopenharmony_ci      "%4 = OpSDiv %int %int_4 %3\n" +
6401fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6402fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6403fd4e5da5Sopenharmony_ci    4, false),
6404fd4e5da5Sopenharmony_ci  // Test case 9: Do not merge sdiv of imul
6405fd4e5da5Sopenharmony_ci  // (4 * x) / 2
6406fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6407fd4e5da5Sopenharmony_ci    Header() +
6408fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6409fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6410fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6411fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6412fd4e5da5Sopenharmony_ci      "%3 = OpIMul %int %int_4 %2\n" +
6413fd4e5da5Sopenharmony_ci      "%4 = OpSDiv %int %3 %int_2\n" +
6414fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6415fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6416fd4e5da5Sopenharmony_ci    4, false),
6417fd4e5da5Sopenharmony_ci  // Test case 10: Do not merge sdiv of imul
6418fd4e5da5Sopenharmony_ci  // (x * 4) / 2
6419fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6420fd4e5da5Sopenharmony_ci    Header() +
6421fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6422fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6423fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6424fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6425fd4e5da5Sopenharmony_ci      "%3 = OpIMul %int %2 %int_4\n" +
6426fd4e5da5Sopenharmony_ci      "%4 = OpSDiv %int %3 %int_2\n" +
6427fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6428fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6429fd4e5da5Sopenharmony_ci    4, false),
6430fd4e5da5Sopenharmony_ci  // Test case 11: Do not merge sdiv of snegate.  If %2 is INT_MIN, then the
6431fd4e5da5Sopenharmony_ci  // sign of %3 will be the same as %2.  This cannot be accounted for in OpSDiv.
6432fd4e5da5Sopenharmony_ci  // Specifically, (-INT_MIN) / 2 != INT_MIN / -2.
6433fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6434fd4e5da5Sopenharmony_ci    Header() +
6435fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6436fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6437fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6438fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6439fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %int %2\n" +
6440fd4e5da5Sopenharmony_ci      "%4 = OpSDiv %int %3 %int_2\n" +
6441fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6442fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6443fd4e5da5Sopenharmony_ci    4, false),
6444fd4e5da5Sopenharmony_ci  // Test case 12: Do not merge sdiv of snegate.  If %2 is INT_MIN, then the
6445fd4e5da5Sopenharmony_ci  // sign of %3 will be the same as %2.  This cannot be accounted for in OpSDiv.
6446fd4e5da5Sopenharmony_ci  // Specifically, 2 / (-INT_MIN) != -2 / INT_MIN.
6447fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6448fd4e5da5Sopenharmony_ci    Header() +
6449fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6450fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6451fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6452fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6453fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %int %2\n" +
6454fd4e5da5Sopenharmony_ci      "%4 = OpSDiv %int %int_2 %3\n" +
6455fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6456fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6457fd4e5da5Sopenharmony_ci    4, false),
6458fd4e5da5Sopenharmony_ci  // Test case 13: Don't merge
6459fd4e5da5Sopenharmony_ci  // (x / {null}) / {null}
6460fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6461fd4e5da5Sopenharmony_ci    Header() +
6462fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6463fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6464fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_v2float Function\n" +
6465fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6466fd4e5da5Sopenharmony_ci      "%3 = OpFDiv %float %2 %v2float_null\n" +
6467fd4e5da5Sopenharmony_ci      "%4 = OpFDiv %float %3 %v2float_null\n" +
6468fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6469fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6470fd4e5da5Sopenharmony_ci    4, false),
6471fd4e5da5Sopenharmony_ci  // Test case 14: merge fmul of fdiv
6472fd4e5da5Sopenharmony_ci  // (y * x) / x = y
6473fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6474fd4e5da5Sopenharmony_ci    Header() +
6475fd4e5da5Sopenharmony_ci        "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6476fd4e5da5Sopenharmony_ci        "; CHECK: [[ldx:%\\w+]] = OpLoad [[float]]\n" +
6477fd4e5da5Sopenharmony_ci        "; CHECK: [[ldy:%\\w+]] = OpLoad [[float]] [[y:%\\w+]]\n" +
6478fd4e5da5Sopenharmony_ci        "; CHECK: %5 = OpCopyObject [[float]] [[ldy]]\n" +
6479fd4e5da5Sopenharmony_ci        "%main = OpFunction %void None %void_func\n" +
6480fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
6481fd4e5da5Sopenharmony_ci        "%x = OpVariable %_ptr_float Function\n" +
6482fd4e5da5Sopenharmony_ci        "%y = OpVariable %_ptr_float Function\n" +
6483fd4e5da5Sopenharmony_ci        "%2 = OpLoad %float %x\n" +
6484fd4e5da5Sopenharmony_ci        "%3 = OpLoad %float %y\n" +
6485fd4e5da5Sopenharmony_ci        "%4 = OpFMul %float %3 %2\n" +
6486fd4e5da5Sopenharmony_ci        "%5 = OpFDiv %float %4 %2\n" +
6487fd4e5da5Sopenharmony_ci        "OpReturn\n" +
6488fd4e5da5Sopenharmony_ci        "OpFunctionEnd\n",
6489fd4e5da5Sopenharmony_ci    5, true),
6490fd4e5da5Sopenharmony_ci  // Test case 15: merge fmul of fdiv
6491fd4e5da5Sopenharmony_ci  // (x * y) / x = y
6492fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6493fd4e5da5Sopenharmony_ci    Header() +
6494fd4e5da5Sopenharmony_ci        "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6495fd4e5da5Sopenharmony_ci        "; CHECK: [[ldx:%\\w+]] = OpLoad [[float]]\n" +
6496fd4e5da5Sopenharmony_ci        "; CHECK: [[ldy:%\\w+]] = OpLoad [[float]] [[y:%\\w+]]\n" +
6497fd4e5da5Sopenharmony_ci        "; CHECK: %5 = OpCopyObject [[float]] [[ldy]]\n" +
6498fd4e5da5Sopenharmony_ci        "%main = OpFunction %void None %void_func\n" +
6499fd4e5da5Sopenharmony_ci        "%main_lab = OpLabel\n" +
6500fd4e5da5Sopenharmony_ci        "%x = OpVariable %_ptr_float Function\n" +
6501fd4e5da5Sopenharmony_ci        "%y = OpVariable %_ptr_float Function\n" +
6502fd4e5da5Sopenharmony_ci        "%2 = OpLoad %float %x\n" +
6503fd4e5da5Sopenharmony_ci        "%3 = OpLoad %float %y\n" +
6504fd4e5da5Sopenharmony_ci        "%4 = OpFMul %float %2 %3\n" +
6505fd4e5da5Sopenharmony_ci        "%5 = OpFDiv %float %4 %2\n" +
6506fd4e5da5Sopenharmony_ci        "OpReturn\n" +
6507fd4e5da5Sopenharmony_ci        "OpFunctionEnd\n",
6508fd4e5da5Sopenharmony_ci    5, true),
6509fd4e5da5Sopenharmony_ci  // Test case 16: Do not merge udiv of snegate
6510fd4e5da5Sopenharmony_ci  // (-x) / 2u
6511fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6512fd4e5da5Sopenharmony_ci    Header() +
6513fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6514fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6515fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_uint Function\n" +
6516fd4e5da5Sopenharmony_ci      "%2 = OpLoad %uint %var\n" +
6517fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %uint %2\n" +
6518fd4e5da5Sopenharmony_ci      "%4 = OpUDiv %uint %3 %uint_2\n" +
6519fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6520fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6521fd4e5da5Sopenharmony_ci    4, false),
6522fd4e5da5Sopenharmony_ci  // Test case 17: Do not merge udiv of snegate
6523fd4e5da5Sopenharmony_ci  // 2u / (-x)
6524fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6525fd4e5da5Sopenharmony_ci    Header() +
6526fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6527fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6528fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_uint Function\n" +
6529fd4e5da5Sopenharmony_ci      "%2 = OpLoad %uint %var\n" +
6530fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %uint %2\n" +
6531fd4e5da5Sopenharmony_ci      "%4 = OpUDiv %uint %uint_2 %3\n" +
6532fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6533fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6534fd4e5da5Sopenharmony_ci    4, false)
6535fd4e5da5Sopenharmony_ci));
6536fd4e5da5Sopenharmony_ci
6537fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(MergeAddTest, MatchingInstructionFoldingTest,
6538fd4e5da5Sopenharmony_ci::testing::Values(
6539fd4e5da5Sopenharmony_ci  // Test case 0: merge add of negate
6540fd4e5da5Sopenharmony_ci  // (-x) + 2 = 2 - x
6541fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6542fd4e5da5Sopenharmony_ci    Header() +
6543fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6544fd4e5da5Sopenharmony_ci      "; CHECK: [[float_2:%\\w+]] = OpConstant [[float]] 2\n" +
6545fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6546fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_2]] [[ld]]\n" +
6547fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6548fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6549fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6550fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6551fd4e5da5Sopenharmony_ci      "%3 = OpFNegate %float %2\n" +
6552fd4e5da5Sopenharmony_ci      "%4 = OpFAdd %float %3 %float_2\n" +
6553fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6554fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6555fd4e5da5Sopenharmony_ci    4, true),
6556fd4e5da5Sopenharmony_ci  // Test case 1: merge add of negate
6557fd4e5da5Sopenharmony_ci  // 2 + (-x) = 2 - x
6558fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6559fd4e5da5Sopenharmony_ci    Header() +
6560fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6561fd4e5da5Sopenharmony_ci      "; CHECK: [[float_2:%\\w+]] = OpConstant [[float]] 2\n" +
6562fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6563fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_2]] [[ld]]\n" +
6564fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6565fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6566fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6567fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6568fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %float %2\n" +
6569fd4e5da5Sopenharmony_ci      "%4 = OpIAdd %float %float_2 %3\n" +
6570fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6571fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6572fd4e5da5Sopenharmony_ci    4, true),
6573fd4e5da5Sopenharmony_ci  // Test case 2: merge add of negate
6574fd4e5da5Sopenharmony_ci  // (-x) + 2 = 2 - x
6575fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6576fd4e5da5Sopenharmony_ci    Header() +
6577fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64 1\n" +
6578fd4e5da5Sopenharmony_ci      "; CHECK: [[long_2:%\\w+]] = OpConstant [[long]] 2\n" +
6579fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
6580fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[long]] [[long_2]] [[ld]]\n" +
6581fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6582fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6583fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
6584fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
6585fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %long %2\n" +
6586fd4e5da5Sopenharmony_ci      "%4 = OpIAdd %long %3 %long_2\n" +
6587fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6588fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6589fd4e5da5Sopenharmony_ci    4, true),
6590fd4e5da5Sopenharmony_ci  // Test case 3: merge add of negate
6591fd4e5da5Sopenharmony_ci  // 2 + (-x) = 2 - x
6592fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6593fd4e5da5Sopenharmony_ci    Header() +
6594fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64 1\n" +
6595fd4e5da5Sopenharmony_ci      "; CHECK: [[long_2:%\\w+]] = OpConstant [[long]] 2\n" +
6596fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
6597fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[long]] [[long_2]] [[ld]]\n" +
6598fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6599fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6600fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
6601fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
6602fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %long %2\n" +
6603fd4e5da5Sopenharmony_ci      "%4 = OpIAdd %long %long_2 %3\n" +
6604fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6605fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6606fd4e5da5Sopenharmony_ci    4, true),
6607fd4e5da5Sopenharmony_ci  // Test case 4: merge add of subtract
6608fd4e5da5Sopenharmony_ci  // (x - 1) + 2 = x + 1
6609fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6610fd4e5da5Sopenharmony_ci    Header() +
6611fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6612fd4e5da5Sopenharmony_ci      "; CHECK: [[float_1:%\\w+]] = OpConstant [[float]] 1\n" +
6613fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6614fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFAdd [[float]] [[ld]] [[float_1]]\n" +
6615fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6616fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6617fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6618fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6619fd4e5da5Sopenharmony_ci      "%3 = OpFSub %float %2 %float_1\n" +
6620fd4e5da5Sopenharmony_ci      "%4 = OpFAdd %float %3 %float_2\n" +
6621fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6622fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6623fd4e5da5Sopenharmony_ci    4, true),
6624fd4e5da5Sopenharmony_ci  // Test case 5: merge add of subtract
6625fd4e5da5Sopenharmony_ci  // (1 - x) + 2 = 3 - x
6626fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6627fd4e5da5Sopenharmony_ci    Header() +
6628fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6629fd4e5da5Sopenharmony_ci      "; CHECK: [[float_3:%\\w+]] = OpConstant [[float]] 3\n" +
6630fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6631fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_3]] [[ld]]\n" +
6632fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6633fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6634fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6635fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6636fd4e5da5Sopenharmony_ci      "%3 = OpFSub %float %float_1 %2\n" +
6637fd4e5da5Sopenharmony_ci      "%4 = OpFAdd %float %3 %float_2\n" +
6638fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6639fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6640fd4e5da5Sopenharmony_ci    4, true),
6641fd4e5da5Sopenharmony_ci  // Test case 6: merge add of subtract
6642fd4e5da5Sopenharmony_ci  // 2 + (x - 1) = x + 1
6643fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6644fd4e5da5Sopenharmony_ci    Header() +
6645fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6646fd4e5da5Sopenharmony_ci      "; CHECK: [[float_1:%\\w+]] = OpConstant [[float]] 1\n" +
6647fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6648fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFAdd [[float]] [[ld]] [[float_1]]\n" +
6649fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6650fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6651fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6652fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6653fd4e5da5Sopenharmony_ci      "%3 = OpFSub %float %2 %float_1\n" +
6654fd4e5da5Sopenharmony_ci      "%4 = OpFAdd %float %float_2 %3\n" +
6655fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6656fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6657fd4e5da5Sopenharmony_ci    4, true),
6658fd4e5da5Sopenharmony_ci  // Test case 7: merge add of subtract
6659fd4e5da5Sopenharmony_ci  // 2 + (1 - x) = 3 - x
6660fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6661fd4e5da5Sopenharmony_ci    Header() +
6662fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6663fd4e5da5Sopenharmony_ci      "; CHECK: [[float_3:%\\w+]] = OpConstant [[float]] 3\n" +
6664fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6665fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_3]] [[ld]]\n" +
6666fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6667fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6668fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6669fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6670fd4e5da5Sopenharmony_ci      "%3 = OpFSub %float %float_1 %2\n" +
6671fd4e5da5Sopenharmony_ci      "%4 = OpFAdd %float %float_2 %3\n" +
6672fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6673fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6674fd4e5da5Sopenharmony_ci    4, true),
6675fd4e5da5Sopenharmony_ci  // Test case 8: merge add of add
6676fd4e5da5Sopenharmony_ci  // (x + 1) + 2 = x + 3
6677fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6678fd4e5da5Sopenharmony_ci    Header() +
6679fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6680fd4e5da5Sopenharmony_ci      "; CHECK: [[float_3:%\\w+]] = OpConstant [[float]] 3\n" +
6681fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6682fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFAdd [[float]] [[ld]] [[float_3]]\n" +
6683fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6684fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6685fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6686fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6687fd4e5da5Sopenharmony_ci      "%3 = OpFAdd %float %2 %float_1\n" +
6688fd4e5da5Sopenharmony_ci      "%4 = OpFAdd %float %3 %float_2\n" +
6689fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6690fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6691fd4e5da5Sopenharmony_ci    4, true),
6692fd4e5da5Sopenharmony_ci  // Test case 9: merge add of add
6693fd4e5da5Sopenharmony_ci  // (1 + x) + 2 = 3 + x
6694fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6695fd4e5da5Sopenharmony_ci    Header() +
6696fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6697fd4e5da5Sopenharmony_ci      "; CHECK: [[float_3:%\\w+]] = OpConstant [[float]] 3\n" +
6698fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6699fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFAdd [[float]] [[ld]] [[float_3]]\n" +
6700fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6701fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6702fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6703fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6704fd4e5da5Sopenharmony_ci      "%3 = OpFAdd %float %float_1 %2\n" +
6705fd4e5da5Sopenharmony_ci      "%4 = OpFAdd %float %3 %float_2\n" +
6706fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6707fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6708fd4e5da5Sopenharmony_ci    4, true),
6709fd4e5da5Sopenharmony_ci  // Test case 10: merge add of add
6710fd4e5da5Sopenharmony_ci  // 2 + (x + 1) = x + 1
6711fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6712fd4e5da5Sopenharmony_ci    Header() +
6713fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6714fd4e5da5Sopenharmony_ci      "; CHECK: [[float_3:%\\w+]] = OpConstant [[float]] 3\n" +
6715fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6716fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFAdd [[float]] [[ld]] [[float_3]]\n" +
6717fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6718fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6719fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6720fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6721fd4e5da5Sopenharmony_ci      "%3 = OpFAdd %float %2 %float_1\n" +
6722fd4e5da5Sopenharmony_ci      "%4 = OpFAdd %float %float_2 %3\n" +
6723fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6724fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6725fd4e5da5Sopenharmony_ci    4, true),
6726fd4e5da5Sopenharmony_ci  // Test case 11: merge add of add
6727fd4e5da5Sopenharmony_ci  // 2 + (1 + x) = 3 - x
6728fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6729fd4e5da5Sopenharmony_ci    Header() +
6730fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6731fd4e5da5Sopenharmony_ci      "; CHECK: [[float_3:%\\w+]] = OpConstant [[float]] 3\n" +
6732fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6733fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFAdd [[float]] [[ld]] [[float_3]]\n" +
6734fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6735fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6736fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6737fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6738fd4e5da5Sopenharmony_ci      "%3 = OpFAdd %float %float_1 %2\n" +
6739fd4e5da5Sopenharmony_ci      "%4 = OpFAdd %float %float_2 %3\n" +
6740fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6741fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6742fd4e5da5Sopenharmony_ci    4, true),
6743fd4e5da5Sopenharmony_ci  // Test case 12: fold overflowing signed 32 bit iadds
6744fd4e5da5Sopenharmony_ci  // (x + int_max) + 1 = x + int_min
6745fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6746fd4e5da5Sopenharmony_ci    Header() +
6747fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32\n" +
6748fd4e5da5Sopenharmony_ci      "; CHECK: [[int_min:%\\w+]] = OpConstant [[int]] -2147483648\n" +
6749fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int]]\n" +
6750fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIAdd [[int]] [[ld]] [[int_min]]\n" +
6751fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6752fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6753fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6754fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6755fd4e5da5Sopenharmony_ci      "%3 = OpIAdd %int %2 %int_max\n" +
6756fd4e5da5Sopenharmony_ci      "%4 = OpIAdd %int %3 %int_1\n" +
6757fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6758fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6759fd4e5da5Sopenharmony_ci    4, true),
6760fd4e5da5Sopenharmony_ci  // Test case 13: fold overflowing signed 64 bit iadds
6761fd4e5da5Sopenharmony_ci  // (x + long_max) + 1 = x + long_min
6762fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6763fd4e5da5Sopenharmony_ci    Header() +
6764fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64\n" +
6765fd4e5da5Sopenharmony_ci      "; CHECK: [[long_min:%\\w+]] = OpConstant [[long]] -9223372036854775808\n" +
6766fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
6767fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIAdd [[long]] [[ld]] [[long_min]]\n" +
6768fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6769fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6770fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
6771fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
6772fd4e5da5Sopenharmony_ci      "%3 = OpIAdd %long %2 %long_max\n" +
6773fd4e5da5Sopenharmony_ci      "%4 = OpIAdd %long %3 %long_1\n" +
6774fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6775fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6776fd4e5da5Sopenharmony_ci    4, true),
6777fd4e5da5Sopenharmony_ci  // Test case 14: fold overflowing 32 bit unsigned iadds
6778fd4e5da5Sopenharmony_ci  // (x + uint_max) + 2 = x + 1
6779fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6780fd4e5da5Sopenharmony_ci    Header() +
6781fd4e5da5Sopenharmony_ci      "; CHECK: [[uint:%\\w+]] = OpTypeInt 32 0\n" +
6782fd4e5da5Sopenharmony_ci      "; CHECK: [[uint_1:%\\w+]] = OpConstant [[uint]] 1\n" +
6783fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[uint]]\n" +
6784fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIAdd [[uint]] [[ld]] [[uint_1]]\n" +
6785fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6786fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6787fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_uint Function\n" +
6788fd4e5da5Sopenharmony_ci      "%2 = OpLoad %uint %var\n" +
6789fd4e5da5Sopenharmony_ci      "%3 = OpIAdd %uint %2 %uint_max\n" +
6790fd4e5da5Sopenharmony_ci      "%4 = OpIAdd %uint %3 %uint_2\n" +
6791fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6792fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6793fd4e5da5Sopenharmony_ci    4, true),
6794fd4e5da5Sopenharmony_ci  // Test case 15: fold overflowing 64 bit unsigned iadds
6795fd4e5da5Sopenharmony_ci  // (x + ulong_max) + 2 = x + 1
6796fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6797fd4e5da5Sopenharmony_ci    Header() +
6798fd4e5da5Sopenharmony_ci      "; CHECK: [[ulong:%\\w+]] = OpTypeInt 64 0\n" +
6799fd4e5da5Sopenharmony_ci      "; CHECK: [[ulong_1:%\\w+]] = OpConstant [[ulong]] 1\n" +
6800fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[ulong]]\n" +
6801fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIAdd [[ulong]] [[ld]] [[ulong_1]]\n" +
6802fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6803fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6804fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_ulong Function\n" +
6805fd4e5da5Sopenharmony_ci      "%2 = OpLoad %ulong %var\n" +
6806fd4e5da5Sopenharmony_ci      "%3 = OpIAdd %ulong %2 %ulong_max\n" +
6807fd4e5da5Sopenharmony_ci      "%4 = OpIAdd %ulong %3 %ulong_2\n" +
6808fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6809fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6810fd4e5da5Sopenharmony_ci    4, true),
6811fd4e5da5Sopenharmony_ci  // Test case 16: fold underflowing signed 32 bit iadds
6812fd4e5da5Sopenharmony_ci  // (x + int_min) + (-1) = x + int_max
6813fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6814fd4e5da5Sopenharmony_ci    Header() +
6815fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32\n" +
6816fd4e5da5Sopenharmony_ci      "; CHECK: [[int_max:%\\w+]] = OpConstant [[int]] 2147483647\n" +
6817fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int]]\n" +
6818fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIAdd [[int]] [[ld]] [[int_max]]\n" +
6819fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6820fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6821fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
6822fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
6823fd4e5da5Sopenharmony_ci      "%3 = OpIAdd %int %2 %int_min\n" +
6824fd4e5da5Sopenharmony_ci      "%4 = OpIAdd %int %3 %int_n1\n" +
6825fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6826fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6827fd4e5da5Sopenharmony_ci    4, true),
6828fd4e5da5Sopenharmony_ci  // Test case 17: fold underflowing signed 64 bit iadds
6829fd4e5da5Sopenharmony_ci  // (x + long_min) + (-1) = x + long_max
6830fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6831fd4e5da5Sopenharmony_ci    Header() +
6832fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64\n" +
6833fd4e5da5Sopenharmony_ci      "; CHECK: [[long_max:%\\w+]] = OpConstant [[long]] 9223372036854775807\n" +
6834fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
6835fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIAdd [[long]] [[ld]] [[long_max]]\n" +
6836fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6837fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6838fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
6839fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
6840fd4e5da5Sopenharmony_ci      "%3 = OpIAdd %long %2 %long_min\n" +
6841fd4e5da5Sopenharmony_ci      "%4 = OpIAdd %long %3 %long_n1\n" +
6842fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6843fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6844fd4e5da5Sopenharmony_ci    4, true)
6845fd4e5da5Sopenharmony_ci));
6846fd4e5da5Sopenharmony_ci
6847fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(MergeGenericAddSub, MatchingInstructionFoldingTest,
6848fd4e5da5Sopenharmony_ci::testing::Values(
6849fd4e5da5Sopenharmony_ci    // Test case 0: merge of add of sub
6850fd4e5da5Sopenharmony_ci    // (a - b) + b => a
6851fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
6852fd4e5da5Sopenharmony_ci      Header() +
6853fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6854fd4e5da5Sopenharmony_ci      "; CHECK: %6 = OpCopyObject [[float]] %3\n" +
6855fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6856fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6857fd4e5da5Sopenharmony_ci      "%var0 = OpVariable %_ptr_float Function\n" +
6858fd4e5da5Sopenharmony_ci      "%var1 = OpVariable %_ptr_float Function\n" +
6859fd4e5da5Sopenharmony_ci      "%3 = OpLoad %float %var0\n" +
6860fd4e5da5Sopenharmony_ci      "%4 = OpLoad %float %var1\n" +
6861fd4e5da5Sopenharmony_ci      "%5 = OpFSub %float %3 %4\n" +
6862fd4e5da5Sopenharmony_ci      "%6 = OpFAdd %float %5 %4\n" +
6863fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6864fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6865fd4e5da5Sopenharmony_ci      6, true),
6866fd4e5da5Sopenharmony_ci  // Test case 1: merge of add of sub
6867fd4e5da5Sopenharmony_ci  // b + (a - b) => a
6868fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6869fd4e5da5Sopenharmony_ci    Header() +
6870fd4e5da5Sopenharmony_ci    "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6871fd4e5da5Sopenharmony_ci    "; CHECK: %6 = OpCopyObject [[float]] %3\n" +
6872fd4e5da5Sopenharmony_ci    "%main = OpFunction %void None %void_func\n" +
6873fd4e5da5Sopenharmony_ci    "%main_lab = OpLabel\n" +
6874fd4e5da5Sopenharmony_ci    "%var0 = OpVariable %_ptr_float Function\n" +
6875fd4e5da5Sopenharmony_ci    "%var1 = OpVariable %_ptr_float Function\n" +
6876fd4e5da5Sopenharmony_ci    "%3 = OpLoad %float %var0\n" +
6877fd4e5da5Sopenharmony_ci    "%4 = OpLoad %float %var1\n" +
6878fd4e5da5Sopenharmony_ci    "%5 = OpFSub %float %3 %4\n" +
6879fd4e5da5Sopenharmony_ci    "%6 = OpFAdd %float %4 %5\n" +
6880fd4e5da5Sopenharmony_ci    "OpReturn\n" +
6881fd4e5da5Sopenharmony_ci    "OpFunctionEnd\n",
6882fd4e5da5Sopenharmony_ci    6, true)
6883fd4e5da5Sopenharmony_ci));
6884fd4e5da5Sopenharmony_ci
6885fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FactorAddMul, MatchingInstructionFoldingTest,
6886fd4e5da5Sopenharmony_ci::testing::Values(
6887fd4e5da5Sopenharmony_ci    // Test case 0: factor of add of muls
6888fd4e5da5Sopenharmony_ci    // (a * b) + (a * c) => a * (b + c)
6889fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
6890fd4e5da5Sopenharmony_ci      Header() +
6891fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6892fd4e5da5Sopenharmony_ci      "; CHECK: [[newadd:%\\w+]] = OpFAdd [[float]] %4 %5\n" +
6893fd4e5da5Sopenharmony_ci      "; CHECK: %9 = OpFMul [[float]] %6 [[newadd]]\n" +
6894fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6895fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6896fd4e5da5Sopenharmony_ci      "%var0 = OpVariable %_ptr_float Function\n" +
6897fd4e5da5Sopenharmony_ci      "%var1 = OpVariable %_ptr_float Function\n" +
6898fd4e5da5Sopenharmony_ci      "%var2 = OpVariable %_ptr_float Function\n" +
6899fd4e5da5Sopenharmony_ci      "%4 = OpLoad %float %var0\n" +
6900fd4e5da5Sopenharmony_ci      "%5 = OpLoad %float %var1\n" +
6901fd4e5da5Sopenharmony_ci      "%6 = OpLoad %float %var2\n" +
6902fd4e5da5Sopenharmony_ci      "%7 = OpFMul %float %6 %4\n" +
6903fd4e5da5Sopenharmony_ci      "%8 = OpFMul %float %6 %5\n" +
6904fd4e5da5Sopenharmony_ci      "%9 = OpFAdd %float %7 %8\n" +
6905fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6906fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6907fd4e5da5Sopenharmony_ci      9, true),
6908fd4e5da5Sopenharmony_ci  // Test case 1: factor of add of muls
6909fd4e5da5Sopenharmony_ci  // (b * a) + (a * c) => a * (b + c)
6910fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6911fd4e5da5Sopenharmony_ci    Header() +
6912fd4e5da5Sopenharmony_ci    "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6913fd4e5da5Sopenharmony_ci    "; CHECK: [[newadd:%\\w+]] = OpFAdd [[float]] %4 %5\n" +
6914fd4e5da5Sopenharmony_ci    "; CHECK: %9 = OpFMul [[float]] %6 [[newadd]]\n" +
6915fd4e5da5Sopenharmony_ci    "%main = OpFunction %void None %void_func\n" +
6916fd4e5da5Sopenharmony_ci    "%main_lab = OpLabel\n" +
6917fd4e5da5Sopenharmony_ci    "%var0 = OpVariable %_ptr_float Function\n" +
6918fd4e5da5Sopenharmony_ci    "%var1 = OpVariable %_ptr_float Function\n" +
6919fd4e5da5Sopenharmony_ci    "%var2 = OpVariable %_ptr_float Function\n" +
6920fd4e5da5Sopenharmony_ci    "%4 = OpLoad %float %var0\n" +
6921fd4e5da5Sopenharmony_ci    "%5 = OpLoad %float %var1\n" +
6922fd4e5da5Sopenharmony_ci    "%6 = OpLoad %float %var2\n" +
6923fd4e5da5Sopenharmony_ci    "%7 = OpFMul %float %4 %6\n" +
6924fd4e5da5Sopenharmony_ci    "%8 = OpFMul %float %6 %5\n" +
6925fd4e5da5Sopenharmony_ci    "%9 = OpFAdd %float %7 %8\n" +
6926fd4e5da5Sopenharmony_ci    "OpReturn\n" +
6927fd4e5da5Sopenharmony_ci    "OpFunctionEnd\n",
6928fd4e5da5Sopenharmony_ci    9, true),
6929fd4e5da5Sopenharmony_ci  // Test case 2: factor of add of muls
6930fd4e5da5Sopenharmony_ci  // (a * b) + (c * a) => a * (b + c)
6931fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6932fd4e5da5Sopenharmony_ci    Header() +
6933fd4e5da5Sopenharmony_ci    "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6934fd4e5da5Sopenharmony_ci    "; CHECK: [[newadd:%\\w+]] = OpFAdd [[float]] %4 %5\n" +
6935fd4e5da5Sopenharmony_ci    "; CHECK: %9 = OpFMul [[float]] %6 [[newadd]]\n" +
6936fd4e5da5Sopenharmony_ci    "%main = OpFunction %void None %void_func\n" +
6937fd4e5da5Sopenharmony_ci    "%main_lab = OpLabel\n" +
6938fd4e5da5Sopenharmony_ci    "%var0 = OpVariable %_ptr_float Function\n" +
6939fd4e5da5Sopenharmony_ci    "%var1 = OpVariable %_ptr_float Function\n" +
6940fd4e5da5Sopenharmony_ci    "%var2 = OpVariable %_ptr_float Function\n" +
6941fd4e5da5Sopenharmony_ci    "%4 = OpLoad %float %var0\n" +
6942fd4e5da5Sopenharmony_ci    "%5 = OpLoad %float %var1\n" +
6943fd4e5da5Sopenharmony_ci    "%6 = OpLoad %float %var2\n" +
6944fd4e5da5Sopenharmony_ci    "%7 = OpFMul %float %6 %4\n" +
6945fd4e5da5Sopenharmony_ci    "%8 = OpFMul %float %5 %6\n" +
6946fd4e5da5Sopenharmony_ci    "%9 = OpFAdd %float %7 %8\n" +
6947fd4e5da5Sopenharmony_ci    "OpReturn\n" +
6948fd4e5da5Sopenharmony_ci    "OpFunctionEnd\n",
6949fd4e5da5Sopenharmony_ci    9, true),
6950fd4e5da5Sopenharmony_ci  // Test case 3: factor of add of muls
6951fd4e5da5Sopenharmony_ci  // (b * a) + (c * a) => a * (b + c)
6952fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6953fd4e5da5Sopenharmony_ci    Header() +
6954fd4e5da5Sopenharmony_ci    "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6955fd4e5da5Sopenharmony_ci    "; CHECK: [[newadd:%\\w+]] = OpFAdd [[float]] %4 %5\n" +
6956fd4e5da5Sopenharmony_ci    "; CHECK: %9 = OpFMul [[float]] %6 [[newadd]]\n" +
6957fd4e5da5Sopenharmony_ci    "%main = OpFunction %void None %void_func\n" +
6958fd4e5da5Sopenharmony_ci    "%main_lab = OpLabel\n" +
6959fd4e5da5Sopenharmony_ci    "%var0 = OpVariable %_ptr_float Function\n" +
6960fd4e5da5Sopenharmony_ci    "%var1 = OpVariable %_ptr_float Function\n" +
6961fd4e5da5Sopenharmony_ci    "%var2 = OpVariable %_ptr_float Function\n" +
6962fd4e5da5Sopenharmony_ci    "%4 = OpLoad %float %var0\n" +
6963fd4e5da5Sopenharmony_ci    "%5 = OpLoad %float %var1\n" +
6964fd4e5da5Sopenharmony_ci    "%6 = OpLoad %float %var2\n" +
6965fd4e5da5Sopenharmony_ci    "%7 = OpFMul %float %4 %6\n" +
6966fd4e5da5Sopenharmony_ci    "%8 = OpFMul %float %5 %6\n" +
6967fd4e5da5Sopenharmony_ci    "%9 = OpFAdd %float %7 %8\n" +
6968fd4e5da5Sopenharmony_ci    "OpReturn\n" +
6969fd4e5da5Sopenharmony_ci    "OpFunctionEnd\n",
6970fd4e5da5Sopenharmony_ci    9, true)
6971fd4e5da5Sopenharmony_ci));
6972fd4e5da5Sopenharmony_ci
6973fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(MergeSubTest, MatchingInstructionFoldingTest,
6974fd4e5da5Sopenharmony_ci::testing::Values(
6975fd4e5da5Sopenharmony_ci  // Test case 0: merge sub of negate
6976fd4e5da5Sopenharmony_ci  // (-x) - 2 = -2 - x
6977fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6978fd4e5da5Sopenharmony_ci    Header() +
6979fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6980fd4e5da5Sopenharmony_ci      "; CHECK: [[float_n2:%\\w+]] = OpConstant [[float]] -2{{[[:space:]]}}\n" +
6981fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6982fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_n2]] [[ld]]\n" +
6983fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
6984fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
6985fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
6986fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
6987fd4e5da5Sopenharmony_ci      "%3 = OpFNegate %float %2\n" +
6988fd4e5da5Sopenharmony_ci      "%4 = OpFSub %float %3 %float_2\n" +
6989fd4e5da5Sopenharmony_ci      "OpReturn\n" +
6990fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
6991fd4e5da5Sopenharmony_ci    4, true),
6992fd4e5da5Sopenharmony_ci  // Test case 1: merge sub of negate
6993fd4e5da5Sopenharmony_ci  // 2 - (-x) = x + 2
6994fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
6995fd4e5da5Sopenharmony_ci    Header() +
6996fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
6997fd4e5da5Sopenharmony_ci      "; CHECK: [[float_2:%\\w+]] = OpConstant [[float]] 2\n" +
6998fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
6999fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFAdd [[float]] [[ld]] [[float_2]]\n" +
7000fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7001fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7002fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
7003fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
7004fd4e5da5Sopenharmony_ci      "%3 = OpFNegate %float %2\n" +
7005fd4e5da5Sopenharmony_ci      "%4 = OpFSub %float %float_2 %3\n" +
7006fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7007fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7008fd4e5da5Sopenharmony_ci    4, true),
7009fd4e5da5Sopenharmony_ci  // Test case 2: merge sub of negate
7010fd4e5da5Sopenharmony_ci  // (-x) - 2 = -2 - x
7011fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7012fd4e5da5Sopenharmony_ci    Header() +
7013fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64 1\n" +
7014fd4e5da5Sopenharmony_ci      "; CHECK: [[long_n2:%\\w+]] = OpConstant [[long]] -2{{[[:space:]]}}\n" +
7015fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
7016fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[long]] [[long_n2]] [[ld]]\n" +
7017fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7018fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7019fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
7020fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
7021fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %long %2\n" +
7022fd4e5da5Sopenharmony_ci      "%4 = OpISub %long %3 %long_2\n" +
7023fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7024fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7025fd4e5da5Sopenharmony_ci    4, true),
7026fd4e5da5Sopenharmony_ci  // Test case 3: merge sub of negate
7027fd4e5da5Sopenharmony_ci  // 2 - (-x) = x + 2
7028fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7029fd4e5da5Sopenharmony_ci    Header() +
7030fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64 1\n" +
7031fd4e5da5Sopenharmony_ci      "; CHECK: [[long_2:%\\w+]] = OpConstant [[long]] 2\n" +
7032fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
7033fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIAdd [[long]] [[ld]] [[long_2]]\n" +
7034fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7035fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7036fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
7037fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
7038fd4e5da5Sopenharmony_ci      "%3 = OpSNegate %long %2\n" +
7039fd4e5da5Sopenharmony_ci      "%4 = OpISub %long %long_2 %3\n" +
7040fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7041fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7042fd4e5da5Sopenharmony_ci    4, true),
7043fd4e5da5Sopenharmony_ci  // Test case 4: merge add of subtract
7044fd4e5da5Sopenharmony_ci  // (x + 2) - 1 = x + 1
7045fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7046fd4e5da5Sopenharmony_ci    Header() +
7047fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7048fd4e5da5Sopenharmony_ci      "; CHECK: [[float_1:%\\w+]] = OpConstant [[float]] 1\n" +
7049fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
7050fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFAdd [[float]] [[ld]] [[float_1]]\n" +
7051fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7052fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7053fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
7054fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
7055fd4e5da5Sopenharmony_ci      "%3 = OpFAdd %float %2 %float_2\n" +
7056fd4e5da5Sopenharmony_ci      "%4 = OpFSub %float %3 %float_1\n" +
7057fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7058fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7059fd4e5da5Sopenharmony_ci    4, true),
7060fd4e5da5Sopenharmony_ci  // Test case 5: merge add of subtract
7061fd4e5da5Sopenharmony_ci  // (2 + x) - 1 = x + 1
7062fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7063fd4e5da5Sopenharmony_ci    Header() +
7064fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7065fd4e5da5Sopenharmony_ci      "; CHECK: [[float_1:%\\w+]] = OpConstant [[float]] 1\n" +
7066fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
7067fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFAdd [[float]] [[ld]] [[float_1]]\n" +
7068fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7069fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7070fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
7071fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
7072fd4e5da5Sopenharmony_ci      "%3 = OpFAdd %float %float_2 %2\n" +
7073fd4e5da5Sopenharmony_ci      "%4 = OpFSub %float %3 %float_1\n" +
7074fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7075fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7076fd4e5da5Sopenharmony_ci    4, true),
7077fd4e5da5Sopenharmony_ci  // Test case 6: merge add of subtract
7078fd4e5da5Sopenharmony_ci  // 2 - (x + 1) = 1 - x
7079fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7080fd4e5da5Sopenharmony_ci    Header() +
7081fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7082fd4e5da5Sopenharmony_ci      "; CHECK: [[float_1:%\\w+]] = OpConstant [[float]] 1\n" +
7083fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
7084fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_1]] [[ld]]\n" +
7085fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7086fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7087fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
7088fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
7089fd4e5da5Sopenharmony_ci      "%3 = OpFAdd %float %2 %float_1\n" +
7090fd4e5da5Sopenharmony_ci      "%4 = OpFSub %float %float_2 %3\n" +
7091fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7092fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7093fd4e5da5Sopenharmony_ci    4, true),
7094fd4e5da5Sopenharmony_ci  // Test case 7: merge add of subtract
7095fd4e5da5Sopenharmony_ci  // 2 - (1 + x) = 1 - x
7096fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7097fd4e5da5Sopenharmony_ci    Header() +
7098fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7099fd4e5da5Sopenharmony_ci      "; CHECK: [[float_1:%\\w+]] = OpConstant [[float]] 1\n" +
7100fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
7101fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_1]] [[ld]]\n" +
7102fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7103fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7104fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
7105fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
7106fd4e5da5Sopenharmony_ci      "%3 = OpFAdd %float %float_1 %2\n" +
7107fd4e5da5Sopenharmony_ci      "%4 = OpFSub %float %float_2 %3\n" +
7108fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7109fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7110fd4e5da5Sopenharmony_ci    4, true),
7111fd4e5da5Sopenharmony_ci  // Test case 8: merge subtract of subtract
7112fd4e5da5Sopenharmony_ci  // (x - 2) - 1 = x - 3
7113fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7114fd4e5da5Sopenharmony_ci    Header() +
7115fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7116fd4e5da5Sopenharmony_ci      "; CHECK: [[float_3:%\\w+]] = OpConstant [[float]] 3\n" +
7117fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
7118fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[ld]] [[float_3]]\n" +
7119fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7120fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7121fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
7122fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
7123fd4e5da5Sopenharmony_ci      "%3 = OpFSub %float %2 %float_2\n" +
7124fd4e5da5Sopenharmony_ci      "%4 = OpFSub %float %3 %float_1\n" +
7125fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7126fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7127fd4e5da5Sopenharmony_ci    4, true),
7128fd4e5da5Sopenharmony_ci  // Test case 9: merge subtract of subtract
7129fd4e5da5Sopenharmony_ci  // (2 - x) - 1 = 1 - x
7130fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7131fd4e5da5Sopenharmony_ci    Header() +
7132fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7133fd4e5da5Sopenharmony_ci      "; CHECK: [[float_1:%\\w+]] = OpConstant [[float]] 1\n" +
7134fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
7135fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_1]] [[ld]]\n" +
7136fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7137fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7138fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
7139fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
7140fd4e5da5Sopenharmony_ci      "%3 = OpFSub %float %float_2 %2\n" +
7141fd4e5da5Sopenharmony_ci      "%4 = OpFSub %float %3 %float_1\n" +
7142fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7143fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7144fd4e5da5Sopenharmony_ci    4, true),
7145fd4e5da5Sopenharmony_ci  // Test case 10: merge subtract of subtract
7146fd4e5da5Sopenharmony_ci  // 2 - (x - 1) = 3 - x
7147fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7148fd4e5da5Sopenharmony_ci    Header() +
7149fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7150fd4e5da5Sopenharmony_ci      "; CHECK: [[float_3:%\\w+]] = OpConstant [[float]] 3\n" +
7151fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
7152fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFSub [[float]] [[float_3]] [[ld]]\n" +
7153fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7154fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7155fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
7156fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
7157fd4e5da5Sopenharmony_ci      "%3 = OpFSub %float %2 %float_1\n" +
7158fd4e5da5Sopenharmony_ci      "%4 = OpFSub %float %float_2 %3\n" +
7159fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7160fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7161fd4e5da5Sopenharmony_ci    4, true),
7162fd4e5da5Sopenharmony_ci  // Test case 11: merge subtract of subtract
7163fd4e5da5Sopenharmony_ci  // 1 - (2 - x) = x + (-1)
7164fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7165fd4e5da5Sopenharmony_ci    Header() +
7166fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7167fd4e5da5Sopenharmony_ci      "; CHECK: [[float_n1:%\\w+]] = OpConstant [[float]] -1\n" +
7168fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
7169fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFAdd [[float]] [[ld]] [[float_n1]]\n" +
7170fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7171fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7172fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
7173fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
7174fd4e5da5Sopenharmony_ci      "%3 = OpFSub %float %float_2 %2\n" +
7175fd4e5da5Sopenharmony_ci      "%4 = OpFSub %float %float_1 %3\n" +
7176fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7177fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7178fd4e5da5Sopenharmony_ci    4, true),
7179fd4e5da5Sopenharmony_ci  // Test case 12: merge subtract of subtract
7180fd4e5da5Sopenharmony_ci  // 2 - (1 - x) = x + 1
7181fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7182fd4e5da5Sopenharmony_ci    Header() +
7183fd4e5da5Sopenharmony_ci      "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7184fd4e5da5Sopenharmony_ci      "; CHECK: [[float_1:%\\w+]] = OpConstant [[float]] 1\n" +
7185fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[float]]\n" +
7186fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpFAdd [[float]] [[ld]] [[float_1]]\n" +
7187fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7188fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7189fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_float Function\n" +
7190fd4e5da5Sopenharmony_ci      "%2 = OpLoad %float %var\n" +
7191fd4e5da5Sopenharmony_ci      "%3 = OpFSub %float %float_1 %2\n" +
7192fd4e5da5Sopenharmony_ci      "%4 = OpFSub %float %float_2 %3\n" +
7193fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7194fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7195fd4e5da5Sopenharmony_ci    4, true),
7196fd4e5da5Sopenharmony_ci  // Test case 13: merge subtract of subtract with mixed types.
7197fd4e5da5Sopenharmony_ci  // 2 - (1 - x) = x + 1
7198fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7199fd4e5da5Sopenharmony_ci    Header() +
7200fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7201fd4e5da5Sopenharmony_ci      "; CHECK: [[int_1:%\\w+]] = OpConstant [[int]] 1\n" +
7202fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int]]\n" +
7203fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpIAdd [[int]] [[ld]] [[int_1]]\n" +
7204fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7205fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7206fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
7207fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
7208fd4e5da5Sopenharmony_ci      "%3 = OpISub %int %uint_1 %2\n" +
7209fd4e5da5Sopenharmony_ci      "%4 = OpISub %int %int_2 %3\n" +
7210fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7211fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7212fd4e5da5Sopenharmony_ci    4, true),
7213fd4e5da5Sopenharmony_ci  // Test case 14: fold overflowing signed 32 bit isubs
7214fd4e5da5Sopenharmony_ci  // (x - int_max) - 1 = x - int_min
7215fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7216fd4e5da5Sopenharmony_ci    Header() +
7217fd4e5da5Sopenharmony_ci      "; CHECK: [[int:%\\w+]] = OpTypeInt 32\n" +
7218fd4e5da5Sopenharmony_ci      "; CHECK: [[int_min:%\\w+]] = OpConstant [[int]] -2147483648\n" +
7219fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[int]]\n" +
7220fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[int]] [[ld]] [[int_min]]\n" +
7221fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7222fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7223fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_int Function\n" +
7224fd4e5da5Sopenharmony_ci      "%2 = OpLoad %int %var\n" +
7225fd4e5da5Sopenharmony_ci      "%3 = OpISub %int %2 %int_max\n" +
7226fd4e5da5Sopenharmony_ci      "%4 = OpISub %int %3 %int_1\n" +
7227fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7228fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7229fd4e5da5Sopenharmony_ci    4, true),
7230fd4e5da5Sopenharmony_ci  // Test case 15: fold overflowing signed 64 bit isubs
7231fd4e5da5Sopenharmony_ci  // (x - long_max) - 1 = x - long_min
7232fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7233fd4e5da5Sopenharmony_ci    Header() +
7234fd4e5da5Sopenharmony_ci      "; CHECK: [[long:%\\w+]] = OpTypeInt 64\n" +
7235fd4e5da5Sopenharmony_ci      "; CHECK: [[long_min:%\\w+]] = OpConstant [[long]] -9223372036854775808\n" +
7236fd4e5da5Sopenharmony_ci      "; CHECK: [[ld:%\\w+]] = OpLoad [[long]]\n" +
7237fd4e5da5Sopenharmony_ci      "; CHECK: %4 = OpISub [[long]] [[ld]] [[long_min]]\n" +
7238fd4e5da5Sopenharmony_ci      "%main = OpFunction %void None %void_func\n" +
7239fd4e5da5Sopenharmony_ci      "%main_lab = OpLabel\n" +
7240fd4e5da5Sopenharmony_ci      "%var = OpVariable %_ptr_long Function\n" +
7241fd4e5da5Sopenharmony_ci      "%2 = OpLoad %long %var\n" +
7242fd4e5da5Sopenharmony_ci      "%3 = OpISub %long %2 %long_max\n" +
7243fd4e5da5Sopenharmony_ci      "%4 = OpISub %long %3 %long_1\n" +
7244fd4e5da5Sopenharmony_ci      "OpReturn\n" +
7245fd4e5da5Sopenharmony_ci      "OpFunctionEnd\n",
7246fd4e5da5Sopenharmony_ci    4, true)
7247fd4e5da5Sopenharmony_ci));
7248fd4e5da5Sopenharmony_ci
7249fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(SelectFoldingTest, MatchingInstructionFoldingTest,
7250fd4e5da5Sopenharmony_ci::testing::Values(
7251fd4e5da5Sopenharmony_ci  // Test case 0: Fold select with the same values for both sides
7252fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7253fd4e5da5Sopenharmony_ci      Header() +
7254fd4e5da5Sopenharmony_ci          "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7255fd4e5da5Sopenharmony_ci          "; CHECK: [[int0:%\\w+]] = OpConstant [[int]] 0\n" +
7256fd4e5da5Sopenharmony_ci          "; CHECK: %2 = OpCopyObject [[int]] [[int0]]\n" +
7257fd4e5da5Sopenharmony_ci          "%main = OpFunction %void None %void_func\n" +
7258fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
7259fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_bool Function\n" +
7260fd4e5da5Sopenharmony_ci          "%load = OpLoad %bool %n\n" +
7261fd4e5da5Sopenharmony_ci          "%2 = OpSelect %int %load %100 %100\n" +
7262fd4e5da5Sopenharmony_ci          "OpReturn\n" +
7263fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
7264fd4e5da5Sopenharmony_ci      2, true),
7265fd4e5da5Sopenharmony_ci  // Test case 1: Fold select true to left side
7266fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7267fd4e5da5Sopenharmony_ci      Header() +
7268fd4e5da5Sopenharmony_ci          "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7269fd4e5da5Sopenharmony_ci          "; CHECK: [[int0:%\\w+]] = OpConstant [[int]] 0\n" +
7270fd4e5da5Sopenharmony_ci          "; CHECK: %2 = OpCopyObject [[int]] [[int0]]\n" +
7271fd4e5da5Sopenharmony_ci          "%main = OpFunction %void None %void_func\n" +
7272fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
7273fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
7274fd4e5da5Sopenharmony_ci          "%load = OpLoad %bool %n\n" +
7275fd4e5da5Sopenharmony_ci          "%2 = OpSelect %int %true %100 %n\n" +
7276fd4e5da5Sopenharmony_ci          "OpReturn\n" +
7277fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
7278fd4e5da5Sopenharmony_ci      2, true),
7279fd4e5da5Sopenharmony_ci  // Test case 2: Fold select false to right side
7280fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7281fd4e5da5Sopenharmony_ci      Header() +
7282fd4e5da5Sopenharmony_ci          "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7283fd4e5da5Sopenharmony_ci          "; CHECK: [[int0:%\\w+]] = OpConstant [[int]] 0\n" +
7284fd4e5da5Sopenharmony_ci          "; CHECK: %2 = OpCopyObject [[int]] [[int0]]\n" +
7285fd4e5da5Sopenharmony_ci          "%main = OpFunction %void None %void_func\n" +
7286fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
7287fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
7288fd4e5da5Sopenharmony_ci          "%load = OpLoad %bool %n\n" +
7289fd4e5da5Sopenharmony_ci          "%2 = OpSelect %int %false %n %100\n" +
7290fd4e5da5Sopenharmony_ci          "OpReturn\n" +
7291fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
7292fd4e5da5Sopenharmony_ci      2, true),
7293fd4e5da5Sopenharmony_ci  // Test case 3: Fold select null to right side
7294fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7295fd4e5da5Sopenharmony_ci      Header() +
7296fd4e5da5Sopenharmony_ci          "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7297fd4e5da5Sopenharmony_ci          "; CHECK: [[int0:%\\w+]] = OpConstant [[int]] 0\n" +
7298fd4e5da5Sopenharmony_ci          "; CHECK: %2 = OpCopyObject [[int]] [[int0]]\n" +
7299fd4e5da5Sopenharmony_ci          "%main = OpFunction %void None %void_func\n" +
7300fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
7301fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_int Function\n" +
7302fd4e5da5Sopenharmony_ci          "%load = OpLoad %int %n\n" +
7303fd4e5da5Sopenharmony_ci          "%2 = OpSelect %int %bool_null %load %100\n" +
7304fd4e5da5Sopenharmony_ci          "OpReturn\n" +
7305fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
7306fd4e5da5Sopenharmony_ci      2, true),
7307fd4e5da5Sopenharmony_ci  // Test case 4: vector null
7308fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7309fd4e5da5Sopenharmony_ci      Header() +
7310fd4e5da5Sopenharmony_ci          "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7311fd4e5da5Sopenharmony_ci          "; CHECK: [[v2int:%\\w+]] = OpTypeVector [[int]] 2\n" +
7312fd4e5da5Sopenharmony_ci          "; CHECK: [[int2:%\\w+]] = OpConstant [[int]] 2\n" +
7313fd4e5da5Sopenharmony_ci          "; CHECK: [[v2int2_2:%\\w+]] = OpConstantComposite [[v2int]] [[int2]] [[int2]]\n" +
7314fd4e5da5Sopenharmony_ci          "; CHECK: %2 = OpCopyObject [[v2int]] [[v2int2_2]]\n" +
7315fd4e5da5Sopenharmony_ci          "%main = OpFunction %void None %void_func\n" +
7316fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
7317fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_v2int Function\n" +
7318fd4e5da5Sopenharmony_ci          "%load = OpLoad %v2int %n\n" +
7319fd4e5da5Sopenharmony_ci          "%2 = OpSelect %v2int %v2bool_null %load %v2int_2_2\n" +
7320fd4e5da5Sopenharmony_ci          "OpReturn\n" +
7321fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
7322fd4e5da5Sopenharmony_ci      2, true),
7323fd4e5da5Sopenharmony_ci  // Test case 5: vector select
7324fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7325fd4e5da5Sopenharmony_ci      Header() +
7326fd4e5da5Sopenharmony_ci          "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7327fd4e5da5Sopenharmony_ci          "; CHECK: [[v2int:%\\w+]] = OpTypeVector [[int]] 2\n" +
7328fd4e5da5Sopenharmony_ci          "; CHECK: %4 = OpVectorShuffle [[v2int]] %2 %3 0 3\n" +
7329fd4e5da5Sopenharmony_ci          "%main = OpFunction %void None %void_func\n" +
7330fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
7331fd4e5da5Sopenharmony_ci          "%m = OpVariable %_ptr_v2int Function\n" +
7332fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_v2int Function\n" +
7333fd4e5da5Sopenharmony_ci          "%2 = OpLoad %v2int %n\n" +
7334fd4e5da5Sopenharmony_ci          "%3 = OpLoad %v2int %n\n" +
7335fd4e5da5Sopenharmony_ci          "%4 = OpSelect %v2int %v2bool_true_false %2 %3\n" +
7336fd4e5da5Sopenharmony_ci          "OpReturn\n" +
7337fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
7338fd4e5da5Sopenharmony_ci      4, true),
7339fd4e5da5Sopenharmony_ci  // Test case 6: vector select
7340fd4e5da5Sopenharmony_ci  InstructionFoldingCase<bool>(
7341fd4e5da5Sopenharmony_ci      Header() +
7342fd4e5da5Sopenharmony_ci          "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7343fd4e5da5Sopenharmony_ci          "; CHECK: [[v2int:%\\w+]] = OpTypeVector [[int]] 2\n" +
7344fd4e5da5Sopenharmony_ci          "; CHECK: %4 = OpVectorShuffle [[v2int]] %2 %3 2 1\n" +
7345fd4e5da5Sopenharmony_ci          "%main = OpFunction %void None %void_func\n" +
7346fd4e5da5Sopenharmony_ci          "%main_lab = OpLabel\n" +
7347fd4e5da5Sopenharmony_ci          "%m = OpVariable %_ptr_v2int Function\n" +
7348fd4e5da5Sopenharmony_ci          "%n = OpVariable %_ptr_v2int Function\n" +
7349fd4e5da5Sopenharmony_ci          "%2 = OpLoad %v2int %n\n" +
7350fd4e5da5Sopenharmony_ci          "%3 = OpLoad %v2int %n\n" +
7351fd4e5da5Sopenharmony_ci          "%4 = OpSelect %v2int %v2bool_false_true %2 %3\n" +
7352fd4e5da5Sopenharmony_ci          "OpReturn\n" +
7353fd4e5da5Sopenharmony_ci          "OpFunctionEnd",
7354fd4e5da5Sopenharmony_ci      4, true)
7355fd4e5da5Sopenharmony_ci));
7356fd4e5da5Sopenharmony_ci
7357fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(CompositeExtractOrInsertMatchingTest, MatchingInstructionFoldingTest,
7358fd4e5da5Sopenharmony_ci::testing::Values(
7359fd4e5da5Sopenharmony_ci    // Test case 0: Extracting from result of consecutive shuffles of differing
7360fd4e5da5Sopenharmony_ci    // size.
7361fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7362fd4e5da5Sopenharmony_ci        Header() +
7363fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7364fd4e5da5Sopenharmony_ci            "; CHECK: %5 = OpCompositeExtract [[int]] %2 2\n" +
7365fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7366fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7367fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4int Function\n" +
7368fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4int %n\n" +
7369fd4e5da5Sopenharmony_ci            "%3 = OpVectorShuffle %v2int %2 %2 2 3\n" +
7370fd4e5da5Sopenharmony_ci            "%4 = OpVectorShuffle %v4int %2 %3 0 4 2 5\n" +
7371fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %int %4 1\n" +
7372fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7373fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7374fd4e5da5Sopenharmony_ci        5, true),
7375fd4e5da5Sopenharmony_ci    // Test case 1: Extracting from result of vector shuffle of differing
7376fd4e5da5Sopenharmony_ci    // input and result sizes.
7377fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7378fd4e5da5Sopenharmony_ci        Header() +
7379fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7380fd4e5da5Sopenharmony_ci            "; CHECK: %4 = OpCompositeExtract [[int]] %2 2\n" +
7381fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7382fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7383fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4int Function\n" +
7384fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4int %n\n" +
7385fd4e5da5Sopenharmony_ci            "%3 = OpVectorShuffle %v2int %2 %2 2 3\n" +
7386fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %3 0\n" +
7387fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7388fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7389fd4e5da5Sopenharmony_ci        4, true),
7390fd4e5da5Sopenharmony_ci    // Test case 2: Extracting from result of vector shuffle of differing
7391fd4e5da5Sopenharmony_ci    // input and result sizes.
7392fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7393fd4e5da5Sopenharmony_ci        Header() +
7394fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7395fd4e5da5Sopenharmony_ci            "; CHECK: %4 = OpCompositeExtract [[int]] %2 3\n" +
7396fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7397fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7398fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4int Function\n" +
7399fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4int %n\n" +
7400fd4e5da5Sopenharmony_ci            "%3 = OpVectorShuffle %v2int %2 %2 2 3\n" +
7401fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %3 1\n" +
7402fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7403fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7404fd4e5da5Sopenharmony_ci        4, true),
7405fd4e5da5Sopenharmony_ci    // Test case 3: Using fmix feeding extract with a 1 in the a position.
7406fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7407fd4e5da5Sopenharmony_ci        Header() +
7408fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
7409fd4e5da5Sopenharmony_ci            "; CHECK: [[v4double:%\\w+]] = OpTypeVector [[double]] 4\n" +
7410fd4e5da5Sopenharmony_ci            "; CHECK: [[ptr_v4double:%\\w+]] = OpTypePointer Function [[v4double]]\n" +
7411fd4e5da5Sopenharmony_ci            "; CHECK: [[m:%\\w+]] = OpVariable [[ptr_v4double]] Function\n" +
7412fd4e5da5Sopenharmony_ci            "; CHECK: [[n:%\\w+]] = OpVariable [[ptr_v4double]] Function\n" +
7413fd4e5da5Sopenharmony_ci            "; CHECK: [[ld:%\\w+]] = OpLoad [[v4double]] [[n]]\n" +
7414fd4e5da5Sopenharmony_ci            "; CHECK: %5 = OpCompositeExtract [[double]] [[ld]] 1\n" +
7415fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7416fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7417fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_v4double Function\n" +
7418fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
7419fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4double %m\n" +
7420fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4double %n\n" +
7421fd4e5da5Sopenharmony_ci            "%4 = OpExtInst %v4double %1 FMix %2 %3 %v4double_0_1_0_0\n" +
7422fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %double %4 1\n" +
7423fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7424fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7425fd4e5da5Sopenharmony_ci        5, true),
7426fd4e5da5Sopenharmony_ci    // Test case 4: Using fmix feeding extract with a 0 in the a position.
7427fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7428fd4e5da5Sopenharmony_ci        Header() +
7429fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
7430fd4e5da5Sopenharmony_ci            "; CHECK: [[v4double:%\\w+]] = OpTypeVector [[double]] 4\n" +
7431fd4e5da5Sopenharmony_ci            "; CHECK: [[ptr_v4double:%\\w+]] = OpTypePointer Function [[v4double]]\n" +
7432fd4e5da5Sopenharmony_ci            "; CHECK: [[m:%\\w+]] = OpVariable [[ptr_v4double]] Function\n" +
7433fd4e5da5Sopenharmony_ci            "; CHECK: [[n:%\\w+]] = OpVariable [[ptr_v4double]] Function\n" +
7434fd4e5da5Sopenharmony_ci            "; CHECK: [[ld:%\\w+]] = OpLoad [[v4double]] [[m]]\n" +
7435fd4e5da5Sopenharmony_ci            "; CHECK: %5 = OpCompositeExtract [[double]] [[ld]] 2\n" +
7436fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7437fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7438fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_v4double Function\n" +
7439fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
7440fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4double %m\n" +
7441fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4double %n\n" +
7442fd4e5da5Sopenharmony_ci            "%4 = OpExtInst %v4double %1 FMix %2 %3 %v4double_0_1_0_0\n" +
7443fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %double %4 2\n" +
7444fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7445fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7446fd4e5da5Sopenharmony_ci        5, true),
7447fd4e5da5Sopenharmony_ci    // Test case 5: Using fmix feeding extract with a null for the alpha
7448fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7449fd4e5da5Sopenharmony_ci        Header() +
7450fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
7451fd4e5da5Sopenharmony_ci            "; CHECK: [[v4double:%\\w+]] = OpTypeVector [[double]] 4\n" +
7452fd4e5da5Sopenharmony_ci            "; CHECK: [[ptr_v4double:%\\w+]] = OpTypePointer Function [[v4double]]\n" +
7453fd4e5da5Sopenharmony_ci            "; CHECK: [[m:%\\w+]] = OpVariable [[ptr_v4double]] Function\n" +
7454fd4e5da5Sopenharmony_ci            "; CHECK: [[n:%\\w+]] = OpVariable [[ptr_v4double]] Function\n" +
7455fd4e5da5Sopenharmony_ci            "; CHECK: [[ld:%\\w+]] = OpLoad [[v4double]] [[m]]\n" +
7456fd4e5da5Sopenharmony_ci            "; CHECK: %5 = OpCompositeExtract [[double]] [[ld]] 0\n" +
7457fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7458fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7459fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_v4double Function\n" +
7460fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
7461fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4double %m\n" +
7462fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4double %n\n" +
7463fd4e5da5Sopenharmony_ci            "%4 = OpExtInst %v4double %1 FMix %2 %3 %v4double_null\n" +
7464fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %double %4 0\n" +
7465fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7466fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7467fd4e5da5Sopenharmony_ci        5, true),
7468fd4e5da5Sopenharmony_ci    // Test case 6: Don't fold: Using fmix feeding extract with 0.5 in the a
7469fd4e5da5Sopenharmony_ci    // position.
7470fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7471fd4e5da5Sopenharmony_ci        Header() +
7472fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7473fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7474fd4e5da5Sopenharmony_ci            "%m = OpVariable %_ptr_v4double Function\n" +
7475fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
7476fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4double %m\n" +
7477fd4e5da5Sopenharmony_ci            "%3 = OpLoad %v4double %n\n" +
7478fd4e5da5Sopenharmony_ci            "%4 = OpExtInst %v4double %1 FMix %2 %3 %v4double_1_1_1_0p5\n" +
7479fd4e5da5Sopenharmony_ci            "%5 = OpCompositeExtract %double %4 3\n" +
7480fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7481fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7482fd4e5da5Sopenharmony_ci        5, false),
7483fd4e5da5Sopenharmony_ci    // Test case 7: Extracting the undefined literal value from a vector
7484fd4e5da5Sopenharmony_ci    // shuffle.
7485fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7486fd4e5da5Sopenharmony_ci        Header() +
7487fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7488fd4e5da5Sopenharmony_ci            "; CHECK: %4 = OpUndef [[int]]\n" +
7489fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7490fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7491fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4int Function\n" +
7492fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4int %n\n" +
7493fd4e5da5Sopenharmony_ci            "%3 = OpVectorShuffle %v2int %2 %2 2 4294967295\n" +
7494fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %3 1\n" +
7495fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7496fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7497fd4e5da5Sopenharmony_ci        4, true),
7498fd4e5da5Sopenharmony_ci    // Test case 8: Inserting every element of a vector turns into a composite construct.
7499fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7500fd4e5da5Sopenharmony_ci        Header() +
7501fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7502fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[v4:%\\w+]] = OpTypeVector [[int]] 4\n" +
7503fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int1:%\\w+]] = OpConstant [[int]] 1\n" +
7504fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int2:%\\w+]] = OpConstant [[int]] 2\n" +
7505fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int3:%\\w+]] = OpConstant [[int]] 3\n" +
7506fd4e5da5Sopenharmony_ci            "; CHECK: [[construct:%\\w+]] = OpCompositeConstruct [[v4]] %100 [[int1]] [[int2]] [[int3]]\n" +
7507fd4e5da5Sopenharmony_ci            "; CHECK: %5 = OpCopyObject [[v4]] [[construct]]\n" +
7508fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7509fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7510fd4e5da5Sopenharmony_ci            "%2 = OpCompositeInsert %v4int %100 %v4int_undef 0\n" +
7511fd4e5da5Sopenharmony_ci            "%3 = OpCompositeInsert %v4int %int_1 %2 1\n" +
7512fd4e5da5Sopenharmony_ci            "%4 = OpCompositeInsert %v4int %int_2 %3 2\n" +
7513fd4e5da5Sopenharmony_ci            "%5 = OpCompositeInsert %v4int %int_3 %4 3\n" +
7514fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7515fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7516fd4e5da5Sopenharmony_ci        5, true),
7517fd4e5da5Sopenharmony_ci    // Test case 9: Inserting every element of a vector turns into a composite construct in a different order.
7518fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7519fd4e5da5Sopenharmony_ci        Header() +
7520fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7521fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[v4:%\\w+]] = OpTypeVector [[int]] 4\n" +
7522fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int1:%\\w+]] = OpConstant [[int]] 1\n" +
7523fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int2:%\\w+]] = OpConstant [[int]] 2\n" +
7524fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int3:%\\w+]] = OpConstant [[int]] 3\n" +
7525fd4e5da5Sopenharmony_ci            "; CHECK: [[construct:%\\w+]] = OpCompositeConstruct [[v4]] %100 [[int1]] [[int2]] [[int3]]\n" +
7526fd4e5da5Sopenharmony_ci            "; CHECK: %5 = OpCopyObject [[v4]] [[construct]]\n" +
7527fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7528fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7529fd4e5da5Sopenharmony_ci            "%2 = OpCompositeInsert %v4int %100 %v4int_undef 0\n" +
7530fd4e5da5Sopenharmony_ci            "%4 = OpCompositeInsert %v4int %int_2 %2 2\n" +
7531fd4e5da5Sopenharmony_ci            "%3 = OpCompositeInsert %v4int %int_1 %4 1\n" +
7532fd4e5da5Sopenharmony_ci            "%5 = OpCompositeInsert %v4int %int_3 %3 3\n" +
7533fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7534fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7535fd4e5da5Sopenharmony_ci        5, true),
7536fd4e5da5Sopenharmony_ci    // Test case 10: Check multiple inserts to the same position are handled correctly.
7537fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7538fd4e5da5Sopenharmony_ci        Header() +
7539fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7540fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[v4:%\\w+]] = OpTypeVector [[int]] 4\n" +
7541fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int1:%\\w+]] = OpConstant [[int]] 1\n" +
7542fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int2:%\\w+]] = OpConstant [[int]] 2\n" +
7543fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int3:%\\w+]] = OpConstant [[int]] 3\n" +
7544fd4e5da5Sopenharmony_ci            "; CHECK: [[construct:%\\w+]] = OpCompositeConstruct [[v4]] %100 [[int1]] [[int2]] [[int3]]\n" +
7545fd4e5da5Sopenharmony_ci            "; CHECK: %6 = OpCopyObject [[v4]] [[construct]]\n" +
7546fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7547fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7548fd4e5da5Sopenharmony_ci            "%2 = OpCompositeInsert %v4int %100 %v4int_undef 0\n" +
7549fd4e5da5Sopenharmony_ci            "%3 = OpCompositeInsert %v4int %int_2 %2 2\n" +
7550fd4e5da5Sopenharmony_ci            "%4 = OpCompositeInsert %v4int %int_4 %3 1\n" +
7551fd4e5da5Sopenharmony_ci            "%5 = OpCompositeInsert %v4int %int_1 %4 1\n" +
7552fd4e5da5Sopenharmony_ci            "%6 = OpCompositeInsert %v4int %int_3 %5 3\n" +
7553fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7554fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7555fd4e5da5Sopenharmony_ci        6, true),
7556fd4e5da5Sopenharmony_ci    // Test case 11: The last indexes are 0 and 1, but they have different first indexes.  This should not be folded.
7557fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7558fd4e5da5Sopenharmony_ci        Header() +
7559fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7560fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7561fd4e5da5Sopenharmony_ci            "%2 = OpCompositeInsert %m2x2int %100 %m2x2int_undef 0 0\n" +
7562fd4e5da5Sopenharmony_ci            "%3 = OpCompositeInsert %m2x2int %int_1 %2 1 1\n" +
7563fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7564fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7565fd4e5da5Sopenharmony_ci        3, false),
7566fd4e5da5Sopenharmony_ci    // Test case 12: Don't fold when there is a partial insertion.
7567fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7568fd4e5da5Sopenharmony_ci        Header() +
7569fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7570fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7571fd4e5da5Sopenharmony_ci            "%2 = OpCompositeInsert %m2x2int %v2int_1_0 %m2x2int_undef 0\n" +
7572fd4e5da5Sopenharmony_ci            "%3 = OpCompositeInsert %m2x2int %int_4 %2 0 0\n" +
7573fd4e5da5Sopenharmony_ci            "%4 = OpCompositeInsert %m2x2int %v2int_2_3 %3 1\n" +
7574fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7575fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7576fd4e5da5Sopenharmony_ci        4, false),
7577fd4e5da5Sopenharmony_ci    // Test case 13: Insert into a column of a matrix
7578fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7579fd4e5da5Sopenharmony_ci        Header() +
7580fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7581fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[v2:%\\w+]] = OpTypeVector [[int]] 2\n" +
7582fd4e5da5Sopenharmony_ci            "; CHECK: [[m2x2:%\\w+]] = OpTypeMatrix [[v2]] 2\n" +
7583fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[m2x2_undef:%\\w+]] = OpUndef [[m2x2]]\n" +
7584fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int1:%\\w+]] = OpConstant [[int]] 1\n" +
7585fd4e5da5Sopenharmony_ci// We keep this insert in the chain.  DeadInsertElimPass should remove it.
7586fd4e5da5Sopenharmony_ci            "; CHECK: [[insert:%\\w+]] = OpCompositeInsert [[m2x2]] %100 [[m2x2_undef]] 0 0\n" +
7587fd4e5da5Sopenharmony_ci            "; CHECK: [[construct:%\\w+]] = OpCompositeConstruct [[v2]] %100 [[int1]]\n" +
7588fd4e5da5Sopenharmony_ci            "; CHECK: %3 = OpCompositeInsert [[m2x2]] [[construct]] [[insert]] 0\n" +
7589fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7590fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7591fd4e5da5Sopenharmony_ci            "%2 = OpCompositeInsert %m2x2int %100 %m2x2int_undef 0 0\n" +
7592fd4e5da5Sopenharmony_ci            "%3 = OpCompositeInsert %m2x2int %int_1 %2 0 1\n" +
7593fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7594fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7595fd4e5da5Sopenharmony_ci        3, true),
7596fd4e5da5Sopenharmony_ci    // Test case 14: Insert all elements of the matrix.
7597fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7598fd4e5da5Sopenharmony_ci        Header() +
7599fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7600fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[v2:%\\w+]] = OpTypeVector [[int]] 2\n" +
7601fd4e5da5Sopenharmony_ci            "; CHECK: [[m2x2:%\\w+]] = OpTypeMatrix [[v2]] 2\n" +
7602fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[m2x2_undef:%\\w+]] = OpUndef [[m2x2]]\n" +
7603fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int1:%\\w+]] = OpConstant [[int]] 1\n" +
7604fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int2:%\\w+]] = OpConstant [[int]] 2\n" +
7605fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int3:%\\w+]] = OpConstant [[int]] 3\n" +
7606fd4e5da5Sopenharmony_ci            "; CHECK: [[c0:%\\w+]] = OpCompositeConstruct [[v2]] %100 [[int1]]\n" +
7607fd4e5da5Sopenharmony_ci            "; CHECK: [[c1:%\\w+]] = OpCompositeConstruct [[v2]] [[int2]] [[int3]]\n" +
7608fd4e5da5Sopenharmony_ci            "; CHECK: [[matrix:%\\w+]] = OpCompositeConstruct [[m2x2]] [[c0]] [[c1]]\n" +
7609fd4e5da5Sopenharmony_ci            "; CHECK: %5 = OpCopyObject [[m2x2]] [[matrix]]\n" +
7610fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7611fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7612fd4e5da5Sopenharmony_ci            "%2 = OpCompositeConstruct %v2int %100 %int_1\n" +
7613fd4e5da5Sopenharmony_ci            "%3 = OpCompositeInsert %m2x2int %2 %m2x2int_undef 0\n" +
7614fd4e5da5Sopenharmony_ci            "%4 = OpCompositeInsert %m2x2int %int_2 %3 1 0\n" +
7615fd4e5da5Sopenharmony_ci            "%5 = OpCompositeInsert %m2x2int %int_3 %4 1 1\n" +
7616fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7617fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7618fd4e5da5Sopenharmony_ci        5, true),
7619fd4e5da5Sopenharmony_ci    // Test case 15: Replace construct with extract when reconstructing a member
7620fd4e5da5Sopenharmony_ci    // of another object.
7621fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7622fd4e5da5Sopenharmony_ci        Header() +
7623fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7624fd4e5da5Sopenharmony_ci            "; CHECK: [[v2:%\\w+]] = OpTypeVector [[int]] 2\n" +
7625fd4e5da5Sopenharmony_ci            "; CHECK: [[m2x2:%\\w+]] = OpTypeMatrix [[v2]] 2\n" +
7626fd4e5da5Sopenharmony_ci            "; CHECK: [[m2x2_undef:%\\w+]] = OpUndef [[m2x2]]\n" +
7627fd4e5da5Sopenharmony_ci            "; CHECK: %5 = OpCompositeExtract [[v2]] [[m2x2_undef]]\n" +
7628fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7629fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7630fd4e5da5Sopenharmony_ci            "%3 = OpCompositeExtract %int %m2x2int_undef 1 0\n" +
7631fd4e5da5Sopenharmony_ci            "%4 = OpCompositeExtract %int %m2x2int_undef 1 1\n" +
7632fd4e5da5Sopenharmony_ci            "%5 = OpCompositeConstruct %v2int %3 %4\n" +
7633fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7634fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7635fd4e5da5Sopenharmony_ci        5, true),
7636fd4e5da5Sopenharmony_ci    // Test case 16: Don't fold when type cannot be deduced to a constant.
7637fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7638fd4e5da5Sopenharmony_ci        Header() +
7639fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7640fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7641fd4e5da5Sopenharmony_ci            "%4 = OpCompositeInsert %struct_v2int_int_int %int_1 %struct_v2int_int_int_null 2\n" +
7642fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7643fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7644fd4e5da5Sopenharmony_ci        4, false),
7645fd4e5da5Sopenharmony_ci    // Test case 17: Don't fold when index into composite is out of bounds.
7646fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7647fd4e5da5Sopenharmony_ci	Header() +
7648fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7649fd4e5da5Sopenharmony_ci	    "%main_lab = OpLabel\n" +
7650fd4e5da5Sopenharmony_ci	    "%4 = OpCompositeExtract %int %struct_v2int_int_int 3\n" +
7651fd4e5da5Sopenharmony_ci	    "OpReturn\n" +
7652fd4e5da5Sopenharmony_ci	    "OpFunctionEnd",
7653fd4e5da5Sopenharmony_ci	4, false),
7654fd4e5da5Sopenharmony_ci    // Test case 18: Fold when every element of an array is inserted.
7655fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7656fd4e5da5Sopenharmony_ci        Header() +
7657fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7658fd4e5da5Sopenharmony_ci            "; CHECK: [[int2:%\\w+]] = OpConstant [[int]] 2\n" +
7659fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[arr_type:%\\w+]] = OpTypeArray [[int]] [[int2]]\n" +
7660fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int10:%\\w+]] = OpConstant [[int]] 10\n" +
7661fd4e5da5Sopenharmony_ci            "; CHECK-DAG: [[int1:%\\w+]] = OpConstant [[int]] 1\n" +
7662fd4e5da5Sopenharmony_ci            "; CHECK: [[construct:%\\w+]] = OpCompositeConstruct [[arr_type]] [[int10]] [[int1]]\n" +
7663fd4e5da5Sopenharmony_ci            "; CHECK: %5 = OpCopyObject [[arr_type]] [[construct]]\n" +
7664fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7665fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7666fd4e5da5Sopenharmony_ci            "%4 = OpCompositeInsert %int_arr_2 %int_10 %int_arr_2_undef 0\n" +
7667fd4e5da5Sopenharmony_ci            "%5 = OpCompositeInsert %int_arr_2 %int_1 %4 1\n" +
7668fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7669fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7670fd4e5da5Sopenharmony_ci        5, true)
7671fd4e5da5Sopenharmony_ci));
7672fd4e5da5Sopenharmony_ci
7673fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(DotProductMatchingTest, MatchingInstructionFoldingTest,
7674fd4e5da5Sopenharmony_ci::testing::Values(
7675fd4e5da5Sopenharmony_ci    // Test case 0: Using OpDot to extract last element.
7676fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7677fd4e5da5Sopenharmony_ci        Header() +
7678fd4e5da5Sopenharmony_ci            "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7679fd4e5da5Sopenharmony_ci            "; CHECK: %3 = OpCompositeExtract [[float]] %2 3\n" +
7680fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7681fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7682fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4float Function\n" +
7683fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4float %n\n" +
7684fd4e5da5Sopenharmony_ci            "%3 = OpDot %float %2 %v4float_0_0_0_1\n" +
7685fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7686fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7687fd4e5da5Sopenharmony_ci        3, true),
7688fd4e5da5Sopenharmony_ci    // Test case 1: Using OpDot to extract last element.
7689fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7690fd4e5da5Sopenharmony_ci        Header() +
7691fd4e5da5Sopenharmony_ci            "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7692fd4e5da5Sopenharmony_ci            "; CHECK: %3 = OpCompositeExtract [[float]] %2 3\n" +
7693fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7694fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7695fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4float Function\n" +
7696fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4float %n\n" +
7697fd4e5da5Sopenharmony_ci            "%3 = OpDot %float %v4float_0_0_0_1 %2\n" +
7698fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7699fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7700fd4e5da5Sopenharmony_ci        3, true),
7701fd4e5da5Sopenharmony_ci    // Test case 2: Using OpDot to extract second element.
7702fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7703fd4e5da5Sopenharmony_ci        Header() +
7704fd4e5da5Sopenharmony_ci            "; CHECK: [[float:%\\w+]] = OpTypeFloat 32\n" +
7705fd4e5da5Sopenharmony_ci            "; CHECK: %3 = OpCompositeExtract [[float]] %2 1\n" +
7706fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7707fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7708fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4float Function\n" +
7709fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4float %n\n" +
7710fd4e5da5Sopenharmony_ci            "%3 = OpDot %float %v4float_0_1_0_0 %2\n" +
7711fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7712fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7713fd4e5da5Sopenharmony_ci        3, true),
7714fd4e5da5Sopenharmony_ci    // Test case 3: Using OpDot to extract last element.
7715fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7716fd4e5da5Sopenharmony_ci        Header() +
7717fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
7718fd4e5da5Sopenharmony_ci            "; CHECK: %3 = OpCompositeExtract [[double]] %2 3\n" +
7719fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7720fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7721fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
7722fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4double %n\n" +
7723fd4e5da5Sopenharmony_ci            "%3 = OpDot %double %2 %v4double_0_0_0_1\n" +
7724fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7725fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7726fd4e5da5Sopenharmony_ci        3, true),
7727fd4e5da5Sopenharmony_ci    // Test case 4: Using OpDot to extract last element.
7728fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7729fd4e5da5Sopenharmony_ci        Header() +
7730fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
7731fd4e5da5Sopenharmony_ci            "; CHECK: %3 = OpCompositeExtract [[double]] %2 3\n" +
7732fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7733fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7734fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
7735fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4double %n\n" +
7736fd4e5da5Sopenharmony_ci            "%3 = OpDot %double %v4double_0_0_0_1 %2\n" +
7737fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7738fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7739fd4e5da5Sopenharmony_ci        3, true),
7740fd4e5da5Sopenharmony_ci    // Test case 5: Using OpDot to extract second element.
7741fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7742fd4e5da5Sopenharmony_ci        Header() +
7743fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
7744fd4e5da5Sopenharmony_ci            "; CHECK: %3 = OpCompositeExtract [[double]] %2 1\n" +
7745fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7746fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7747fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
7748fd4e5da5Sopenharmony_ci            "%2 = OpLoad %v4double %n\n" +
7749fd4e5da5Sopenharmony_ci            "%3 = OpDot %double %v4double_0_1_0_0 %2\n" +
7750fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7751fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7752fd4e5da5Sopenharmony_ci        3, true)
7753fd4e5da5Sopenharmony_ci));
7754fd4e5da5Sopenharmony_ci
7755fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(VectorShuffleMatchingTest, MatchingInstructionFoldingTest,
7756fd4e5da5Sopenharmony_ci::testing::Values(
7757fd4e5da5Sopenharmony_ci    // Test case 0: Using OpDot to extract last element.
7758fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7759fd4e5da5Sopenharmony_ci        Header() +
7760fd4e5da5Sopenharmony_ci            "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
7761fd4e5da5Sopenharmony_ci            "; CHECK: [[v2int:%\\w+]] = OpTypeVector [[int]] 2{{[[:space:]]}}\n" +
7762fd4e5da5Sopenharmony_ci            "; CHECK: [[null:%\\w+]] = OpConstantNull [[v2int]]\n" +
7763fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
7764fd4e5da5Sopenharmony_ci            "; CHECK: %3 = OpVectorShuffle [[v2int]] [[null]] {{%\\w+}} 4294967295 2\n" +
7765fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
7766fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
7767fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_int Function\n" +
7768fd4e5da5Sopenharmony_ci            "%load = OpLoad %int %n\n" +
7769fd4e5da5Sopenharmony_ci            "%2 = OpVectorShuffle %v2int %v2int_null %v2int_2_3 3 0xFFFFFFFF \n" +
7770fd4e5da5Sopenharmony_ci            "%3 = OpVectorShuffle %v2int %2 %v2int_2_3 1 2 \n" +
7771fd4e5da5Sopenharmony_ci            "OpReturn\n" +
7772fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
7773fd4e5da5Sopenharmony_ci        3, true)
7774fd4e5da5Sopenharmony_ci ));
7775fd4e5da5Sopenharmony_ci
7776fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FmaGenerationMatchingTest, MatchingInstructionFoldingTest,
7777fd4e5da5Sopenharmony_ci::testing::Values(
7778fd4e5da5Sopenharmony_ci   // Test case 0: (x * y) + a = Fma(x, y, a)
7779fd4e5da5Sopenharmony_ci   InstructionFoldingCase<bool>(
7780fd4e5da5Sopenharmony_ci       Header() +
7781fd4e5da5Sopenharmony_ci           "; CHECK: [[ext:%\\w+]] = OpExtInstImport \"GLSL.std.450\"\n" +
7782fd4e5da5Sopenharmony_ci           "; CHECK: OpFunction\n" +
7783fd4e5da5Sopenharmony_ci           "; CHECK: [[x:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7784fd4e5da5Sopenharmony_ci           "; CHECK: [[y:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7785fd4e5da5Sopenharmony_ci           "; CHECK: [[a:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7786fd4e5da5Sopenharmony_ci           "; CHECK: [[lx:%\\w+]] = OpLoad {{%\\w+}} [[x]]\n" +
7787fd4e5da5Sopenharmony_ci           "; CHECK: [[ly:%\\w+]] = OpLoad {{%\\w+}} [[y]]\n" +
7788fd4e5da5Sopenharmony_ci           "; CHECK: [[la:%\\w+]] = OpLoad {{%\\w+}} [[a]]\n" +
7789fd4e5da5Sopenharmony_ci           "; CHECK: [[fma:%\\w+]] = OpExtInst {{%\\w+}} [[ext]] Fma [[lx]] [[ly]] [[la]]\n" +
7790fd4e5da5Sopenharmony_ci           "; CHECK: OpStore {{%\\w+}} [[fma]]\n" +
7791fd4e5da5Sopenharmony_ci           "%main = OpFunction %void None %void_func\n" +
7792fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
7793fd4e5da5Sopenharmony_ci           "%x = OpVariable %_ptr_float Function\n" +
7794fd4e5da5Sopenharmony_ci           "%y = OpVariable %_ptr_float Function\n" +
7795fd4e5da5Sopenharmony_ci           "%a = OpVariable %_ptr_float Function\n" +
7796fd4e5da5Sopenharmony_ci           "%lx = OpLoad %float %x\n" +
7797fd4e5da5Sopenharmony_ci           "%ly = OpLoad %float %y\n" +
7798fd4e5da5Sopenharmony_ci           "%mul = OpFMul %float %lx %ly\n" +
7799fd4e5da5Sopenharmony_ci           "%la = OpLoad %float %a\n" +
7800fd4e5da5Sopenharmony_ci           "%3 = OpFAdd %float %mul %la\n" +
7801fd4e5da5Sopenharmony_ci           "OpStore %a %3\n" +
7802fd4e5da5Sopenharmony_ci           "OpReturn\n" +
7803fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
7804fd4e5da5Sopenharmony_ci       3, true),
7805fd4e5da5Sopenharmony_ci    // Test case 1:  a + (x * y) = Fma(x, y, a)
7806fd4e5da5Sopenharmony_ci   InstructionFoldingCase<bool>(
7807fd4e5da5Sopenharmony_ci       Header() +
7808fd4e5da5Sopenharmony_ci           "; CHECK: [[ext:%\\w+]] = OpExtInstImport \"GLSL.std.450\"\n" +
7809fd4e5da5Sopenharmony_ci           "; CHECK: OpFunction\n" +
7810fd4e5da5Sopenharmony_ci           "; CHECK: [[x:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7811fd4e5da5Sopenharmony_ci           "; CHECK: [[y:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7812fd4e5da5Sopenharmony_ci           "; CHECK: [[a:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7813fd4e5da5Sopenharmony_ci           "; CHECK: [[lx:%\\w+]] = OpLoad {{%\\w+}} [[x]]\n" +
7814fd4e5da5Sopenharmony_ci           "; CHECK: [[ly:%\\w+]] = OpLoad {{%\\w+}} [[y]]\n" +
7815fd4e5da5Sopenharmony_ci           "; CHECK: [[la:%\\w+]] = OpLoad {{%\\w+}} [[a]]\n" +
7816fd4e5da5Sopenharmony_ci           "; CHECK: [[fma:%\\w+]] = OpExtInst {{%\\w+}} [[ext]] Fma [[lx]] [[ly]] [[la]]\n" +
7817fd4e5da5Sopenharmony_ci           "; CHECK: OpStore {{%\\w+}} [[fma]]\n" +
7818fd4e5da5Sopenharmony_ci           "%main = OpFunction %void None %void_func\n" +
7819fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
7820fd4e5da5Sopenharmony_ci           "%x = OpVariable %_ptr_float Function\n" +
7821fd4e5da5Sopenharmony_ci           "%y = OpVariable %_ptr_float Function\n" +
7822fd4e5da5Sopenharmony_ci           "%a = OpVariable %_ptr_float Function\n" +
7823fd4e5da5Sopenharmony_ci           "%lx = OpLoad %float %x\n" +
7824fd4e5da5Sopenharmony_ci           "%ly = OpLoad %float %y\n" +
7825fd4e5da5Sopenharmony_ci           "%mul = OpFMul %float %lx %ly\n" +
7826fd4e5da5Sopenharmony_ci           "%la = OpLoad %float %a\n" +
7827fd4e5da5Sopenharmony_ci           "%3 = OpFAdd %float %la %mul\n" +
7828fd4e5da5Sopenharmony_ci           "OpStore %a %3\n" +
7829fd4e5da5Sopenharmony_ci           "OpReturn\n" +
7830fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
7831fd4e5da5Sopenharmony_ci       3, true),
7832fd4e5da5Sopenharmony_ci   // Test case 2: (x * y) + a = Fma(x, y, a) with vectors
7833fd4e5da5Sopenharmony_ci   InstructionFoldingCase<bool>(
7834fd4e5da5Sopenharmony_ci       Header() +
7835fd4e5da5Sopenharmony_ci           "; CHECK: [[ext:%\\w+]] = OpExtInstImport \"GLSL.std.450\"\n" +
7836fd4e5da5Sopenharmony_ci           "; CHECK: OpFunction\n" +
7837fd4e5da5Sopenharmony_ci           "; CHECK: [[x:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7838fd4e5da5Sopenharmony_ci           "; CHECK: [[y:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7839fd4e5da5Sopenharmony_ci           "; CHECK: [[a:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7840fd4e5da5Sopenharmony_ci           "; CHECK: [[lx:%\\w+]] = OpLoad {{%\\w+}} [[x]]\n" +
7841fd4e5da5Sopenharmony_ci           "; CHECK: [[ly:%\\w+]] = OpLoad {{%\\w+}} [[y]]\n" +
7842fd4e5da5Sopenharmony_ci           "; CHECK: [[la:%\\w+]] = OpLoad {{%\\w+}} [[a]]\n" +
7843fd4e5da5Sopenharmony_ci           "; CHECK: [[fma:%\\w+]] = OpExtInst {{%\\w+}} [[ext]] Fma [[lx]] [[ly]] [[la]]\n" +
7844fd4e5da5Sopenharmony_ci           "; CHECK: OpStore {{%\\w+}} [[fma]]\n" +
7845fd4e5da5Sopenharmony_ci           "%main = OpFunction %void None %void_func\n" +
7846fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
7847fd4e5da5Sopenharmony_ci           "%x = OpVariable %_ptr_v4float Function\n" +
7848fd4e5da5Sopenharmony_ci           "%y = OpVariable %_ptr_v4float Function\n" +
7849fd4e5da5Sopenharmony_ci           "%a = OpVariable %_ptr_v4float Function\n" +
7850fd4e5da5Sopenharmony_ci           "%lx = OpLoad %v4float %x\n" +
7851fd4e5da5Sopenharmony_ci           "%ly = OpLoad %v4float %y\n" +
7852fd4e5da5Sopenharmony_ci           "%mul = OpFMul %v4float %lx %ly\n" +
7853fd4e5da5Sopenharmony_ci           "%la = OpLoad %v4float %a\n" +
7854fd4e5da5Sopenharmony_ci           "%3 = OpFAdd %v4float %mul %la\n" +
7855fd4e5da5Sopenharmony_ci           "OpStore %a %3\n" +
7856fd4e5da5Sopenharmony_ci           "OpReturn\n" +
7857fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
7858fd4e5da5Sopenharmony_ci       3, true),
7859fd4e5da5Sopenharmony_ci    // Test case 3:  a + (x * y) = Fma(x, y, a) with vectors
7860fd4e5da5Sopenharmony_ci   InstructionFoldingCase<bool>(
7861fd4e5da5Sopenharmony_ci       Header() +
7862fd4e5da5Sopenharmony_ci           "; CHECK: [[ext:%\\w+]] = OpExtInstImport \"GLSL.std.450\"\n" +
7863fd4e5da5Sopenharmony_ci           "; CHECK: OpFunction\n" +
7864fd4e5da5Sopenharmony_ci           "; CHECK: [[x:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7865fd4e5da5Sopenharmony_ci           "; CHECK: [[y:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7866fd4e5da5Sopenharmony_ci           "; CHECK: [[a:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7867fd4e5da5Sopenharmony_ci           "; CHECK: [[lx:%\\w+]] = OpLoad {{%\\w+}} [[x]]\n" +
7868fd4e5da5Sopenharmony_ci           "; CHECK: [[ly:%\\w+]] = OpLoad {{%\\w+}} [[y]]\n" +
7869fd4e5da5Sopenharmony_ci           "; CHECK: [[la:%\\w+]] = OpLoad {{%\\w+}} [[a]]\n" +
7870fd4e5da5Sopenharmony_ci           "; CHECK: [[fma:%\\w+]] = OpExtInst {{%\\w+}} [[ext]] Fma [[lx]] [[ly]] [[la]]\n" +
7871fd4e5da5Sopenharmony_ci           "; CHECK: OpStore {{%\\w+}} [[fma]]\n" +
7872fd4e5da5Sopenharmony_ci           "%main = OpFunction %void None %void_func\n" +
7873fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
7874fd4e5da5Sopenharmony_ci           "%x = OpVariable %_ptr_float Function\n" +
7875fd4e5da5Sopenharmony_ci           "%y = OpVariable %_ptr_float Function\n" +
7876fd4e5da5Sopenharmony_ci           "%a = OpVariable %_ptr_float Function\n" +
7877fd4e5da5Sopenharmony_ci           "%lx = OpLoad %float %x\n" +
7878fd4e5da5Sopenharmony_ci           "%ly = OpLoad %float %y\n" +
7879fd4e5da5Sopenharmony_ci           "%mul = OpFMul %float %lx %ly\n" +
7880fd4e5da5Sopenharmony_ci           "%la = OpLoad %float %a\n" +
7881fd4e5da5Sopenharmony_ci           "%3 = OpFAdd %float %la %mul\n" +
7882fd4e5da5Sopenharmony_ci           "OpStore %a %3\n" +
7883fd4e5da5Sopenharmony_ci           "OpReturn\n" +
7884fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
7885fd4e5da5Sopenharmony_ci       3, true),
7886fd4e5da5Sopenharmony_ci    // Test 4: that the OpExtInstImport instruction is generated if it is missing.
7887fd4e5da5Sopenharmony_ci   InstructionFoldingCase<bool>(
7888fd4e5da5Sopenharmony_ci           std::string() +
7889fd4e5da5Sopenharmony_ci           "; CHECK: [[ext:%\\w+]] = OpExtInstImport \"GLSL.std.450\"\n" +
7890fd4e5da5Sopenharmony_ci           "; CHECK: OpFunction\n" +
7891fd4e5da5Sopenharmony_ci           "; CHECK: [[x:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7892fd4e5da5Sopenharmony_ci           "; CHECK: [[y:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7893fd4e5da5Sopenharmony_ci           "; CHECK: [[a:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7894fd4e5da5Sopenharmony_ci           "; CHECK: [[lx:%\\w+]] = OpLoad {{%\\w+}} [[x]]\n" +
7895fd4e5da5Sopenharmony_ci           "; CHECK: [[ly:%\\w+]] = OpLoad {{%\\w+}} [[y]]\n" +
7896fd4e5da5Sopenharmony_ci           "; CHECK: [[la:%\\w+]] = OpLoad {{%\\w+}} [[a]]\n" +
7897fd4e5da5Sopenharmony_ci           "; CHECK: [[fma:%\\w+]] = OpExtInst {{%\\w+}} [[ext]] Fma [[lx]] [[ly]] [[la]]\n" +
7898fd4e5da5Sopenharmony_ci           "; CHECK: OpStore {{%\\w+}} [[fma]]\n" +
7899fd4e5da5Sopenharmony_ci           "OpCapability Shader\n" +
7900fd4e5da5Sopenharmony_ci           "OpMemoryModel Logical GLSL450\n" +
7901fd4e5da5Sopenharmony_ci           "OpEntryPoint Fragment %main \"main\"\n" +
7902fd4e5da5Sopenharmony_ci           "OpExecutionMode %main OriginUpperLeft\n" +
7903fd4e5da5Sopenharmony_ci           "OpSource GLSL 140\n" +
7904fd4e5da5Sopenharmony_ci           "OpName %main \"main\"\n" +
7905fd4e5da5Sopenharmony_ci           "%void = OpTypeVoid\n" +
7906fd4e5da5Sopenharmony_ci           "%void_func = OpTypeFunction %void\n" +
7907fd4e5da5Sopenharmony_ci           "%bool = OpTypeBool\n" +
7908fd4e5da5Sopenharmony_ci           "%float = OpTypeFloat 32\n" +
7909fd4e5da5Sopenharmony_ci           "%_ptr_float = OpTypePointer Function %float\n" +
7910fd4e5da5Sopenharmony_ci           "%main = OpFunction %void None %void_func\n" +
7911fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
7912fd4e5da5Sopenharmony_ci           "%x = OpVariable %_ptr_float Function\n" +
7913fd4e5da5Sopenharmony_ci           "%y = OpVariable %_ptr_float Function\n" +
7914fd4e5da5Sopenharmony_ci           "%a = OpVariable %_ptr_float Function\n" +
7915fd4e5da5Sopenharmony_ci           "%lx = OpLoad %float %x\n" +
7916fd4e5da5Sopenharmony_ci           "%ly = OpLoad %float %y\n" +
7917fd4e5da5Sopenharmony_ci           "%mul = OpFMul %float %lx %ly\n" +
7918fd4e5da5Sopenharmony_ci           "%la = OpLoad %float %a\n" +
7919fd4e5da5Sopenharmony_ci           "%3 = OpFAdd %float %mul %la\n" +
7920fd4e5da5Sopenharmony_ci           "OpStore %a %3\n" +
7921fd4e5da5Sopenharmony_ci           "OpReturn\n" +
7922fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
7923fd4e5da5Sopenharmony_ci       3, true),
7924fd4e5da5Sopenharmony_ci   // Test 5: Don't fold if the multiple is marked no contract.
7925fd4e5da5Sopenharmony_ci   InstructionFoldingCase<bool>(
7926fd4e5da5Sopenharmony_ci       std::string() +
7927fd4e5da5Sopenharmony_ci           "OpCapability Shader\n" +
7928fd4e5da5Sopenharmony_ci           "OpMemoryModel Logical GLSL450\n" +
7929fd4e5da5Sopenharmony_ci           "OpEntryPoint Fragment %main \"main\"\n" +
7930fd4e5da5Sopenharmony_ci           "OpExecutionMode %main OriginUpperLeft\n" +
7931fd4e5da5Sopenharmony_ci           "OpSource GLSL 140\n" +
7932fd4e5da5Sopenharmony_ci           "OpName %main \"main\"\n" +
7933fd4e5da5Sopenharmony_ci           "OpDecorate %mul NoContraction\n" +
7934fd4e5da5Sopenharmony_ci           "%void = OpTypeVoid\n" +
7935fd4e5da5Sopenharmony_ci           "%void_func = OpTypeFunction %void\n" +
7936fd4e5da5Sopenharmony_ci           "%bool = OpTypeBool\n" +
7937fd4e5da5Sopenharmony_ci           "%float = OpTypeFloat 32\n" +
7938fd4e5da5Sopenharmony_ci           "%_ptr_float = OpTypePointer Function %float\n" +
7939fd4e5da5Sopenharmony_ci           "%main = OpFunction %void None %void_func\n" +
7940fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
7941fd4e5da5Sopenharmony_ci           "%x = OpVariable %_ptr_float Function\n" +
7942fd4e5da5Sopenharmony_ci           "%y = OpVariable %_ptr_float Function\n" +
7943fd4e5da5Sopenharmony_ci           "%a = OpVariable %_ptr_float Function\n" +
7944fd4e5da5Sopenharmony_ci           "%lx = OpLoad %float %x\n" +
7945fd4e5da5Sopenharmony_ci           "%ly = OpLoad %float %y\n" +
7946fd4e5da5Sopenharmony_ci           "%mul = OpFMul %float %lx %ly\n" +
7947fd4e5da5Sopenharmony_ci           "%la = OpLoad %float %a\n" +
7948fd4e5da5Sopenharmony_ci           "%3 = OpFAdd %float %mul %la\n" +
7949fd4e5da5Sopenharmony_ci           "OpStore %a %3\n" +
7950fd4e5da5Sopenharmony_ci           "OpReturn\n" +
7951fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
7952fd4e5da5Sopenharmony_ci       3, false),
7953fd4e5da5Sopenharmony_ci       // Test 6: Don't fold if the add is marked no contract.
7954fd4e5da5Sopenharmony_ci       InstructionFoldingCase<bool>(
7955fd4e5da5Sopenharmony_ci           std::string() +
7956fd4e5da5Sopenharmony_ci               "OpCapability Shader\n" +
7957fd4e5da5Sopenharmony_ci               "OpMemoryModel Logical GLSL450\n" +
7958fd4e5da5Sopenharmony_ci               "OpEntryPoint Fragment %main \"main\"\n" +
7959fd4e5da5Sopenharmony_ci               "OpExecutionMode %main OriginUpperLeft\n" +
7960fd4e5da5Sopenharmony_ci               "OpSource GLSL 140\n" +
7961fd4e5da5Sopenharmony_ci               "OpName %main \"main\"\n" +
7962fd4e5da5Sopenharmony_ci               "OpDecorate %3 NoContraction\n" +
7963fd4e5da5Sopenharmony_ci               "%void = OpTypeVoid\n" +
7964fd4e5da5Sopenharmony_ci               "%void_func = OpTypeFunction %void\n" +
7965fd4e5da5Sopenharmony_ci               "%bool = OpTypeBool\n" +
7966fd4e5da5Sopenharmony_ci               "%float = OpTypeFloat 32\n" +
7967fd4e5da5Sopenharmony_ci               "%_ptr_float = OpTypePointer Function %float\n" +
7968fd4e5da5Sopenharmony_ci               "%main = OpFunction %void None %void_func\n" +
7969fd4e5da5Sopenharmony_ci               "%main_lab = OpLabel\n" +
7970fd4e5da5Sopenharmony_ci               "%x = OpVariable %_ptr_float Function\n" +
7971fd4e5da5Sopenharmony_ci               "%y = OpVariable %_ptr_float Function\n" +
7972fd4e5da5Sopenharmony_ci               "%a = OpVariable %_ptr_float Function\n" +
7973fd4e5da5Sopenharmony_ci               "%lx = OpLoad %float %x\n" +
7974fd4e5da5Sopenharmony_ci               "%ly = OpLoad %float %y\n" +
7975fd4e5da5Sopenharmony_ci               "%mul = OpFMul %float %lx %ly\n" +
7976fd4e5da5Sopenharmony_ci               "%la = OpLoad %float %a\n" +
7977fd4e5da5Sopenharmony_ci               "%3 = OpFAdd %float %mul %la\n" +
7978fd4e5da5Sopenharmony_ci               "OpStore %a %3\n" +
7979fd4e5da5Sopenharmony_ci               "OpReturn\n" +
7980fd4e5da5Sopenharmony_ci               "OpFunctionEnd",
7981fd4e5da5Sopenharmony_ci           3, false),
7982fd4e5da5Sopenharmony_ci    // Test case 7: (x * y) - a = Fma(x, y, -a)
7983fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
7984fd4e5da5Sopenharmony_ci       Header() +
7985fd4e5da5Sopenharmony_ci           "; CHECK: [[ext:%\\w+]] = OpExtInstImport \"GLSL.std.450\"\n" +
7986fd4e5da5Sopenharmony_ci           "; CHECK: OpFunction\n" +
7987fd4e5da5Sopenharmony_ci           "; CHECK: [[x:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7988fd4e5da5Sopenharmony_ci           "; CHECK: [[y:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7989fd4e5da5Sopenharmony_ci           "; CHECK: [[a:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
7990fd4e5da5Sopenharmony_ci           "; CHECK: [[lx:%\\w+]] = OpLoad {{%\\w+}} [[x]]\n" +
7991fd4e5da5Sopenharmony_ci           "; CHECK: [[ly:%\\w+]] = OpLoad {{%\\w+}} [[y]]\n" +
7992fd4e5da5Sopenharmony_ci           "; CHECK: [[la:%\\w+]] = OpLoad {{%\\w+}} [[a]]\n" +
7993fd4e5da5Sopenharmony_ci           "; CHECK: [[na:%\\w+]] = OpFNegate {{%\\w+}} [[la]]\n" +
7994fd4e5da5Sopenharmony_ci           "; CHECK: [[fma:%\\w+]] = OpExtInst {{%\\w+}} [[ext]] Fma [[lx]] [[ly]] [[na]]\n" +
7995fd4e5da5Sopenharmony_ci           "; CHECK: OpStore {{%\\w+}} [[fma]]\n" +
7996fd4e5da5Sopenharmony_ci           "%main = OpFunction %void None %void_func\n" +
7997fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
7998fd4e5da5Sopenharmony_ci           "%x = OpVariable %_ptr_float Function\n" +
7999fd4e5da5Sopenharmony_ci           "%y = OpVariable %_ptr_float Function\n" +
8000fd4e5da5Sopenharmony_ci           "%a = OpVariable %_ptr_float Function\n" +
8001fd4e5da5Sopenharmony_ci           "%lx = OpLoad %float %x\n" +
8002fd4e5da5Sopenharmony_ci           "%ly = OpLoad %float %y\n" +
8003fd4e5da5Sopenharmony_ci           "%mul = OpFMul %float %lx %ly\n" +
8004fd4e5da5Sopenharmony_ci           "%la = OpLoad %float %a\n" +
8005fd4e5da5Sopenharmony_ci           "%3 = OpFSub %float %mul %la\n" +
8006fd4e5da5Sopenharmony_ci           "OpStore %a %3\n" +
8007fd4e5da5Sopenharmony_ci           "OpReturn\n" +
8008fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
8009fd4e5da5Sopenharmony_ci       3, true),
8010fd4e5da5Sopenharmony_ci   // Test case 8: a - (x * y) = Fma(-x, y, a)
8011fd4e5da5Sopenharmony_ci   InstructionFoldingCase<bool>(
8012fd4e5da5Sopenharmony_ci       Header() +
8013fd4e5da5Sopenharmony_ci           "; CHECK: [[ext:%\\w+]] = OpExtInstImport \"GLSL.std.450\"\n" +
8014fd4e5da5Sopenharmony_ci           "; CHECK: OpFunction\n" +
8015fd4e5da5Sopenharmony_ci           "; CHECK: [[x:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
8016fd4e5da5Sopenharmony_ci           "; CHECK: [[y:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
8017fd4e5da5Sopenharmony_ci           "; CHECK: [[a:%\\w+]] = OpVariable {{%\\w+}} Function\n" +
8018fd4e5da5Sopenharmony_ci           "; CHECK: [[lx:%\\w+]] = OpLoad {{%\\w+}} [[x]]\n" +
8019fd4e5da5Sopenharmony_ci           "; CHECK: [[ly:%\\w+]] = OpLoad {{%\\w+}} [[y]]\n" +
8020fd4e5da5Sopenharmony_ci           "; CHECK: [[la:%\\w+]] = OpLoad {{%\\w+}} [[a]]\n" +
8021fd4e5da5Sopenharmony_ci           "; CHECK: [[nx:%\\w+]] = OpFNegate {{%\\w+}} [[lx]]\n" +
8022fd4e5da5Sopenharmony_ci           "; CHECK: [[fma:%\\w+]] = OpExtInst {{%\\w+}} [[ext]] Fma [[nx]] [[ly]] [[la]]\n" +
8023fd4e5da5Sopenharmony_ci           "; CHECK: OpStore {{%\\w+}} [[fma]]\n" +
8024fd4e5da5Sopenharmony_ci           "%main = OpFunction %void None %void_func\n" +
8025fd4e5da5Sopenharmony_ci           "%main_lab = OpLabel\n" +
8026fd4e5da5Sopenharmony_ci           "%x = OpVariable %_ptr_float Function\n" +
8027fd4e5da5Sopenharmony_ci           "%y = OpVariable %_ptr_float Function\n" +
8028fd4e5da5Sopenharmony_ci           "%a = OpVariable %_ptr_float Function\n" +
8029fd4e5da5Sopenharmony_ci           "%lx = OpLoad %float %x\n" +
8030fd4e5da5Sopenharmony_ci           "%ly = OpLoad %float %y\n" +
8031fd4e5da5Sopenharmony_ci           "%mul = OpFMul %float %lx %ly\n" +
8032fd4e5da5Sopenharmony_ci           "%la = OpLoad %float %a\n" +
8033fd4e5da5Sopenharmony_ci           "%3 = OpFSub %float %la %mul\n" +
8034fd4e5da5Sopenharmony_ci           "OpStore %a %3\n" +
8035fd4e5da5Sopenharmony_ci           "OpReturn\n" +
8036fd4e5da5Sopenharmony_ci           "OpFunctionEnd",
8037fd4e5da5Sopenharmony_ci       3, true)
8038fd4e5da5Sopenharmony_ci));
8039fd4e5da5Sopenharmony_ci
8040fd4e5da5Sopenharmony_ciusing MatchingInstructionWithNoResultFoldingTest =
8041fd4e5da5Sopenharmony_ci::testing::TestWithParam<InstructionFoldingCase<bool>>;
8042fd4e5da5Sopenharmony_ci
8043fd4e5da5Sopenharmony_ci// Test folding instructions that do not have a result.  The instruction
8044fd4e5da5Sopenharmony_ci// that will be folded is the last instruction before the return.  If there
8045fd4e5da5Sopenharmony_ci// are multiple returns, there is not guarantee which one is used.
8046fd4e5da5Sopenharmony_ciTEST_P(MatchingInstructionWithNoResultFoldingTest, Case) {
8047fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
8048fd4e5da5Sopenharmony_ci
8049fd4e5da5Sopenharmony_ci  // Build module.
8050fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
8051fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
8052fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
8053fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
8054fd4e5da5Sopenharmony_ci
8055fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
8056fd4e5da5Sopenharmony_ci  Instruction* inst = nullptr;
8057fd4e5da5Sopenharmony_ci  Function* func = &*context->module()->begin();
8058fd4e5da5Sopenharmony_ci  for (auto& bb : *func) {
8059fd4e5da5Sopenharmony_ci    Instruction* terminator = bb.terminator();
8060fd4e5da5Sopenharmony_ci    if (terminator->IsReturnOrAbort()) {
8061fd4e5da5Sopenharmony_ci      inst = terminator->PreviousNode();
8062fd4e5da5Sopenharmony_ci      break;
8063fd4e5da5Sopenharmony_ci    }
8064fd4e5da5Sopenharmony_ci  }
8065fd4e5da5Sopenharmony_ci  assert(inst && "Invalid test.  Could not find instruction to fold.");
8066fd4e5da5Sopenharmony_ci  std::unique_ptr<Instruction> original_inst(inst->Clone(context.get()));
8067fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
8068fd4e5da5Sopenharmony_ci  EXPECT_EQ(succeeded, tc.expected_result);
8069fd4e5da5Sopenharmony_ci  if (succeeded) {
8070fd4e5da5Sopenharmony_ci    Match(tc.test_body, context.get());
8071fd4e5da5Sopenharmony_ci  }
8072fd4e5da5Sopenharmony_ci}
8073fd4e5da5Sopenharmony_ci
8074fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(StoreMatchingTest, MatchingInstructionWithNoResultFoldingTest,
8075fd4e5da5Sopenharmony_ci::testing::Values(
8076fd4e5da5Sopenharmony_ci    // Test case 0: Remove store of undef.
8077fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8078fd4e5da5Sopenharmony_ci        Header() +
8079fd4e5da5Sopenharmony_ci            "; CHECK: OpLabel\n" +
8080fd4e5da5Sopenharmony_ci            "; CHECK-NOT: OpStore\n" +
8081fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8082fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8083fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8084fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
8085fd4e5da5Sopenharmony_ci            "%undef = OpUndef %v4double\n" +
8086fd4e5da5Sopenharmony_ci            "OpStore %n %undef\n" +
8087fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8088fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8089fd4e5da5Sopenharmony_ci        0 /* OpStore */, true),
8090fd4e5da5Sopenharmony_ci    // Test case 1: Keep volatile store.
8091fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8092fd4e5da5Sopenharmony_ci        Header() +
8093fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8094fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8095fd4e5da5Sopenharmony_ci            "%n = OpVariable %_ptr_v4double Function\n" +
8096fd4e5da5Sopenharmony_ci            "%undef = OpUndef %v4double\n" +
8097fd4e5da5Sopenharmony_ci            "OpStore %n %undef Volatile\n" +
8098fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8099fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8100fd4e5da5Sopenharmony_ci        0 /* OpStore */, false)
8101fd4e5da5Sopenharmony_ci));
8102fd4e5da5Sopenharmony_ci
8103fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(VectorShuffleMatchingTest, MatchingInstructionWithNoResultFoldingTest,
8104fd4e5da5Sopenharmony_ci::testing::Values(
8105fd4e5da5Sopenharmony_ci    // Test case 0: Basic test 1
8106fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8107fd4e5da5Sopenharmony_ci        Header() +
8108fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8109fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} %7 %5 2 3 6 7\n" +
8110fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8111fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8112fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8113fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8114fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8115fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8116fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8117fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8118fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8119fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v4double %5 %6 2 3 4 5\n" +
8120fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %7 %8 2 3 4 5\n" +
8121fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8122fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8123fd4e5da5Sopenharmony_ci        9, true),
8124fd4e5da5Sopenharmony_ci    // Test case 1: Basic test 2
8125fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8126fd4e5da5Sopenharmony_ci        Header() +
8127fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8128fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} %6 %7 0 1 4 5\n" +
8129fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8130fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8131fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8132fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8133fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8134fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8135fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8136fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8137fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8138fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v4double %5 %6 2 3 4 5\n" +
8139fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %8 %7 2 3 4 5\n" +
8140fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8141fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8142fd4e5da5Sopenharmony_ci        9, true),
8143fd4e5da5Sopenharmony_ci    // Test case 2: Basic test 3
8144fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8145fd4e5da5Sopenharmony_ci        Header() +
8146fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8147fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} %5 %7 3 2 4 5\n" +
8148fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8149fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8150fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8151fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8152fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8153fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8154fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8155fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8156fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8157fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v4double %5 %6 2 3 4 5\n" +
8158fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %8 %7 1 0 4 5\n" +
8159fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8160fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8161fd4e5da5Sopenharmony_ci        9, true),
8162fd4e5da5Sopenharmony_ci    // Test case 3: Basic test 4
8163fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8164fd4e5da5Sopenharmony_ci        Header() +
8165fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8166fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} %7 %6 2 3 5 4\n" +
8167fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8168fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8169fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8170fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8171fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8172fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8173fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8174fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8175fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8176fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v4double %5 %6 2 3 4 5\n" +
8177fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %7 %8 2 3 7 6\n" +
8178fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8179fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8180fd4e5da5Sopenharmony_ci        9, true),
8181fd4e5da5Sopenharmony_ci    // Test case 4: Don't fold, need both operands of the feeder.
8182fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8183fd4e5da5Sopenharmony_ci        Header() +
8184fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8185fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8186fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8187fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8188fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8189fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8190fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8191fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8192fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v4double %5 %6 2 3 4 5\n" +
8193fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %7 %8 2 3 7 5\n" +
8194fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8195fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8196fd4e5da5Sopenharmony_ci        9, false),
8197fd4e5da5Sopenharmony_ci    // Test case 5: Don't fold, need both operands of the feeder.
8198fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8199fd4e5da5Sopenharmony_ci        Header() +
8200fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8201fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8202fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8203fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8204fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8205fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8206fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8207fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8208fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v4double %5 %6 2 3 4 5\n" +
8209fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %8 %7 2 0 7 5\n" +
8210fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8211fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8212fd4e5da5Sopenharmony_ci        9, false),
8213fd4e5da5Sopenharmony_ci    // Test case 6: Fold, need both operands of the feeder, but they are the same.
8214fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8215fd4e5da5Sopenharmony_ci        Header() +
8216fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8217fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} %5 %7 0 2 7 5\n" +
8218fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8219fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8220fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8221fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8222fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8223fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8224fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8225fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8226fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8227fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v4double %5 %5 2 3 4 5\n" +
8228fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %8 %7 2 0 7 5\n" +
8229fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8230fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8231fd4e5da5Sopenharmony_ci        9, true),
8232fd4e5da5Sopenharmony_ci    // Test case 7: Fold, need both operands of the feeder, but they are the same.
8233fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8234fd4e5da5Sopenharmony_ci        Header() +
8235fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8236fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} %7 %5 2 0 5 7\n" +
8237fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8238fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8239fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8240fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8241fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8242fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8243fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8244fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8245fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8246fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v4double %5 %5 2 3 4 5\n" +
8247fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %7 %8 2 0 7 5\n" +
8248fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8249fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8250fd4e5da5Sopenharmony_ci        9, true),
8251fd4e5da5Sopenharmony_ci    // Test case 8: Replace first operand with a smaller vector.
8252fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8253fd4e5da5Sopenharmony_ci        Header() +
8254fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8255fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} %5 %7 0 0 5 3\n" +
8256fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8257fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8258fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8259fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v2double Function\n" +
8260fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8261fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8262fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v2double %2\n" +
8263fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8264fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8265fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v4double %5 %5 0 1 2 3\n" +
8266fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %8 %7 2 0 7 5\n" +
8267fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8268fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8269fd4e5da5Sopenharmony_ci        9, true),
8270fd4e5da5Sopenharmony_ci    // Test case 9: Replace first operand with a larger vector.
8271fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8272fd4e5da5Sopenharmony_ci        Header() +
8273fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8274fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} %5 %7 3 0 7 5\n" +
8275fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8276fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8277fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8278fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8279fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8280fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8281fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8282fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8283fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8284fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v2double %5 %5 0 3\n" +
8285fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %8 %7 1 0 5 3\n" +
8286fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8287fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8288fd4e5da5Sopenharmony_ci        9, true),
8289fd4e5da5Sopenharmony_ci    // Test case 10: Replace unused operand with null.
8290fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8291fd4e5da5Sopenharmony_ci        Header() +
8292fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
8293fd4e5da5Sopenharmony_ci            "; CHECK: [[v4double:%\\w+]] = OpTypeVector [[double]] 2\n" +
8294fd4e5da5Sopenharmony_ci            "; CHECK: [[null:%\\w+]] = OpConstantNull [[v4double]]\n" +
8295fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8296fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} [[null]] %7 4 2 5 3\n" +
8297fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8298fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8299fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8300fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8301fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8302fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8303fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8304fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8305fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8306fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v2double %5 %5 0 3\n" +
8307fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %8 %7 4 2 5 3\n" +
8308fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8309fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8310fd4e5da5Sopenharmony_ci        9, true),
8311fd4e5da5Sopenharmony_ci    // Test case 11: Replace unused operand with null.
8312fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8313fd4e5da5Sopenharmony_ci        Header() +
8314fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
8315fd4e5da5Sopenharmony_ci            "; CHECK: [[v4double:%\\w+]] = OpTypeVector [[double]] 2\n" +
8316fd4e5da5Sopenharmony_ci            "; CHECK: [[null:%\\w+]] = OpConstantNull [[v4double]]\n" +
8317fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8318fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} [[null]] %5 2 2 5 5\n" +
8319fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8320fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8321fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8322fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8323fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8324fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8325fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8326fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v2double %5 %5 0 3\n" +
8327fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %8 %8 2 2 3 3\n" +
8328fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8329fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8330fd4e5da5Sopenharmony_ci        9, true),
8331fd4e5da5Sopenharmony_ci    // Test case 12: Replace unused operand with null.
8332fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8333fd4e5da5Sopenharmony_ci        Header() +
8334fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
8335fd4e5da5Sopenharmony_ci            "; CHECK: [[v4double:%\\w+]] = OpTypeVector [[double]] 2\n" +
8336fd4e5da5Sopenharmony_ci            "; CHECK: [[null:%\\w+]] = OpConstantNull [[v4double]]\n" +
8337fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8338fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} %7 [[null]] 2 0 1 3\n" +
8339fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8340fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8341fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8342fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8343fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8344fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8345fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8346fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8347fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8348fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v2double %5 %5 0 3\n" +
8349fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %7 %8 2 0 1 3\n" +
8350fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8351fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8352fd4e5da5Sopenharmony_ci        9, true),
8353fd4e5da5Sopenharmony_ci    // Test case 13: Shuffle with undef literal.
8354fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8355fd4e5da5Sopenharmony_ci        Header() +
8356fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
8357fd4e5da5Sopenharmony_ci            "; CHECK: [[v4double:%\\w+]] = OpTypeVector [[double]] 2\n" +
8358fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8359fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} %7 {{%\\w+}} 2 0 1 4294967295\n" +
8360fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8361fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8362fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8363fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8364fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8365fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8366fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8367fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8368fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8369fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v2double %5 %5 0 1\n" +
8370fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %7 %8 2 0 1 4294967295\n" +
8371fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8372fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8373fd4e5da5Sopenharmony_ci        9, true),
8374fd4e5da5Sopenharmony_ci    // Test case 14: Shuffle with undef literal and change size of first input vector.
8375fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(
8376fd4e5da5Sopenharmony_ci        Header() +
8377fd4e5da5Sopenharmony_ci            "; CHECK: [[double:%\\w+]] = OpTypeFloat 64\n" +
8378fd4e5da5Sopenharmony_ci            "; CHECK: [[v4double:%\\w+]] = OpTypeVector [[double]] 2\n" +
8379fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle\n" +
8380fd4e5da5Sopenharmony_ci            "; CHECK: OpVectorShuffle {{%\\w+}} %5 %7 0 1 4 4294967295\n" +
8381fd4e5da5Sopenharmony_ci            "; CHECK: OpReturn\n" +
8382fd4e5da5Sopenharmony_ci            "%main = OpFunction %void None %void_func\n" +
8383fd4e5da5Sopenharmony_ci            "%main_lab = OpLabel\n" +
8384fd4e5da5Sopenharmony_ci            "%2 = OpVariable %_ptr_v4double Function\n" +
8385fd4e5da5Sopenharmony_ci            "%3 = OpVariable %_ptr_v4double Function\n" +
8386fd4e5da5Sopenharmony_ci            "%4 = OpVariable %_ptr_v4double Function\n" +
8387fd4e5da5Sopenharmony_ci            "%5 = OpLoad %v4double %2\n" +
8388fd4e5da5Sopenharmony_ci            "%6 = OpLoad %v4double %3\n" +
8389fd4e5da5Sopenharmony_ci            "%7 = OpLoad %v4double %4\n" +
8390fd4e5da5Sopenharmony_ci            "%8 = OpVectorShuffle %v2double %5 %5 0 1\n" +
8391fd4e5da5Sopenharmony_ci            "%9 = OpVectorShuffle %v4double %8 %7 0 1 2 4294967295\n" +
8392fd4e5da5Sopenharmony_ci            "OpReturn\n" +
8393fd4e5da5Sopenharmony_ci            "OpFunctionEnd",
8394fd4e5da5Sopenharmony_ci        9, true)
8395fd4e5da5Sopenharmony_ci));
8396fd4e5da5Sopenharmony_ci
8397fd4e5da5Sopenharmony_ciusing EntryPointFoldingTest =
8398fd4e5da5Sopenharmony_ci::testing::TestWithParam<InstructionFoldingCase<bool>>;
8399fd4e5da5Sopenharmony_ci
8400fd4e5da5Sopenharmony_ciTEST_P(EntryPointFoldingTest, Case) {
8401fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
8402fd4e5da5Sopenharmony_ci
8403fd4e5da5Sopenharmony_ci  // Build module.
8404fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
8405fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_1, nullptr, tc.test_body,
8406fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
8407fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
8408fd4e5da5Sopenharmony_ci
8409fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
8410fd4e5da5Sopenharmony_ci  Instruction* inst = nullptr;
8411fd4e5da5Sopenharmony_ci  inst = &*context->module()->entry_points().begin();
8412fd4e5da5Sopenharmony_ci  assert(inst && "Invalid test.  Could not find entry point instruction to fold.");
8413fd4e5da5Sopenharmony_ci  std::unique_ptr<Instruction> original_inst(inst->Clone(context.get()));
8414fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
8415fd4e5da5Sopenharmony_ci  EXPECT_EQ(succeeded, tc.expected_result);
8416fd4e5da5Sopenharmony_ci  if (succeeded) {
8417fd4e5da5Sopenharmony_ci    Match(tc.test_body, context.get());
8418fd4e5da5Sopenharmony_ci  }
8419fd4e5da5Sopenharmony_ci}
8420fd4e5da5Sopenharmony_ci
8421fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(OpEntryPointFoldingTest, EntryPointFoldingTest,
8422fd4e5da5Sopenharmony_ci::testing::Values(
8423fd4e5da5Sopenharmony_ci    // Test case 0: Basic test 1
8424fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(std::string() +
8425fd4e5da5Sopenharmony_ci                    "; CHECK: OpEntryPoint Fragment %2 \"main\" %3\n" +
8426fd4e5da5Sopenharmony_ci                             "OpCapability Shader\n" +
8427fd4e5da5Sopenharmony_ci                        "%1 = OpExtInstImport \"GLSL.std.450\"\n" +
8428fd4e5da5Sopenharmony_ci                             "OpMemoryModel Logical GLSL450\n" +
8429fd4e5da5Sopenharmony_ci                             "OpEntryPoint Fragment %2 \"main\" %3 %3 %3\n" +
8430fd4e5da5Sopenharmony_ci                             "OpExecutionMode %2 OriginUpperLeft\n" +
8431fd4e5da5Sopenharmony_ci                             "OpSource GLSL 430\n" +
8432fd4e5da5Sopenharmony_ci                             "OpDecorate %3 Location 0\n" +
8433fd4e5da5Sopenharmony_ci                     "%void = OpTypeVoid\n" +
8434fd4e5da5Sopenharmony_ci                        "%5 = OpTypeFunction %void\n" +
8435fd4e5da5Sopenharmony_ci                    "%float = OpTypeFloat 32\n" +
8436fd4e5da5Sopenharmony_ci                  "%v4float = OpTypeVector %float 4\n" +
8437fd4e5da5Sopenharmony_ci      "%_ptr_Output_v4float = OpTypePointer Output %v4float\n" +
8438fd4e5da5Sopenharmony_ci                        "%3 = OpVariable %_ptr_Output_v4float Output\n" +
8439fd4e5da5Sopenharmony_ci                      "%int = OpTypeInt 32 1\n" +
8440fd4e5da5Sopenharmony_ci                    "%int_0 = OpConstant %int 0\n" +
8441fd4e5da5Sopenharmony_ci"%_ptr_PushConstant_v4float = OpTypePointer PushConstant %v4float\n" +
8442fd4e5da5Sopenharmony_ci                        "%2 = OpFunction %void None %5\n" +
8443fd4e5da5Sopenharmony_ci                       "%12 = OpLabel\n" +
8444fd4e5da5Sopenharmony_ci                             "OpReturn\n" +
8445fd4e5da5Sopenharmony_ci                             "OpFunctionEnd\n",
8446fd4e5da5Sopenharmony_ci        9, true),
8447fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(std::string() +
8448fd4e5da5Sopenharmony_ci                    "; CHECK: OpEntryPoint Fragment %2 \"main\" %3 %4\n" +
8449fd4e5da5Sopenharmony_ci                             "OpCapability Shader\n" +
8450fd4e5da5Sopenharmony_ci                        "%1 = OpExtInstImport \"GLSL.std.450\"\n" +
8451fd4e5da5Sopenharmony_ci                             "OpMemoryModel Logical GLSL450\n" +
8452fd4e5da5Sopenharmony_ci                             "OpEntryPoint Fragment %2 \"main\" %3 %4 %3\n" +
8453fd4e5da5Sopenharmony_ci                             "OpExecutionMode %2 OriginUpperLeft\n" +
8454fd4e5da5Sopenharmony_ci                             "OpSource GLSL 430\n" +
8455fd4e5da5Sopenharmony_ci                             "OpDecorate %3 Location 0\n" +
8456fd4e5da5Sopenharmony_ci                     "%void = OpTypeVoid\n" +
8457fd4e5da5Sopenharmony_ci                        "%5 = OpTypeFunction %void\n" +
8458fd4e5da5Sopenharmony_ci                    "%float = OpTypeFloat 32\n" +
8459fd4e5da5Sopenharmony_ci                  "%v4float = OpTypeVector %float 4\n" +
8460fd4e5da5Sopenharmony_ci      "%_ptr_Output_v4float = OpTypePointer Output %v4float\n" +
8461fd4e5da5Sopenharmony_ci                        "%3 = OpVariable %_ptr_Output_v4float Output\n" +
8462fd4e5da5Sopenharmony_ci                        "%4 = OpVariable %_ptr_Output_v4float Output\n" +
8463fd4e5da5Sopenharmony_ci                      "%int = OpTypeInt 32 1\n" +
8464fd4e5da5Sopenharmony_ci                    "%int_0 = OpConstant %int 0\n" +
8465fd4e5da5Sopenharmony_ci"%_ptr_PushConstant_v4float = OpTypePointer PushConstant %v4float\n" +
8466fd4e5da5Sopenharmony_ci                        "%2 = OpFunction %void None %5\n" +
8467fd4e5da5Sopenharmony_ci                       "%12 = OpLabel\n" +
8468fd4e5da5Sopenharmony_ci                             "OpReturn\n" +
8469fd4e5da5Sopenharmony_ci                             "OpFunctionEnd\n",
8470fd4e5da5Sopenharmony_ci        9, true),
8471fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(std::string() +
8472fd4e5da5Sopenharmony_ci                    "; CHECK: OpEntryPoint Fragment %2 \"main\" %4 %3\n" +
8473fd4e5da5Sopenharmony_ci                             "OpCapability Shader\n" +
8474fd4e5da5Sopenharmony_ci                        "%1 = OpExtInstImport \"GLSL.std.450\"\n" +
8475fd4e5da5Sopenharmony_ci                             "OpMemoryModel Logical GLSL450\n" +
8476fd4e5da5Sopenharmony_ci                             "OpEntryPoint Fragment %2 \"main\" %4 %4 %3\n" +
8477fd4e5da5Sopenharmony_ci                             "OpExecutionMode %2 OriginUpperLeft\n" +
8478fd4e5da5Sopenharmony_ci                             "OpSource GLSL 430\n" +
8479fd4e5da5Sopenharmony_ci                             "OpDecorate %3 Location 0\n" +
8480fd4e5da5Sopenharmony_ci                     "%void = OpTypeVoid\n" +
8481fd4e5da5Sopenharmony_ci                        "%5 = OpTypeFunction %void\n" +
8482fd4e5da5Sopenharmony_ci                    "%float = OpTypeFloat 32\n" +
8483fd4e5da5Sopenharmony_ci                  "%v4float = OpTypeVector %float 4\n" +
8484fd4e5da5Sopenharmony_ci      "%_ptr_Output_v4float = OpTypePointer Output %v4float\n" +
8485fd4e5da5Sopenharmony_ci                        "%3 = OpVariable %_ptr_Output_v4float Output\n" +
8486fd4e5da5Sopenharmony_ci                        "%4 = OpVariable %_ptr_Output_v4float Output\n" +
8487fd4e5da5Sopenharmony_ci                      "%int = OpTypeInt 32 1\n" +
8488fd4e5da5Sopenharmony_ci                    "%int_0 = OpConstant %int 0\n" +
8489fd4e5da5Sopenharmony_ci"%_ptr_PushConstant_v4float = OpTypePointer PushConstant %v4float\n" +
8490fd4e5da5Sopenharmony_ci                        "%2 = OpFunction %void None %5\n" +
8491fd4e5da5Sopenharmony_ci                       "%12 = OpLabel\n" +
8492fd4e5da5Sopenharmony_ci                             "OpReturn\n" +
8493fd4e5da5Sopenharmony_ci                             "OpFunctionEnd\n",
8494fd4e5da5Sopenharmony_ci        9, true)
8495fd4e5da5Sopenharmony_ci));
8496fd4e5da5Sopenharmony_ci
8497fd4e5da5Sopenharmony_ciusing SPV14FoldingTest =
8498fd4e5da5Sopenharmony_ci::testing::TestWithParam<InstructionFoldingCase<bool>>;
8499fd4e5da5Sopenharmony_ci
8500fd4e5da5Sopenharmony_ciTEST_P(SPV14FoldingTest, Case) {
8501fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
8502fd4e5da5Sopenharmony_ci
8503fd4e5da5Sopenharmony_ci  // Build module.
8504fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
8505fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_4, nullptr, tc.test_body,
8506fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
8507fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
8508fd4e5da5Sopenharmony_ci
8509fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
8510fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
8511fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
8512fd4e5da5Sopenharmony_ci  std::unique_ptr<Instruction> original_inst(inst->Clone(context.get()));
8513fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
8514fd4e5da5Sopenharmony_ci  EXPECT_EQ(succeeded, tc.expected_result);
8515fd4e5da5Sopenharmony_ci  if (succeeded) {
8516fd4e5da5Sopenharmony_ci    Match(tc.test_body, context.get());
8517fd4e5da5Sopenharmony_ci  }
8518fd4e5da5Sopenharmony_ci}
8519fd4e5da5Sopenharmony_ci
8520fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(SPV14FoldingTest, SPV14FoldingTest,
8521fd4e5da5Sopenharmony_ci::testing::Values(
8522fd4e5da5Sopenharmony_ci    // Test case 0: select vectors with scalar condition.
8523fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(std::string() +
8524fd4e5da5Sopenharmony_ci"; CHECK-NOT: OpSelect\n" +
8525fd4e5da5Sopenharmony_ci"; CHECK: %3 = OpCopyObject {{%\\w+}} %1\n" +
8526fd4e5da5Sopenharmony_ci"OpCapability Shader\n" +
8527fd4e5da5Sopenharmony_ci"OpCapability Linkage\n" +
8528fd4e5da5Sopenharmony_ci"%void = OpTypeVoid\n" +
8529fd4e5da5Sopenharmony_ci"%bool = OpTypeBool\n" +
8530fd4e5da5Sopenharmony_ci"%true = OpConstantTrue %bool\n" +
8531fd4e5da5Sopenharmony_ci"%int = OpTypeInt 32 0\n" +
8532fd4e5da5Sopenharmony_ci"%int4 = OpTypeVector %int 4\n" +
8533fd4e5da5Sopenharmony_ci"%int_0 = OpConstant %int 0\n" +
8534fd4e5da5Sopenharmony_ci"%int_1 = OpConstant %int 1\n" +
8535fd4e5da5Sopenharmony_ci"%1 = OpUndef %int4\n" +
8536fd4e5da5Sopenharmony_ci"%2 = OpUndef %int4\n" +
8537fd4e5da5Sopenharmony_ci"%void_fn = OpTypeFunction %void\n" +
8538fd4e5da5Sopenharmony_ci"%func = OpFunction %void None %void_fn\n" +
8539fd4e5da5Sopenharmony_ci"%entry = OpLabel\n" +
8540fd4e5da5Sopenharmony_ci"%3 = OpSelect %int4 %true %1 %2\n" +
8541fd4e5da5Sopenharmony_ci"OpReturn\n" +
8542fd4e5da5Sopenharmony_ci"OpFunctionEnd\n"
8543fd4e5da5Sopenharmony_ci,
8544fd4e5da5Sopenharmony_ci                                 3, true),
8545fd4e5da5Sopenharmony_ci    // Test case 1: select struct with scalar condition.
8546fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(std::string() +
8547fd4e5da5Sopenharmony_ci"; CHECK-NOT: OpSelect\n" +
8548fd4e5da5Sopenharmony_ci"; CHECK: %3 = OpCopyObject {{%\\w+}} %2\n" +
8549fd4e5da5Sopenharmony_ci"OpCapability Shader\n" +
8550fd4e5da5Sopenharmony_ci"OpCapability Linkage\n" +
8551fd4e5da5Sopenharmony_ci"%void = OpTypeVoid\n" +
8552fd4e5da5Sopenharmony_ci"%bool = OpTypeBool\n" +
8553fd4e5da5Sopenharmony_ci"%true = OpConstantFalse %bool\n" +
8554fd4e5da5Sopenharmony_ci"%int = OpTypeInt 32 0\n" +
8555fd4e5da5Sopenharmony_ci"%struct = OpTypeStruct %int %int %int %int\n" +
8556fd4e5da5Sopenharmony_ci"%int_0 = OpConstant %int 0\n" +
8557fd4e5da5Sopenharmony_ci"%int_1 = OpConstant %int 1\n" +
8558fd4e5da5Sopenharmony_ci"%1 = OpUndef %struct\n" +
8559fd4e5da5Sopenharmony_ci"%2 = OpUndef %struct\n" +
8560fd4e5da5Sopenharmony_ci"%void_fn = OpTypeFunction %void\n" +
8561fd4e5da5Sopenharmony_ci"%func = OpFunction %void None %void_fn\n" +
8562fd4e5da5Sopenharmony_ci"%entry = OpLabel\n" +
8563fd4e5da5Sopenharmony_ci"%3 = OpSelect %struct %true %1 %2\n" +
8564fd4e5da5Sopenharmony_ci"OpReturn\n" +
8565fd4e5da5Sopenharmony_ci"OpFunctionEnd\n"
8566fd4e5da5Sopenharmony_ci,
8567fd4e5da5Sopenharmony_ci                                 3, true),
8568fd4e5da5Sopenharmony_ci    // Test case 1: select array with scalar condition.
8569fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(std::string() +
8570fd4e5da5Sopenharmony_ci"; CHECK-NOT: OpSelect\n" +
8571fd4e5da5Sopenharmony_ci"; CHECK: %3 = OpCopyObject {{%\\w+}} %2\n" +
8572fd4e5da5Sopenharmony_ci"OpCapability Shader\n" +
8573fd4e5da5Sopenharmony_ci"OpCapability Linkage\n" +
8574fd4e5da5Sopenharmony_ci"%void = OpTypeVoid\n" +
8575fd4e5da5Sopenharmony_ci"%bool = OpTypeBool\n" +
8576fd4e5da5Sopenharmony_ci"%true = OpConstantFalse %bool\n" +
8577fd4e5da5Sopenharmony_ci"%int = OpTypeInt 32 0\n" +
8578fd4e5da5Sopenharmony_ci"%int_0 = OpConstant %int 0\n" +
8579fd4e5da5Sopenharmony_ci"%int_1 = OpConstant %int 1\n" +
8580fd4e5da5Sopenharmony_ci"%int_4 = OpConstant %int 4\n" +
8581fd4e5da5Sopenharmony_ci"%array = OpTypeStruct %int %int %int %int\n" +
8582fd4e5da5Sopenharmony_ci"%1 = OpUndef %array\n" +
8583fd4e5da5Sopenharmony_ci"%2 = OpUndef %array\n" +
8584fd4e5da5Sopenharmony_ci"%void_fn = OpTypeFunction %void\n" +
8585fd4e5da5Sopenharmony_ci"%func = OpFunction %void None %void_fn\n" +
8586fd4e5da5Sopenharmony_ci"%entry = OpLabel\n" +
8587fd4e5da5Sopenharmony_ci"%3 = OpSelect %array %true %1 %2\n" +
8588fd4e5da5Sopenharmony_ci"OpReturn\n" +
8589fd4e5da5Sopenharmony_ci"OpFunctionEnd\n"
8590fd4e5da5Sopenharmony_ci,
8591fd4e5da5Sopenharmony_ci                                 3, true)
8592fd4e5da5Sopenharmony_ci));
8593fd4e5da5Sopenharmony_ci
8594fd4e5da5Sopenharmony_cistd::string FloatControlsHeader(const std::string& capabilities) {
8595fd4e5da5Sopenharmony_ci  std::string header = R"(
8596fd4e5da5Sopenharmony_ciOpCapability Shader
8597fd4e5da5Sopenharmony_ci)" + capabilities + R"(
8598fd4e5da5Sopenharmony_ci%void = OpTypeVoid
8599fd4e5da5Sopenharmony_ci%float = OpTypeFloat 32
8600fd4e5da5Sopenharmony_ci%float_0 = OpConstant %float 0
8601fd4e5da5Sopenharmony_ci%float_1 = OpConstant %float 1
8602fd4e5da5Sopenharmony_ci%void_fn = OpTypeFunction %void
8603fd4e5da5Sopenharmony_ci%func = OpFunction %void None %void_fn
8604fd4e5da5Sopenharmony_ci%entry = OpLabel
8605fd4e5da5Sopenharmony_ci)";
8606fd4e5da5Sopenharmony_ci
8607fd4e5da5Sopenharmony_ci  return header;
8608fd4e5da5Sopenharmony_ci}
8609fd4e5da5Sopenharmony_ci
8610fd4e5da5Sopenharmony_ciusing FloatControlsFoldingTest =
8611fd4e5da5Sopenharmony_ci::testing::TestWithParam<InstructionFoldingCase<bool>>;
8612fd4e5da5Sopenharmony_ci
8613fd4e5da5Sopenharmony_ciTEST_P(FloatControlsFoldingTest, Case) {
8614fd4e5da5Sopenharmony_ci  const auto& tc = GetParam();
8615fd4e5da5Sopenharmony_ci
8616fd4e5da5Sopenharmony_ci  // Build module.
8617fd4e5da5Sopenharmony_ci  std::unique_ptr<IRContext> context =
8618fd4e5da5Sopenharmony_ci      BuildModule(SPV_ENV_UNIVERSAL_1_4, nullptr, tc.test_body,
8619fd4e5da5Sopenharmony_ci                  SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
8620fd4e5da5Sopenharmony_ci  ASSERT_NE(nullptr, context);
8621fd4e5da5Sopenharmony_ci
8622fd4e5da5Sopenharmony_ci  // Fold the instruction to test.
8623fd4e5da5Sopenharmony_ci  analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
8624fd4e5da5Sopenharmony_ci  Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
8625fd4e5da5Sopenharmony_ci  std::unique_ptr<Instruction> original_inst(inst->Clone(context.get()));
8626fd4e5da5Sopenharmony_ci  bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
8627fd4e5da5Sopenharmony_ci  EXPECT_EQ(succeeded, tc.expected_result);
8628fd4e5da5Sopenharmony_ci  if (succeeded) {
8629fd4e5da5Sopenharmony_ci    Match(tc.test_body, context.get());
8630fd4e5da5Sopenharmony_ci  }
8631fd4e5da5Sopenharmony_ci}
8632fd4e5da5Sopenharmony_ci
8633fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(FloatControlsFoldingTest, FloatControlsFoldingTest,
8634fd4e5da5Sopenharmony_ci::testing::Values(
8635fd4e5da5Sopenharmony_ci    // Test case 0: no folding with DenormPreserve
8636fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(FloatControlsHeader("OpCapability DenormPreserve") +
8637fd4e5da5Sopenharmony_ci                                 "%1 = OpFAdd %float %float_0 %float_1\n" +
8638fd4e5da5Sopenharmony_ci                                 "OpReturn\n" +
8639fd4e5da5Sopenharmony_ci                                 "OpFunctionEnd\n"
8640fd4e5da5Sopenharmony_ci,
8641fd4e5da5Sopenharmony_ci                                 1, false),
8642fd4e5da5Sopenharmony_ci    // Test case 1: no folding with DenormFlushToZero
8643fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(FloatControlsHeader("OpCapability DenormFlushToZero") +
8644fd4e5da5Sopenharmony_ci                                 "%1 = OpFAdd %float %float_0 %float_1\n" +
8645fd4e5da5Sopenharmony_ci                                 "OpReturn\n" +
8646fd4e5da5Sopenharmony_ci                                 "OpFunctionEnd\n"
8647fd4e5da5Sopenharmony_ci,
8648fd4e5da5Sopenharmony_ci                                 1, false),
8649fd4e5da5Sopenharmony_ci    // Test case 2: no folding with SignedZeroInfNanPreserve
8650fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(FloatControlsHeader("OpCapability SignedZeroInfNanPreserve") +
8651fd4e5da5Sopenharmony_ci                                 "%1 = OpFAdd %float %float_0 %float_1\n" +
8652fd4e5da5Sopenharmony_ci                                 "OpReturn\n" +
8653fd4e5da5Sopenharmony_ci                                 "OpFunctionEnd\n"
8654fd4e5da5Sopenharmony_ci,
8655fd4e5da5Sopenharmony_ci                                 1, false),
8656fd4e5da5Sopenharmony_ci    // Test case 3: no folding with RoundingModeRTE
8657fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(FloatControlsHeader("OpCapability RoundingModeRTE") +
8658fd4e5da5Sopenharmony_ci                                 "%1 = OpFAdd %float %float_0 %float_1\n" +
8659fd4e5da5Sopenharmony_ci                                 "OpReturn\n" +
8660fd4e5da5Sopenharmony_ci                                 "OpFunctionEnd\n"
8661fd4e5da5Sopenharmony_ci,
8662fd4e5da5Sopenharmony_ci                                 1, false),
8663fd4e5da5Sopenharmony_ci    // Test case 4: no folding with RoundingModeRTZ
8664fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(FloatControlsHeader("OpCapability RoundingModeRTZ") +
8665fd4e5da5Sopenharmony_ci                                 "%1 = OpFAdd %float %float_0 %float_1\n" +
8666fd4e5da5Sopenharmony_ci                                 "OpReturn\n" +
8667fd4e5da5Sopenharmony_ci                                 "OpFunctionEnd\n"
8668fd4e5da5Sopenharmony_ci,
8669fd4e5da5Sopenharmony_ci                                 1, false)
8670fd4e5da5Sopenharmony_ci));
8671fd4e5da5Sopenharmony_ci
8672fd4e5da5Sopenharmony_cistd::string ImageOperandsTestBody(const std::string& image_instruction) {
8673fd4e5da5Sopenharmony_ci  std::string body = R"(
8674fd4e5da5Sopenharmony_ci               OpCapability Shader
8675fd4e5da5Sopenharmony_ci               OpCapability ImageGatherExtended
8676fd4e5da5Sopenharmony_ci               OpMemoryModel Logical GLSL450
8677fd4e5da5Sopenharmony_ci               OpEntryPoint Fragment %main "main"
8678fd4e5da5Sopenharmony_ci               OpExecutionMode %main OriginUpperLeft
8679fd4e5da5Sopenharmony_ci               OpDecorate %Texture DescriptorSet 0
8680fd4e5da5Sopenharmony_ci               OpDecorate %Texture Binding 0
8681fd4e5da5Sopenharmony_ci        %int = OpTypeInt 32 1
8682fd4e5da5Sopenharmony_ci     %int_n1 = OpConstant %int -1
8683fd4e5da5Sopenharmony_ci          %5 = OpConstant %int 0
8684fd4e5da5Sopenharmony_ci      %float = OpTypeFloat 32
8685fd4e5da5Sopenharmony_ci    %float_0 = OpConstant %float 0
8686fd4e5da5Sopenharmony_ci%type_2d_image = OpTypeImage %float 2D 2 0 0 1 Unknown
8687fd4e5da5Sopenharmony_ci%type_sampled_image = OpTypeSampledImage %type_2d_image
8688fd4e5da5Sopenharmony_ci%type_sampler = OpTypeSampler
8689fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_sampler = OpTypePointer UniformConstant %type_sampler
8690fd4e5da5Sopenharmony_ci%_ptr_UniformConstant_type_2d_image = OpTypePointer UniformConstant %type_2d_image
8691fd4e5da5Sopenharmony_ci   %_ptr_int = OpTypePointer Function %int
8692fd4e5da5Sopenharmony_ci      %v2int = OpTypeVector %int 2
8693fd4e5da5Sopenharmony_ci         %10 = OpTypeVector %float 4
8694fd4e5da5Sopenharmony_ci       %void = OpTypeVoid
8695fd4e5da5Sopenharmony_ci         %22 = OpTypeFunction %void
8696fd4e5da5Sopenharmony_ci    %v2float = OpTypeVector %float 2
8697fd4e5da5Sopenharmony_ci      %v3int = OpTypeVector %int 3
8698fd4e5da5Sopenharmony_ci    %Texture = OpVariable %_ptr_UniformConstant_type_2d_image UniformConstant
8699fd4e5da5Sopenharmony_ci   %gSampler = OpVariable %_ptr_UniformConstant_type_sampler UniformConstant
8700fd4e5da5Sopenharmony_ci        %110 = OpConstantComposite %v2int %5 %5
8701fd4e5da5Sopenharmony_ci        %101 = OpConstantComposite %v2int %int_n1 %int_n1
8702fd4e5da5Sopenharmony_ci         %20 = OpConstantComposite %v2float %float_0 %float_0
8703fd4e5da5Sopenharmony_ci       %main = OpFunction %void None %22
8704fd4e5da5Sopenharmony_ci         %23 = OpLabel
8705fd4e5da5Sopenharmony_ci        %var = OpVariable %_ptr_int Function
8706fd4e5da5Sopenharmony_ci         %88 = OpLoad %type_2d_image %Texture
8707fd4e5da5Sopenharmony_ci        %val = OpLoad %int %var
8708fd4e5da5Sopenharmony_ci    %sampler = OpLoad %type_sampler %gSampler
8709fd4e5da5Sopenharmony_ci         %26 = OpSampledImage %type_sampled_image %88 %sampler
8710fd4e5da5Sopenharmony_ci)" + image_instruction + R"(
8711fd4e5da5Sopenharmony_ci               OpReturn
8712fd4e5da5Sopenharmony_ci               OpFunctionEnd
8713fd4e5da5Sopenharmony_ci)";
8714fd4e5da5Sopenharmony_ci
8715fd4e5da5Sopenharmony_ci  return body;
8716fd4e5da5Sopenharmony_ci}
8717fd4e5da5Sopenharmony_ci
8718fd4e5da5Sopenharmony_ciINSTANTIATE_TEST_SUITE_P(ImageOperandsBitmaskFoldingTest, MatchingInstructionWithNoResultFoldingTest,
8719fd4e5da5Sopenharmony_ci::testing::Values(
8720fd4e5da5Sopenharmony_ci    // Test case 0: OpImageFetch without Offset
8721fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(ImageOperandsTestBody(
8722fd4e5da5Sopenharmony_ci        "%89 = OpImageFetch %10 %88 %101 Lod %5 \n")
8723fd4e5da5Sopenharmony_ci        , 89, false),
8724fd4e5da5Sopenharmony_ci    // Test case 1: OpImageFetch with non-const offset
8725fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(ImageOperandsTestBody(
8726fd4e5da5Sopenharmony_ci        "%89 = OpImageFetch %10 %88 %101 Lod|Offset %5 %val \n")
8727fd4e5da5Sopenharmony_ci        , 89, false),
8728fd4e5da5Sopenharmony_ci    // Test case 2: OpImageFetch with Lod and Offset
8729fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(ImageOperandsTestBody(
8730fd4e5da5Sopenharmony_ci      "         %89 = OpImageFetch %10 %88 %101 Lod|Offset %5 %101      \n"
8731fd4e5da5Sopenharmony_ci      "; CHECK: %89 = OpImageFetch %10 %88 %101 Lod|ConstOffset %5 %101 \n")
8732fd4e5da5Sopenharmony_ci      , 89, true),
8733fd4e5da5Sopenharmony_ci    // Test case 3: OpImageFetch with Bias and Offset
8734fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(ImageOperandsTestBody(
8735fd4e5da5Sopenharmony_ci      "         %89 = OpImageFetch %10 %88 %101 Bias|Offset %5 %101      \n"
8736fd4e5da5Sopenharmony_ci      "; CHECK: %89 = OpImageFetch %10 %88 %101 Bias|ConstOffset %5 %101 \n")
8737fd4e5da5Sopenharmony_ci      , 89, true),
8738fd4e5da5Sopenharmony_ci    // Test case 4: OpImageFetch with Grad and Offset.
8739fd4e5da5Sopenharmony_ci    // Grad adds 2 operands to the instruction.
8740fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(ImageOperandsTestBody(
8741fd4e5da5Sopenharmony_ci      "         %89 = OpImageFetch %10 %88 %101 Grad|Offset %5 %5 %101      \n"
8742fd4e5da5Sopenharmony_ci      "; CHECK: %89 = OpImageFetch %10 %88 %101 Grad|ConstOffset %5 %5 %101 \n")
8743fd4e5da5Sopenharmony_ci      , 89, true),
8744fd4e5da5Sopenharmony_ci    // Test case 5: OpImageFetch with Offset and MinLod.
8745fd4e5da5Sopenharmony_ci    // This is an example of a case where the bitmask bit-offset is larger than
8746fd4e5da5Sopenharmony_ci    // that of the Offset.
8747fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(ImageOperandsTestBody(
8748fd4e5da5Sopenharmony_ci      "         %89 = OpImageFetch %10 %88 %101 Offset|MinLod %101 %5      \n"
8749fd4e5da5Sopenharmony_ci      "; CHECK: %89 = OpImageFetch %10 %88 %101 ConstOffset|MinLod %101 %5 \n")
8750fd4e5da5Sopenharmony_ci      , 89, true),
8751fd4e5da5Sopenharmony_ci    // Test case 6: OpImageGather with constant Offset
8752fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(ImageOperandsTestBody(
8753fd4e5da5Sopenharmony_ci      "         %89 = OpImageGather %10 %26 %20 %5 Offset %101      \n"
8754fd4e5da5Sopenharmony_ci      "; CHECK: %89 = OpImageGather %10 %26 %20 %5 ConstOffset %101 \n")
8755fd4e5da5Sopenharmony_ci      , 89, true),
8756fd4e5da5Sopenharmony_ci    // Test case 7: OpImageWrite with constant Offset
8757fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(ImageOperandsTestBody(
8758fd4e5da5Sopenharmony_ci      "         OpImageWrite %88 %5 %101 Offset %101      \n"
8759fd4e5da5Sopenharmony_ci      "; CHECK: OpImageWrite %88 %5 %101 ConstOffset %101 \n")
8760fd4e5da5Sopenharmony_ci      , 0 /* No result-id */, true),
8761fd4e5da5Sopenharmony_ci    // Test case 8: OpImageFetch with zero constant Offset
8762fd4e5da5Sopenharmony_ci    InstructionFoldingCase<bool>(ImageOperandsTestBody(
8763fd4e5da5Sopenharmony_ci        "         %89 = OpImageFetch %10 %88 %101 Lod|Offset %5 %110      \n"
8764fd4e5da5Sopenharmony_ci        "; CHECK: %89 = OpImageFetch %10 %88 %101 Lod %5 \n")
8765fd4e5da5Sopenharmony_ci        , 89, true)
8766fd4e5da5Sopenharmony_ci));
8767fd4e5da5Sopenharmony_ci
8768fd4e5da5Sopenharmony_ci}  // namespace
8769fd4e5da5Sopenharmony_ci}  // namespace opt
8770fd4e5da5Sopenharmony_ci}  // namespace spvtools
8771