summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-07-10 00:44:03 +0000
committerChris Lattner <sabre@nondot.org>2008-07-10 00:44:03 +0000
commitd977c076802a64e7666145b844c7765f3b866acc (patch)
treecdbb5992be7372d058ab4de7d96b46d070681f7a /llvm/lib
parent67136cff7b4ca58ade2ff7be7bbc0f4b1a66e209 (diff)
downloadbcm5719-llvm-d977c076802a64e7666145b844c7765f3b866acc.tar.gz
bcm5719-llvm-d977c076802a64e7666145b844c7765f3b866acc.zip
SImplify ConstantVector::get a bit and make it turn a vector
of all undefs into a single undef value. llvm-svn: 53384
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/VMCore/Constants.cpp26
1 files changed, 18 insertions, 8 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index 7908638fd67..dc9cab032c5 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/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) {
OpenPOWER on IntegriCloud