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
This commit is contained in:
Steven Perron 2022-03-07 19:35:57 +00:00 committed by GitHub
parent 4fa1a6f9b4
commit 48a36c72e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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>>;