diff options
author | Chris Lattner <sabre@nondot.org> | 2007-08-03 15:52:31 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-08-03 15:52:31 +0000 |
commit | a1036f9155e85c966fed55762290c17517e759f5 (patch) | |
tree | 224ac7863838414c79f05d4028b5dec4bbdd123a | |
parent | 774761c503b0185f5c91cf81736fab8567a4b1b8 (diff) | |
download | bcm5719-llvm-a1036f9155e85c966fed55762290c17517e759f5.tar.gz bcm5719-llvm-a1036f9155e85c966fed55762290c17517e759f5.zip |
Add support for scalar-returning element accesses like V.x
llvm-svn: 40777
-rw-r--r-- | clang/CodeGen/CGExpr.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/clang/CodeGen/CGExpr.cpp b/clang/CodeGen/CGExpr.cpp index 7d8dc8c33b9..178107e2eea 100644 --- a/clang/CodeGen/CGExpr.cpp +++ b/clang/CodeGen/CGExpr.cpp @@ -287,13 +287,23 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) { // shuffle the input or extract/insert them as appropriate. if (LV.isOCUVectorComp()) { llvm::Value *Vec = Builder.CreateLoad(LV.getOCUVectorAddr(), "tmp"); + + unsigned EncFields = LV.getOCUVectorComp(); + + // If the result of the expression is a non-vector type, we must be + // extracting a single element. Just codegen as an extractelement. + if (!isa<VectorType>(ExprType)) { + unsigned InIdx = OCUVectorComponent::getAccessedFieldNo(0, EncFields); + llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx); + return RValue::get(Builder.CreateExtractElement(Vec, Elt, "tmp")); + } + + unsigned NumElts = cast<VectorType>(ExprType)->getNumElements(); // Start out with an undef of the result type. llvm::Value *Result = llvm::UndefValue::get(ConvertType(ExprType)); - unsigned EncFields = LV.getOCUVectorComp(); - // Extract/Insert each element of the result. for (unsigned i = 0; i != NumElts; ++i) { unsigned InIdx = OCUVectorComponent::getAccessedFieldNo(i, EncFields); |