[cfe-commits] r40777 - /cfe/trunk/CodeGen/CGExpr.cpp

Chris Lattner sabre at nondot.org
Fri Aug 3 08:52:33 PDT 2007


Author: lattner
Date: Fri Aug  3 10:52:31 2007
New Revision: 40777

URL: http://llvm.org/viewvc/llvm-project?rev=40777&view=rev
Log:
Add support for scalar-returning element accesses like V.x

Modified:
    cfe/trunk/CodeGen/CGExpr.cpp

Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=40777&r1=40776&r2=40777&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Fri Aug  3 10:52:31 2007
@@ -287,13 +287,23 @@
   // 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);





More information about the cfe-commits mailing list