[GlobalISel][Legalizer] Fix minScalarEltSameAsIf to handle p0 element types.

The mutation the action generates tries to change the input type into the
element type of larger vector type. This doesn't work if the larger element
type is a vector of pointers since it creates an illegal mutation between
scalar and pointer types.

Differential Revision: https://reviews.llvm.org/D133671
This commit is contained in:
Amara Emerson 2022-09-11 16:14:58 +01:00
parent 540d054b12
commit 25bcc8c797
2 changed files with 18 additions and 0 deletions

View File

@ -1040,6 +1040,8 @@ public:
},
[=](const LegalityQuery &Query) {
LLT T = Query.Types[LargeTypeIdx];
if (T.isVector() && T.getElementType().isPointer())
T = T.changeElementType(LLT::scalar(T.getScalarSizeInBits()));
return std::make_pair(TypeIdx, T);
});
}

View File

@ -241,6 +241,7 @@ TEST(LegalizerInfoTest, RuleSets) {
const LLT v2s64 = LLT::fixed_vector(2, 64);
const LLT p0 = LLT::pointer(0, 32);
const LLT v2p0 = LLT::fixed_vector(2, p0);
const LLT v3p0 = LLT::fixed_vector(3, p0);
const LLT v4p0 = LLT::fixed_vector(4, p0);
@ -427,6 +428,21 @@ TEST(LegalizerInfoTest, RuleSets) {
EXPECT_ACTION(FewerElements, 0, s16,
LegalityQuery(G_ADD, {LLT::scalable_vector(8, 16)}));
}
// Test minScalarEltSameAsIf
{
LegalizerInfo LI;
auto &LegacyInfo = LI.getLegacyLegalizerInfo();
LI.getActionDefinitionsBuilder(G_SELECT).minScalarEltSameAsIf(
all(isVector(0), isVector(1)), 1, 0);
LegacyInfo.computeTables();
LLT p1 = LLT::pointer(1, 32);
LLT v2p1 = LLT::fixed_vector(2, p1);
EXPECT_ACTION(WidenScalar, 1, v2s32, LegalityQuery(G_SELECT, {v2p0, v2s1}));
EXPECT_ACTION(WidenScalar, 1, v2s32, LegalityQuery(G_SELECT, {v2p1, v2s1}));
}
}
TEST(LegalizerInfoTest, MMOAlignment) {