[PATCH] D79197: [SVE] Fix invalid usage of getNumElements() in InstCombineMulDivRem

Christopher Tetreault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 30 13:26:50 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 added a child revision: D79053: [SVE] Fix invalid uses of VectorType::getNumElements().
ctetreau added reviewers: fpetrogalli, kmclaughlin, spatel.

getLogBase2 tries to walk its input vector type to do its work. This
cannot be done for scalable vectors, return null if the input type is
scalable

Identified by test LLVM.Transforms/InstCombine::nsw.ll


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79197

Files:
  llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -96,19 +96,20 @@
 
 /// A helper routine of InstCombiner::visitMul().
 ///
-/// If C is a scalar/vector of known powers of 2, then this function returns
-/// a new scalar/vector obtained from logBase2 of C.
+/// If C is a scalar/fixed width vector of known powers of 2, then this
+/// function returns a new scalar/fixed width vector obtained from logBase2
+/// of C.
 /// Return a null pointer otherwise.
 static Constant *getLogBase2(Type *Ty, Constant *C) {
   const APInt *IVal;
   if (match(C, m_APInt(IVal)) && IVal->isPowerOf2())
     return ConstantInt::get(Ty, IVal->logBase2());
 
-  if (!Ty->isVectorTy())
+  if (!isa<FixedVectorType>(Ty))
     return nullptr;
 
   SmallVector<Constant *, 4> Elts;
-  for (unsigned I = 0, E = cast<VectorType>(Ty)->getNumElements(); I != E;
+  for (unsigned I = 0, E = cast<FixedVectorType>(Ty)->getNumElements(); I != E;
        ++I) {
     Constant *Elt = C->getAggregateElement(I);
     if (!Elt)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79197.261327.patch
Type: text/x-patch
Size: 1202 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200430/dabb0c0e/attachment.bin>


More information about the llvm-commits mailing list