diff options
author | Renato Golin <renato.golin@linaro.org> | 2015-08-30 10:49:04 +0000 |
---|---|---|
committer | Renato Golin <renato.golin@linaro.org> | 2015-08-30 10:49:04 +0000 |
commit | 3b1d3b0d84af2bf5a50dd31f20fb81ca74c41880 (patch) | |
tree | 661170df30d1869d3fee2a847811534e4ca1a514 /llvm/lib/Analysis/VectorUtils.cpp | |
parent | c7be31736ca0cbd7fca41989b805228cf87e4355 (diff) | |
download | bcm5719-llvm-3b1d3b0d84af2bf5a50dd31f20fb81ca74c41880.tar.gz bcm5719-llvm-3b1d3b0d84af2bf5a50dd31f20fb81ca74c41880.zip |
Revert "Revert "New interface function is added to VectorUtils Value *getSplatValue(Value *Val);""
This reverts commit r246379. It seems that the commit was not the culprit,
and the bot will be investigated for instability.
llvm-svn: 246380
Diffstat (limited to 'llvm/lib/Analysis/VectorUtils.cpp')
-rw-r--r-- | llvm/lib/Analysis/VectorUtils.cpp | 26 |
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); +} |