From 25bcc8c7974e80d6d39ccd359c9b5beb09fa7694 Mon Sep 17 00:00:00 2001 From: Amara Emerson Date: Sun, 11 Sep 2022 16:14:58 +0100 Subject: [PATCH] [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 --- .../llvm/CodeGen/GlobalISel/LegalizerInfo.h | 2 ++ .../CodeGen/GlobalISel/LegalizerInfoTest.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h b/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h index c0cad8ff675d..090388d107ed 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h @@ -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); }); } diff --git a/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp b/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp index 0cce67411e22..5ff5a0790247 100644 --- a/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp +++ b/llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp @@ -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) {