[spirv-reader] Test block order dup cases

- branch-conditional where both targets are the same
- switch where the default target is the same as a case target

Bug: tint:3
Change-Id: If5a3e1fead43ae3d528341f3e54dcae959d9eb8c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20061
Reviewed-by: dan sinclair <dsinclair@google.com>
This commit is contained in:
David Neto 2020-04-21 17:44:44 +00:00
parent f6def6d572
commit b5d518b68b
1 changed files with 53 additions and 0 deletions

View File

@ -145,6 +145,29 @@ TEST_F(SpvParserTest, ComputeBlockOrder_ReorderSequence) {
EXPECT_THAT(fe.rspo(), ElementsAre(10, 20, 30));
}
TEST_F(SpvParserTest, ComputeBlockOrder_DupConditionalBranch) {
auto* p = parser(test::Assemble(CommonTypes() + R"(
%100 = OpFunction %void None %voidfn
%10 = OpLabel
OpSelectionMerge %99 None
OpBranchConditional %cond %20 %20
%99 = OpLabel
OpReturn
%20 = OpLabel
OpBranch %99
OpFunctionEnd
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p, *spirv_function(100));
fe.ComputeBlockOrderAndPositions();
EXPECT_THAT(fe.rspo(), ElementsAre(10, 20, 99));
}
TEST_F(SpvParserTest, ComputeBlockOrder_RespectConditionalBranchOrder) {
auto* p = parser(test::Assemble(CommonTypes() + R"(
%100 = OpFunction %void None %voidfn
@ -273,6 +296,36 @@ TEST_F(SpvParserTest,
EXPECT_THAT(fe.rspo(), ElementsAre(10, 30, 20, 80, 99));
}
TEST_F(SpvParserTest,
ComputeBlockOrder_Switch_DefaultSameAsACase) {
auto* p = parser(test::Assemble(CommonTypes() + R"(
%100 = OpFunction %void None %voidfn
%10 = OpLabel
OpSelectionMerge %99 None
OpSwitch %selector %30 20 %20 30 %30 40 %40
%99 = OpLabel
OpReturn
%30 = OpLabel
OpBranch %99
%20 = OpLabel
OpBranch %99
%40 = OpLabel
OpBranch %99
OpFunctionEnd
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
FunctionEmitter fe(p, *spirv_function(100));
fe.ComputeBlockOrderAndPositions();
EXPECT_THAT(fe.rspo(), ElementsAre(10, 40, 20, 30, 99));
}
TEST_F(SpvParserTest, ComputeBlockOrder_RespectSwitchCaseFallthrough) {
auto assembly = CommonTypes() + R"(
%100 = OpFunction %void None %voidfn