[PATCH] D78237: [SVE] Fixup calls to VectorType::getNumElements in IR

Christopher Tetreault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 13:47:08 PDT 2020


ctetreau created this revision.
Herald added subscribers: llvm-commits, psnobl, rkruppe, hiraditya, tschuett.
Herald added a reviewer: efriedma.
Herald added a project: LLVM.
ctetreau abandoned this revision.

getNumElements() is going to be moved into FixedVectorType. In
preparation for this, fixup all calls to VectorType::getNumElements.
If getElementCount() can be used with no change in functionality, use
it. Otherwise cast to FixedVectorType and assume that this is correct


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78237

Files:
  llvm/lib/IR/ConstantFold.cpp
  llvm/lib/IR/Constants.cpp
  llvm/lib/IR/Verifier.cpp


Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -4905,7 +4905,7 @@
     Assert(Operand->getType()->isFPOrFPVectorTy(),
            "Intrinsic first argument must be floating point", &FPI);
     if (auto *OperandT = dyn_cast<VectorType>(Operand->getType())) {
-      NumSrcElem = cast<FixedVectorType>(OperandT)->getElementCount();
+      NumSrcElem = OperandT->getElementCount();
     }
 
     Operand = &FPI;
Index: llvm/lib/IR/Constants.cpp
===================================================================
--- llvm/lib/IR/Constants.cpp
+++ llvm/lib/IR/Constants.cpp
@@ -230,7 +230,8 @@
   auto *VTy = dyn_cast<VectorType>(getType());
   if (!VTy)
     return false;
-  for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
+  for (unsigned i = 0, e = cast<FixedVectorType>(VTy)->getNumElements(); i != e;
+       ++i) {
     auto *CFP = dyn_cast_or_null<ConstantFP>(this->getAggregateElement(i));
     if (!CFP || !CFP->getValueAPF().isFiniteNonZero())
       return false;
@@ -1899,8 +1900,8 @@
          "PtrToInt destination must be integer or integer vector");
   assert(isa<VectorType>(C->getType()) == isa<VectorType>(DstTy));
   if (auto *CVTy = dyn_cast<VectorType>(C->getType()))
-    assert(cast<FixedVectorType>(CVTy)->getNumElements() ==
-               cast<FixedVectorType>(DstTy)->getNumElements() &&
+    assert(CVTy->getElementCount() ==
+               cast<VectorType>(DstTy)->getElementCount() &&
            "Invalid cast between a different number of vector elements");
   return getFoldedCast(Instruction::PtrToInt, C, DstTy, OnlyIfReduced);
 }
@@ -1913,8 +1914,8 @@
          "IntToPtr destination must be a pointer or pointer vector");
   assert(isa<VectorType>(C->getType()) == isa<VectorType>(DstTy));
   if (auto *CVTy = dyn_cast<VectorType>(C->getType()))
-    assert(cast<FixedVectorType>(CVTy)->getNumElements() ==
-               cast<FixedVectorType>(DstTy)->getNumElements() &&
+    assert(CVTy->getElementCount() ==
+               cast<VectorType>(DstTy)->getElementCount() &&
            "Invalid cast between a different number of vector elements");
   return getFoldedCast(Instruction::IntToPtr, C, DstTy, OnlyIfReduced);
 }
Index: llvm/lib/IR/ConstantFold.cpp
===================================================================
--- llvm/lib/IR/ConstantFold.cpp
+++ llvm/lib/IR/ConstantFold.cpp
@@ -573,8 +573,8 @@
   // count may be mismatched; don't attempt to handle that here.
   if ((isa<ConstantVector>(V) || isa<ConstantDataVector>(V)) &&
       DestTy->isVectorTy() &&
-      cast<VectorType>(DestTy)->getElementCount() ==
-          cast<VectorType>(V->getType())->getElementCount()) {
+      cast<FixedVectorType>(DestTy)->getNumElements() ==
+          cast<FixedVectorType>(V->getType())->getNumElements()) {
     VectorType *DestVecTy = cast<VectorType>(DestTy);
     Type *DstEltTy = DestVecTy->getElementType();
     // Fast path for splatted constants.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78237.257828.patch
Type: text/x-patch
Size: 3035 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200415/1ed8fe8b/attachment.bin>


More information about the llvm-commits mailing list