Skip to content

Commit

Permalink
[GlobalISel][Legalizer] Fix minScalarEltSameAsIf to handle p0 element…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
aemerson committed Sep 12, 2022
1 parent 540d054 commit 25bcc8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,8 @@ class LegalizeRuleSet {
},
[=](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);
});
}
Expand Down
16 changes: 16 additions & 0 deletions llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 25bcc8c

Please sign in to comment.