[GlobalISel][Legalizer] Fix minScalarEltSameAsIf to handle p0 element types.
authorAmara Emerson <amara@apple.com>
Sun, 11 Sep 2022 15:14:58 +0000 (16:14 +0100)
committerAmara Emerson <amara@apple.com>
Mon, 12 Sep 2022 23:01:37 +0000 (00:01 +0100)
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/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h
llvm/unittests/CodeGen/GlobalISel/LegalizerInfoTest.cpp

index c0cad8f..090388d 100644 (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);
         });
   }
index 0cce674..5ff5a07 100644 (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) {