diff options
author | Eli Friedman <efriedma@quicinc.com> | 2020-03-31 13:08:59 -0700 |
---|---|---|
committer | Eli Friedman <efriedma@quicinc.com> | 2020-03-31 13:08:59 -0700 |
commit | 1ee6ec2bf370fbd1d93f34c8b56741a9d3f22ed2 (patch) | |
tree | b9623492ad0fb566cfa38ee8d99d538b95ba8c3e /llvm/lib/IR/ConstantFold.cpp | |
parent | c538c57d6dae548e644449352d9350d58be9a4af (diff) | |
download | llvm-1ee6ec2bf370fbd1d93f34c8b56741a9d3f22ed2.zip llvm-1ee6ec2bf370fbd1d93f34c8b56741a9d3f22ed2.tar.gz llvm-1ee6ec2bf370fbd1d93f34c8b56741a9d3f22ed2.tar.bz2 |
Remove "mask" operand from shufflevector.
Instead, represent the mask as out-of-line data in the instruction. This
should be more efficient in the places that currently use
getShuffleVector(), and paves the way for further changes to add new
shuffles for scalable vectors.
This doesn't change the syntax in textual IR. And I don't currently plan
to change the bitcode encoding in this patch, although we'll probably
need to do something once we extend shufflevector for scalable types.
I expect that once this is finished, we can then replace the raw "mask"
with something more appropriate for scalable vectors. Not sure exactly
what this looks like at the moment, but there are a few different ways
we could handle it. Maybe we could try to describe specific shuffles.
Or maybe we could define it in terms of a function to convert a fixed-length
array into an appropriate scalable vector, using a "step", or something
like that.
Differential Revision: https://reviews.llvm.org/D72467
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 07292e5..c4465d9 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -876,22 +876,22 @@ Constant *llvm::ConstantFoldInsertElementInstruction(Constant *Val, return ConstantVector::get(Result); } -Constant *llvm::ConstantFoldShuffleVectorInstruction(Constant *V1, - Constant *V2, - Constant *Mask) { - ElementCount MaskEltCount = Mask->getType()->getVectorElementCount(); +Constant *llvm::ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, + ArrayRef<int> Mask) { + unsigned MaskNumElts = Mask.size(); + ElementCount MaskEltCount = {MaskNumElts, + V1->getType()->getVectorIsScalable()}; Type *EltTy = V1->getType()->getVectorElementType(); // Undefined shuffle mask -> undefined value. - if (isa<UndefValue>(Mask)) - return UndefValue::get(VectorType::get(EltTy, MaskEltCount)); - - // Don't break the bitcode reader hack. - if (isa<ConstantExpr>(Mask)) return nullptr; + if (all_of(Mask, [](int Elt) { return Elt == UndefMaskElem; })) { + return UndefValue::get(VectorType::get(EltTy, MaskNumElts)); + } // If the mask is all zeros this is a splat, no need to go through all // elements. - if (isa<ConstantAggregateZero>(Mask) && !MaskEltCount.Scalable) { + if (all_of(Mask, [](int Elt) { return Elt == 0; }) && + !MaskEltCount.Scalable) { Type *Ty = IntegerType::get(V1->getContext(), 32); Constant *Elt = ConstantExpr::getExtractElement(V1, ConstantInt::get(Ty, 0)); @@ -903,13 +903,12 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(Constant *V1, if (ValTy->isScalable()) return nullptr; - unsigned MaskNumElts = MaskEltCount.Min; unsigned SrcNumElts = V1->getType()->getVectorNumElements(); // Loop over the shuffle mask, evaluating each element. SmallVector<Constant*, 32> Result; for (unsigned i = 0; i != MaskNumElts; ++i) { - int Elt = ShuffleVectorInst::getMaskValue(Mask, i); + int Elt = Mask[i]; if (Elt == -1) { Result.push_back(UndefValue::get(EltTy)); continue; |