diff options
author | Chris Lattner <sabre@nondot.org> | 2008-07-10 00:44:03 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-07-10 00:44:03 +0000 |
commit | 7cc9a4b990b8dc6043c47b64e91352b444d3938b (patch) | |
tree | 9d6b9233c48db86731b86daed4b5a94faa645bd3 /lib/VMCore/Constants.cpp | |
parent | fea85c46c0baae0d40584e3901607ed3db55d6ef (diff) | |
download | external_llvm-7cc9a4b990b8dc6043c47b64e91352b444d3938b.zip external_llvm-7cc9a4b990b8dc6043c47b64e91352b444d3938b.tar.gz external_llvm-7cc9a4b990b8dc6043c47b64e91352b444d3938b.tar.bz2 |
SImplify ConstantVector::get a bit and make it turn a vector
of all undefs into a single undef value.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53384 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Constants.cpp')
-rw-r--r-- | lib/VMCore/Constants.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 7908638..dc9cab0 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1498,16 +1498,26 @@ static ManagedStatic<ValueMap<std::vector<Constant*>, VectorType, Constant *ConstantVector::get(const VectorType *Ty, const std::vector<Constant*> &V) { - // If this is an all-zero vector, return a ConstantAggregateZero object - if (!V.empty()) { - Constant *C = V[0]; - if (!C->isNullValue()) - return VectorConstants->getOrCreate(Ty, V); + assert(!V.empty() && "Vectors can't be empty"); + // If this is an all-undef or alll-zero vector, return a + // ConstantAggregateZero or UndefValue. + Constant *C = V[0]; + bool isZero = C->isNullValue(); + bool isUndef = isa<UndefValue>(C); + + if (isZero || isUndef) { for (unsigned i = 1, e = V.size(); i != e; ++i) - if (V[i] != C) - return VectorConstants->getOrCreate(Ty, V); + if (V[i] != C) { + isZero = isUndef = false; + break; + } } - return ConstantAggregateZero::get(Ty); + + if (isZero) + return ConstantAggregateZero::get(Ty); + if (isUndef) + return UndefValue::get(Ty); + return VectorConstants->getOrCreate(Ty, V); } Constant *ConstantVector::get(const std::vector<Constant*> &V) { |