aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExprConstant.cpp
diff options
context:
space:
mode:
authorAnton Yartsev <anton.yartsev@gmail.com>2011-03-27 09:32:40 +0000
committerAnton Yartsev <anton.yartsev@gmail.com>2011-03-27 09:32:40 +0000
commitd06fea8580658470f92fb5d0d3d7ab5b475728dc (patch)
tree9ee9d5c46327ce3f931ba10af09aabf844a85bc6 /lib/CodeGen/CGExprConstant.cpp
parentbda0d6bda0f1a08a9fdf3ee4cf550b6b10d454ec (diff)
supported: AltiVec vector initialization with a single literal according to PIM section 2.5.1 - after initialization all elements have the value specified by the literal
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128375 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprConstant.cpp')
-rw-r--r--lib/CodeGen/CGExprConstant.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index ce25dc7ac5..3a2fb9bd9d 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -979,12 +979,29 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
llvm::SmallVector<llvm::Constant *, 4> Inits;
unsigned NumElts = Result.Val.getVectorLength();
- for (unsigned i = 0; i != NumElts; ++i) {
- APValue &Elt = Result.Val.getVectorElt(i);
- if (Elt.isInt())
- Inits.push_back(llvm::ConstantInt::get(VMContext, Elt.getInt()));
- else
- Inits.push_back(llvm::ConstantFP::get(VMContext, Elt.getFloat()));
+ if (Context.getLangOptions().AltiVec &&
+ isa<CastExpr>(E) &&
+ cast<CastExpr>(E)->getCastKind() == CK_VectorSplat) {
+ // AltiVec vector initialization with a single literal
+ APValue &Elt = Result.Val.getVectorElt(0);
+
+ llvm::Constant* InitValue = Elt.isInt()
+ ? cast<llvm::Constant>
+ (llvm::ConstantInt::get(VMContext, Elt.getInt()))
+ : cast<llvm::Constant>
+ (llvm::ConstantFP::get(VMContext, Elt.getFloat()));
+
+ for (unsigned i = 0; i != NumElts; ++i)
+ Inits.push_back(InitValue);
+
+ } else {
+ for (unsigned i = 0; i != NumElts; ++i) {
+ APValue &Elt = Result.Val.getVectorElt(i);
+ if (Elt.isInt())
+ Inits.push_back(llvm::ConstantInt::get(VMContext, Elt.getInt()));
+ else
+ Inits.push_back(llvm::ConstantFP::get(VMContext, Elt.getFloat()));
+ }
}
return llvm::ConstantVector::get(Inits);
}