[PATCH] D73564: LLT: Add changeNumElements

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 28 10:30:34 PST 2020


arsenm created this revision.
arsenm added reviewers: aditya_nandakumar, paquette, aemerson, dsanders.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

This is the element analog of changeElementType/changeElementSize


https://reviews.llvm.org/D73564

Files:
  llvm/include/llvm/Support/LowLevelTypeImpl.h
  llvm/unittests/CodeGen/LowLevelTypeTest.cpp


Index: llvm/unittests/CodeGen/LowLevelTypeTest.cpp
===================================================================
--- llvm/unittests/CodeGen/LowLevelTypeTest.cpp
+++ llvm/unittests/CodeGen/LowLevelTypeTest.cpp
@@ -138,6 +138,29 @@
   EXPECT_EQ(V2S32, V2P0.changeElementType(S32));
 }
 
+TEST(LowLevelTypeTest, ChangeNumElements) {
+  const LLT P0 = LLT::pointer(0, 32);
+  const LLT V2P0 = LLT::vector(2, P0);
+  const LLT V3P0 = LLT::vector(3, P0);
+
+  const LLT S64 = LLT::scalar(64);
+  const LLT V2S64 = LLT::vector(2, 64);
+  const LLT V3S64 = LLT::vector(3, 64);
+
+  // Vector to scalar
+  EXPECT_EQ(S64, V2S64.changeNumElements(1));
+
+  // Vector to vector
+  EXPECT_EQ(V3S64, V2S64.changeNumElements(3));
+
+  // Scalar to vector
+  EXPECT_EQ(V2S64, S64.changeNumElements(2));
+
+  EXPECT_EQ(P0, V2P0.changeNumElements(1));
+  EXPECT_EQ(V3P0, V2P0.changeNumElements(3));
+  EXPECT_EQ(V2P0, P0.changeNumElements(2));
+}
+
 #ifdef GTEST_HAS_DEATH_TEST
 #ifndef NDEBUG
 
Index: llvm/include/llvm/Support/LowLevelTypeImpl.h
===================================================================
--- llvm/include/llvm/Support/LowLevelTypeImpl.h
+++ llvm/include/llvm/Support/LowLevelTypeImpl.h
@@ -137,6 +137,12 @@
                       : LLT::scalar(NewEltSize);
   }
 
+  /// Return a vector or scalar with the same element type and the new number of
+  /// elements.
+  LLT changeNumElements(unsigned NewNumElts) const {
+    return LLT::scalarOrVector(NewNumElts, getScalarType());
+  }
+
   bool isByteSized() const { return (getSizeInBits() & 7) == 0; }
 
   unsigned getScalarSizeInBits() const {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73564.240934.patch
Type: text/x-patch
Size: 1613 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200128/ac5631c8/attachment.bin>


More information about the llvm-commits mailing list