[llvm] 8074670 - [X86] getX86MaskVec - replace mask limit from NumElts < 8 with NumElts <= 4

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 6 04:00:01 PDT 2020


Author: Simon Pilgrim
Date: 2020-08-06T11:46:19+01:00
New Revision: 807467009d6faa5beb732d49ec4575fa1409abd7

URL: https://github.com/llvm/llvm-project/commit/807467009d6faa5beb732d49ec4575fa1409abd7
DIFF: https://github.com/llvm/llvm-project/commit/807467009d6faa5beb732d49ec4575fa1409abd7.diff

LOG: [X86] getX86MaskVec - replace mask limit from NumElts < 8 with NumElts <= 4

As noted on PR46885, the number of mask elements should always be a power of 2, so to fix the static analyzer warning we are better off replacing the condition to <= 4, and I've added a pow2 assertion as well.

Added: 
    

Modified: 
    llvm/lib/IR/AutoUpgrade.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 1e8fdb506619..df6595cf4d20 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -966,19 +966,19 @@ static Value *UpgradeX86PSRLDQIntrinsics(IRBuilder<> &Builder, Value *Op,
 
 static Value *getX86MaskVec(IRBuilder<> &Builder, Value *Mask,
                             unsigned NumElts) {
+  assert(isPowerOf2_32(NumElts) && "Expected power-of-2 mask elements");
   llvm::VectorType *MaskTy = FixedVectorType::get(
       Builder.getInt1Ty(), cast<IntegerType>(Mask->getType())->getBitWidth());
   Mask = Builder.CreateBitCast(Mask, MaskTy);
 
-  // If we have less than 8 elements, then the starting mask was an i8 and
-  // we need to extract down to the right number of elements.
-  if (NumElts < 8) {
+  // If we have less than 8 elements (1, 2 or 4), then the starting mask was an
+  // i8 and we need to extract down to the right number of elements.
+  if (NumElts <= 4) {
     int Indices[4];
     for (unsigned i = 0; i != NumElts; ++i)
       Indices[i] = i;
-    Mask = Builder.CreateShuffleVector(Mask, Mask,
-                                       makeArrayRef(Indices, NumElts),
-                                       "extract");
+    Mask = Builder.CreateShuffleVector(
+        Mask, Mask, makeArrayRef(Indices, NumElts), "extract");
   }
 
   return Mask;


        


More information about the llvm-commits mailing list