[llvm] 4b776a9 - [SVE] Fix invalid usages of getNumElements in ShuffleVectorInstruction

Christopher Tetreault via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 17 13:45:52 PDT 2020


Author: Christopher Tetreault
Date: 2020-06-17T13:45:34-07:00
New Revision: 4b776a98f1a425e264545b5c2abeff9e83a6f947

URL: https://github.com/llvm/llvm-project/commit/4b776a98f1a425e264545b5c2abeff9e83a6f947
DIFF: https://github.com/llvm/llvm-project/commit/4b776a98f1a425e264545b5c2abeff9e83a6f947.diff

LOG: [SVE] Fix invalid usages of getNumElements in ShuffleVectorInstruction

Summary:
Fix invalid usages of getNumElements identified by test case
LLVM.Transforms/InstCombine::vscale_extractelement.ll.

changesLength: Since the length of the llvm::SmallVector shufflemask
is related to the minimum number of elements in a scalable vector, it is
fine to just get the Min field of the ElementCount

isIdentityWithExtract: Since it is not possible to express the mask
needed for this pattern for scalable vectors, we can just bail before
calling getNumElements()

Reviewers: efriedma, sdesmalen, fpetrogalli, gchatelet, yrouban, craig.topper

Reviewed By: sdesmalen

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

Tags: #llvm

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

Added: 
    

Modified: 
    llvm/include/llvm/IR/Instructions.h
    llvm/lib/IR/Instructions.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index b2fe803ed978..7710542efd95 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -1977,7 +1977,7 @@ class ShuffleVectorInst : public Instruction {
   ///           shufflevector <4 x n> A, <4 x n> B, <1,2,3,4,5>
   bool changesLength() const {
     unsigned NumSourceElts =
-        cast<VectorType>(Op<0>()->getType())->getNumElements();
+        cast<VectorType>(Op<0>()->getType())->getElementCount().Min;
     unsigned NumMaskElts = ShuffleMask.size();
     return NumSourceElts != NumMaskElts;
   }

diff  --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 0068ec5f7808..2087188e3edd 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -2205,8 +2205,14 @@ bool ShuffleVectorInst::isIdentityWithPadding() const {
 bool ShuffleVectorInst::isIdentityWithExtract() const {
   if (isa<UndefValue>(Op<2>()))
     return false;
-  int NumOpElts = cast<VectorType>(Op<0>()->getType())->getNumElements();
-  int NumMaskElts = getType()->getNumElements();
+
+  // FIXME: Not currently possible to express a shuffle mask for a scalable
+  // vector for this case
+  if (isa<ScalableVectorType>(getType()))
+    return false;
+
+  int NumOpElts = cast<FixedVectorType>(Op<0>()->getType())->getNumElements();
+  int NumMaskElts = cast<FixedVectorType>(getType())->getNumElements();
   if (NumMaskElts >= NumOpElts)
     return false;
 


        


More information about the llvm-commits mailing list