aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Instructions.cpp
diff options
context:
space:
mode:
authorThomas Raoux <thomasraoux@google.com>2020-03-30 10:36:21 -0700
committerThomas Raoux <thomasraoux@google.com>2020-03-30 11:27:09 -0700
commit3ea0774b13a538759aa1a68f30130d18ddb0d3f2 (patch)
treef19bd3ecf25f6fd958a60bc909e185b98b4eea2f /llvm/lib/IR/Instructions.cpp
parent8242509a49e019c0279305d152c7ab2b9cdc2d0d (diff)
downloadllvm-3ea0774b13a538759aa1a68f30130d18ddb0d3f2.zip
llvm-3ea0774b13a538759aa1a68f30130d18ddb0d3f2.tar.gz
llvm-3ea0774b13a538759aa1a68f30130d18ddb0d3f2.tar.bz2
[ConstantFold][NFC] Compile time optimization for large vectors
Optimize the common case of splat vector constant. For large vector going through all elements is expensive. For splatr/broadcast cases we can skip going through all elements. Differential Revision: https://reviews.llvm.org/D76664
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r--llvm/lib/IR/Instructions.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 0884a24..f6748c8 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -1958,7 +1958,11 @@ void ShuffleVectorInst::getShuffleMask(const Constant *Mask,
assert(!Mask->getType()->getVectorElementCount().Scalable &&
"Length of scalable vectors unknown at compile time");
unsigned NumElts = Mask->getType()->getVectorNumElements();
-
+ if (isa<ConstantAggregateZero>(Mask)) {
+ Result.resize(NumElts, 0);
+ return;
+ }
+ Result.reserve(NumElts);
if (auto *CDS = dyn_cast<ConstantDataSequential>(Mask)) {
for (unsigned i = 0; i != NumElts; ++i)
Result.push_back(CDS->getElementAsInteger(i));