Define a helper function ConstantVector::getSplatValue for testing for
authorDan Gohman <gohman@apple.com>
Wed, 17 Oct 2007 17:51:30 +0000 (17:51 +0000)
committerDan Gohman <gohman@apple.com>
Wed, 17 Oct 2007 17:51:30 +0000 (17:51 +0000)
and working with broadcasted constants.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43076 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Constants.h
lib/VMCore/Constants.cpp

index 4c497b6f58b962ed9075f013c74e350734b59ddd..c8552395313cb160dc1a42d3d6e846b5ec12cc68 100644 (file)
@@ -438,6 +438,10 @@ public:
   /// @brief Determine if the value is all ones.
   bool isAllOnesValue() const;
 
+  /// getSplatValue - If this is a splat constant, meaning that all of the
+  /// elements have the same value, return that value. Otherwise return NULL.
+  Constant *getSplatValue();
+
   virtual void destroyConstant();
   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
 
index 350a306d797a968fa06c695b6e4f70de49400fb2..9c1377dbd7b2f56e11b67fa7dc0a1b2c42ac3ae9 100644 (file)
@@ -1286,6 +1286,17 @@ bool ConstantVector::isAllOnesValue() const {
   return true;
 }
 
+/// getSplatValue - If this is a splat constant, where all of the
+/// elements have the same value, return that value. Otherwise return null.
+Constant *ConstantVector::getSplatValue() {
+  // Check out first element.
+  Constant *Elt = getOperand(0);
+  // Then make sure all remaining elements point to the same value.
+  for (unsigned I = 1, E = getNumOperands(); I < E; ++I)
+    if (getOperand(I) != Elt) return 0;
+  return Elt;
+}
+
 //---- ConstantPointerNull::get() implementation...
 //