summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/VectorUtils.cpp
diff options
context:
space:
mode:
authorElena Demikhovsky <elena.demikhovsky@intel.com>2015-08-30 07:28:18 +0000
committerElena Demikhovsky <elena.demikhovsky@intel.com>2015-08-30 07:28:18 +0000
commita59fcfa56b5299b82183ae2613892df1bf13d0f6 (patch)
treef97c5c1e1c78340b9ac5a2e9e859038de63caa9a /llvm/lib/Analysis/VectorUtils.cpp
parent799e880e95f6e179290abb83a538685b95859093 (diff)
downloadbcm5719-llvm-a59fcfa56b5299b82183ae2613892df1bf13d0f6.tar.gz
bcm5719-llvm-a59fcfa56b5299b82183ae2613892df1bf13d0f6.zip
New interface function is added to VectorUtils
Value *getSplatValue(Value *Val); It complements the CreateVectorSplat(), which creates 2 instructions - insertelement and shuffle with all-zero mask. The new function recognizes the pattern - insertelement+shuffle and returns the splat value (or nullptr). It also returns a splat value form ConstantDataVector, for completeness. Differential Revision: http://reviews.llvm.org/D11124 llvm-svn: 246371
Diffstat (limited to 'llvm/lib/Analysis/VectorUtils.cpp')
-rw-r--r--llvm/lib/Analysis/VectorUtils.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp
index 72140952ecb..92a880c3762 100644
--- a/llvm/lib/Analysis/VectorUtils.cpp
+++ b/llvm/lib/Analysis/VectorUtils.cpp
@@ -18,6 +18,8 @@
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Value.h"
+#include "llvm/IR/Constants.h"
+
using namespace llvm;
using namespace llvm::PatternMatch;
@@ -406,3 +408,27 @@ Value *llvm::findScalarElement(Value *V, unsigned EltNo) {
// Otherwise, we don't know.
return nullptr;
}
+
+/// \brief Get splat value if the input is a splat vector or return nullptr.
+/// The value may be extracted from a splat constants vector or from
+/// a sequence of instructions that broadcast a single value into a vector.
+llvm::Value *llvm::getSplatValue(Value *V) {
+ llvm::ConstantDataVector *CV = dyn_cast<llvm::ConstantDataVector>(V);
+ if (CV)
+ return CV->getSplatValue();
+ llvm::ShuffleVectorInst *ShuffleInst = dyn_cast<llvm::ShuffleVectorInst>(V);
+ if (!ShuffleInst)
+ return nullptr;
+ // All-zero (our undef) shuffle mask elements.
+ for (int i : ShuffleInst->getShuffleMask())
+ if (i != 0 && i != -1)
+ return nullptr;
+ // The first shuffle source is 'insertelement' with index 0.
+ llvm::InsertElementInst *InsertEltInst =
+ dyn_cast<llvm::InsertElementInst>(ShuffleInst->getOperand(0));
+ if (!InsertEltInst || !isa<ConstantInt>(InsertEltInst->getOperand(2)) ||
+ !cast<ConstantInt>(InsertEltInst->getOperand(2))->isNullValue())
+ return nullptr;
+
+ return InsertEltInst->getOperand(1);
+}
OpenPOWER on IntegriCloud