aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Laskey <jlaskey@mac.com>2007-01-12 22:39:14 +0000
committerJim Laskey <jlaskey@mac.com>2007-01-12 22:39:14 +0000
commitfa30182eb84ee70d9f52120d653d63374b99cee6 (patch)
tree416640252b30aa20bb511260d626332bd8404c04
parent9f7f49caa46d00d455c8ae5152e4412dd5eed26d (diff)
Allow isAllOnesValue testing on packed constants
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33146 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Constants.h6
-rw-r--r--lib/VMCore/Constants.cpp16
2 files changed, 22 insertions, 0 deletions
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index dd85b43bc7..e8ded56dcf 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -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);
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index c2332c6e61..50b8982278 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -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...
//