From 807467009d6faa5beb732d49ec4575fa1409abd7 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 6 Aug 2020 11:46:19 +0100 Subject: [PATCH] [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. --- llvm/lib/IR/AutoUpgrade.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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(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;