[SVE] Remove invalid usage of getNumElements in Instructions
authorChristopher Tetreault <ctetreau@quicinc.com>
Mon, 4 May 2020 15:29:08 +0000 (08:29 -0700)
committerChristopher Tetreault <ctetreau@quicinc.com>
Mon, 4 May 2020 15:36:37 +0000 (08:36 -0700)
Summary:
Remove invalid usage of VectorType::getNumElements in
ShuffleVectorInst::isValidOperands identified by test case
llvm::Analysis/ConstantFolding/vscale-shufflevector.ll. The tested
conditions hold for both fixed width and scalable vectors; use
getElementCount().

Reviewers: efriedma, sdesmalen, c-rhodes, spatel

Reviewed By: sdesmalen

Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79212

llvm/lib/IR/Instructions.cpp

index cccbd51..d9cda0f 100644 (file)
@@ -1916,11 +1916,11 @@ void ShuffleVectorInst::commute() {
 bool ShuffleVectorInst::isValidOperands(const Value *V1, const Value *V2,
                                         ArrayRef<int> Mask) {
   // V1 and V2 must be vectors of the same type.
-  if (!V1->getType()->isVectorTy() || V1->getType() != V2->getType())
+  if (!isa<VectorType>(V1->getType()) || V1->getType() != V2->getType())
     return false;
 
   // Make sure the mask elements make sense.
-  int V1Size = cast<VectorType>(V1->getType())->getNumElements();
+  int V1Size = cast<VectorType>(V1->getType())->getElementCount().Min;
   for (int Elem : Mask)
     if (Elem != UndefMaskElem && Elem >= V1Size * 2)
       return false;