Add tests for folding 1.4 selects (#2568)
Fixes #2554 * Folding rules already handle 1.4 selects so I simply added some tests
This commit is contained in:
Родитель
ea5e1b62e1
Коммит
cc3e93c4e6
|
@ -6311,6 +6311,103 @@ INSTANTIATE_TEST_SUITE_P(OpEntryPointFoldingTest, EntryPointFoldingTest,
|
|||
9, true)
|
||||
));
|
||||
|
||||
using SPV14FoldingTest =
|
||||
::testing::TestWithParam<InstructionFoldingCase<bool>>;
|
||||
|
||||
TEST_P(SPV14FoldingTest, Case) {
|
||||
const auto& tc = GetParam();
|
||||
|
||||
// Build module.
|
||||
std::unique_ptr<IRContext> context =
|
||||
BuildModule(SPV_ENV_UNIVERSAL_1_4, nullptr, tc.test_body,
|
||||
SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
|
||||
ASSERT_NE(nullptr, context);
|
||||
|
||||
// Fold the instruction to test.
|
||||
analysis::DefUseManager* def_use_mgr = context->get_def_use_mgr();
|
||||
Instruction* inst = def_use_mgr->GetDef(tc.id_to_fold);
|
||||
std::unique_ptr<Instruction> original_inst(inst->Clone(context.get()));
|
||||
bool succeeded = context->get_instruction_folder().FoldInstruction(inst);
|
||||
EXPECT_EQ(succeeded, tc.expected_result);
|
||||
if (succeeded) {
|
||||
Match(tc.test_body, context.get());
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(SPV14FoldingTest, SPV14FoldingTest,
|
||||
::testing::Values(
|
||||
// Test case 0: select vectors with scalar condition.
|
||||
InstructionFoldingCase<bool>(std::string() +
|
||||
"; CHECK-NOT: OpSelect\n" +
|
||||
"; CHECK: %3 = OpCopyObject {{%\\w+}} %1\n" +
|
||||
"OpCapability Shader\n" +
|
||||
"OpCapability Linkage\n" +
|
||||
"%void = OpTypeVoid\n" +
|
||||
"%bool = OpTypeBool\n" +
|
||||
"%true = OpConstantTrue %bool\n" +
|
||||
"%int = OpTypeInt 32 0\n" +
|
||||
"%int4 = OpTypeVector %int 4\n" +
|
||||
"%int_0 = OpConstant %int 0\n" +
|
||||
"%int_1 = OpConstant %int 1\n" +
|
||||
"%1 = OpUndef %int4\n" +
|
||||
"%2 = OpUndef %int4\n" +
|
||||
"%void_fn = OpTypeFunction %void\n" +
|
||||
"%func = OpFunction %void None %void_fn\n" +
|
||||
"%entry = OpLabel\n" +
|
||||
"%3 = OpSelect %int4 %true %1 %2\n" +
|
||||
"OpReturn\n" +
|
||||
"OpFunctionEnd\n"
|
||||
,
|
||||
3, true),
|
||||
// Test case 1: select struct with scalar condition.
|
||||
InstructionFoldingCase<bool>(std::string() +
|
||||
"; CHECK-NOT: OpSelect\n" +
|
||||
"; CHECK: %3 = OpCopyObject {{%\\w+}} %2\n" +
|
||||
"OpCapability Shader\n" +
|
||||
"OpCapability Linkage\n" +
|
||||
"%void = OpTypeVoid\n" +
|
||||
"%bool = OpTypeBool\n" +
|
||||
"%true = OpConstantFalse %bool\n" +
|
||||
"%int = OpTypeInt 32 0\n" +
|
||||
"%struct = OpTypeStruct %int %int %int %int\n" +
|
||||
"%int_0 = OpConstant %int 0\n" +
|
||||
"%int_1 = OpConstant %int 1\n" +
|
||||
"%1 = OpUndef %struct\n" +
|
||||
"%2 = OpUndef %struct\n" +
|
||||
"%void_fn = OpTypeFunction %void\n" +
|
||||
"%func = OpFunction %void None %void_fn\n" +
|
||||
"%entry = OpLabel\n" +
|
||||
"%3 = OpSelect %struct %true %1 %2\n" +
|
||||
"OpReturn\n" +
|
||||
"OpFunctionEnd\n"
|
||||
,
|
||||
3, true),
|
||||
// Test case 1: select array with scalar condition.
|
||||
InstructionFoldingCase<bool>(std::string() +
|
||||
"; CHECK-NOT: OpSelect\n" +
|
||||
"; CHECK: %3 = OpCopyObject {{%\\w+}} %2\n" +
|
||||
"OpCapability Shader\n" +
|
||||
"OpCapability Linkage\n" +
|
||||
"%void = OpTypeVoid\n" +
|
||||
"%bool = OpTypeBool\n" +
|
||||
"%true = OpConstantFalse %bool\n" +
|
||||
"%int = OpTypeInt 32 0\n" +
|
||||
"%int_0 = OpConstant %int 0\n" +
|
||||
"%int_1 = OpConstant %int 1\n" +
|
||||
"%int_4 = OpConstant %int 4\n" +
|
||||
"%array = OpTypeStruct %int %int %int %int\n" +
|
||||
"%1 = OpUndef %array\n" +
|
||||
"%2 = OpUndef %array\n" +
|
||||
"%void_fn = OpTypeFunction %void\n" +
|
||||
"%func = OpFunction %void None %void_fn\n" +
|
||||
"%entry = OpLabel\n" +
|
||||
"%3 = OpSelect %array %true %1 %2\n" +
|
||||
"OpReturn\n" +
|
||||
"OpFunctionEnd\n"
|
||||
,
|
||||
3, true)
|
||||
));
|
||||
|
||||
} // namespace
|
||||
} // namespace opt
|
||||
} // namespace spvtools
|
||||
|
|
Загрузка…
Ссылка в новой задаче