Allow isAllOnesValue testing on packed constants

llvm-svn: 33146
This commit is contained in:
Jim Laskey 2007-01-12 22:39:14 +00:00
parent 01503121c1
commit f047882b15
2 changed files with 22 additions and 0 deletions

View 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);

View 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...
//