Allow isAllOnesValue testing on packed constants
authorJim Laskey <jlaskey@mac.com>
Fri, 12 Jan 2007 22:39:14 +0000 (22:39 +0000)
committerJim Laskey <jlaskey@mac.com>
Fri, 12 Jan 2007 22:39:14 +0000 (22:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33146 91177308-0d34-0410-b5e6-96231b3b80d8

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

index dd85b43bc7ac558acf75984ce0b62ac51342ecb4..e8ded56dcff490348c7c1eca18476ab1299a9b29 100644 (file)
@@ -358,6 +358,12 @@ public:
   /// created as ConstantAggregateZero objects.
   virtual bool isNullValue() const { return false; }
 
+  /// This function will return true iff every element in this packed constant
+  /// is set to all ones.
+  /// @returns true iff this constant's emements are all set to all ones.
+  /// @brief Determine if the value is all ones.
+  virtual bool isAllOnesValue() const;
+
   virtual void destroyConstant();
   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
 
index c2332c6e6146b4d46b1d59335dc58ce90b603c72..50b89822782fdd0d71ada2a6bdce6ad585fb1340 100644 (file)
@@ -1166,6 +1166,22 @@ void ConstantPacked::destroyConstant() {
   destroyConstantImpl();
 }
 
+/// This function will return true iff every element in this packed constant
+/// is set to all ones.
+/// @returns true iff this constant's emements are all set to all ones.
+/// @brief Determine if the value is all ones.
+bool ConstantPacked::isAllOnesValue() const {
+  // Check out first element.
+  const Constant *Elt = getOperand(0);
+  const ConstantInt *CI = dyn_cast<ConstantInt>(Elt);
+  if (!CI || !CI->isAllOnesValue()) return false;
+  // 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 false;
+  }
+  return true;
+}
+
 //---- ConstantPointerNull::get() implementation...
 //