Index: include/llvm/Analysis/VectorUtils.h
===================================================================
--- include/llvm/Analysis/VectorUtils.h
+++ include/llvm/Analysis/VectorUtils.h
@@ -74,6 +74,11 @@
 /// strides "a[i*stride]". Returns the symbolic stride, or null otherwise.
 Value *getStrideFromPointer(Value *Ptr, ScalarEvolution *SE, Loop *Lp);
 
+/// \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.
+Value *getSplatValue(Value *V);
+
 } // llvm namespace
 
 #endif
Index: lib/Analysis/VectorUtils.cpp
===================================================================
--- lib/Analysis/VectorUtils.cpp
+++ lib/Analysis/VectorUtils.cpp
@@ -18,6 +18,7 @@
 #include "llvm/IR/GetElementPtrTypeIterator.h"
 #include "llvm/IR/PatternMatch.h"
 #include "llvm/IR/Value.h"
+#include "llvm/IR/Constants.h"
 
 /// \brief Identify if the intrinsic is trivially vectorizable.
 /// This method returns true if the intrinsic's argument types are all
@@ -357,3 +358,15 @@
 
   return Stride;
 }
+
+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 || !ShuffleInst->getMask()->isNullValue() ||
+      !isa<llvm::InsertElementInst>(ShuffleInst->getOperand(0)))
+    return nullptr;
+
+  return cast<InsertElementInst>(ShuffleInst->getOperand(0))->getOperand(1);
+}