aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Perron <stevenperron@google.com>2022-03-07 19:35:57 +0000
committerGitHub <noreply@github.com>2022-03-07 19:35:57 +0000
commit48a36c72e4d358ed9f0a5e53fe775a7ebb2f8f2b (patch)
treec66f33ca208e566c1c96ef4cd9e882c725597175
parent4fa1a6f9b497193e54a814112f17ab3c2cf58053 (diff)
downloadspirv-tools-48a36c72e4d358ed9f0a5e53fe775a7ebb2f8f2b.tar.gz
Better handling of 0xFFFFFFFF when folding vector shuffle (#4743)
When folding a vector shuffle feeding a vector shuffle, we do not propagate an 0xFFFFFFFF, which has a special meaning, correctly. We adjust the value making it lose it meaning as an undefined value. Fixes #4581
-rw-r--r--source/opt/folding_rules.cpp4
-rw-r--r--test/opt/fold_test.cpp21
2 files changed, 23 insertions, 2 deletions
diff --git a/source/opt/folding_rules.cpp b/source/opt/folding_rules.cpp
index 4904f186..c879a0c5 100644
--- a/source/opt/folding_rules.cpp
+++ b/source/opt/folding_rules.cpp
@@ -2368,7 +2368,7 @@ FoldingRule VectorShuffleFeedingShuffle() {
// fold.
return false;
}
- } else {
+ } else if (component_index != undef_literal) {
if (new_feeder_id == 0) {
// First time through, save the id of the operand the element comes
// from.
@@ -2382,7 +2382,7 @@ FoldingRule VectorShuffleFeedingShuffle() {
component_index -= feeder_op0_length;
}
- if (!feeder_is_op0) {
+ if (!feeder_is_op0 && component_index != undef_literal) {
component_index += op0_length;
}
}
diff --git a/test/opt/fold_test.cpp b/test/opt/fold_test.cpp
index df8f3b12..7565ca7f 100644
--- a/test/opt/fold_test.cpp
+++ b/test/opt/fold_test.cpp
@@ -7087,6 +7087,27 @@ INSTANTIATE_TEST_SUITE_P(DotProductMatchingTest, MatchingInstructionFoldingTest,
3, true)
));
+INSTANTIATE_TEST_SUITE_P(VectorShuffleMatchingTest, MatchingInstructionFoldingTest,
+::testing::Values(
+ // Test case 0: Using OpDot to extract last element.
+ InstructionFoldingCase<bool>(
+ Header() +
+ "; CHECK: [[int:%\\w+]] = OpTypeInt 32 1\n" +
+ "; CHECK: [[v2int:%\\w+]] = OpTypeVector [[int]] 2{{[[:space:]]}}\n" +
+ "; CHECK: [[null:%\\w+]] = OpConstantNull [[v2int]]\n" +
+ "; CHECK: OpVectorShuffle\n" +
+ "; CHECK: %3 = OpVectorShuffle [[v2int]] [[null]] {{%\\w+}} 4294967295 2\n" +
+ "%main = OpFunction %void None %void_func\n" +
+ "%main_lab = OpLabel\n" +
+ "%n = OpVariable %_ptr_int Function\n" +
+ "%load = OpLoad %int %n\n" +
+ "%2 = OpVectorShuffle %v2int %v2int_null %v2int_2_3 3 0xFFFFFFFF \n" +
+ "%3 = OpVectorShuffle %v2int %2 %v2int_2_3 1 2 \n" +
+ "OpReturn\n" +
+ "OpFunctionEnd",
+ 3, true)
+ ));
+
using MatchingInstructionWithNoResultFoldingTest =
::testing::TestWithParam<InstructionFoldingCase<bool>>;