[cfe-commits] r73005 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp test/CodeGen/vector.c

Eli Friedman eli.friedman at gmail.com
Sat Jun 6 12:09:26 PDT 2009


Author: efriedma
Date: Sat Jun  6 14:09:26 2009
New Revision: 73005

URL: http://llvm.org/viewvc/llvm-project?rev=73005&view=rev
Log:
PR4339: make sure to properly extend/trunc the index of a vector element 
insert/extract; the relevant instructions are defined to take only an 
i32.


Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGen/vector.c

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Sat Jun  6 14:09:26 2009
@@ -843,14 +843,16 @@
 LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
   // The index must always be an integer, which is not an aggregate.  Emit it.
   llvm::Value *Idx = EmitScalarExpr(E->getIdx());
-  
+  QualType IdxTy  = E->getIdx()->getType();
+  bool IdxSigned = IdxTy->isSignedIntegerType();
+
   // If the base is a vector type, then we are forming a vector element lvalue
   // with this subscript.
   if (E->getBase()->getType()->isVectorType()) {
     // Emit the vector as an lvalue to get its address.
     LValue LHS = EmitLValue(E->getBase());
     assert(LHS.isSimple() && "Can only subscript lvalue vectors here!");
-    // FIXME: This should properly sign/zero/extend or truncate Idx to i32.
+    Idx = Builder.CreateIntCast(Idx, llvm::Type::Int32Ty, IdxSigned, "vidx");
     return LValue::MakeVectorElt(LHS.getAddress(), Idx,
       E->getBase()->getType().getCVRQualifiers());
   }
@@ -859,8 +861,6 @@
   llvm::Value *Base = EmitScalarExpr(E->getBase());
   
   // Extend or truncate the index type to 32 or 64-bits.
-  QualType IdxTy  = E->getIdx()->getType();
-  bool IdxSigned = IdxTy->isSignedIntegerType();
   unsigned IdxBitwidth = cast<llvm::IntegerType>(Idx->getType())->getBitWidth();
   if (IdxBitwidth != LLVMPointerWidth)
     Idx = Builder.CreateIntCast(Idx, llvm::IntegerType::get(LLVMPointerWidth),

Modified: cfe/trunk/test/CodeGen/vector.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vector.c?rev=73005&r1=73004&r2=73005&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/vector.c (original)
+++ cfe/trunk/test/CodeGen/vector.c Sat Jun  6 14:09:26 2009
@@ -11,3 +11,11 @@
 
 typedef int vty __attribute((vector_size(16)));
 int a() { vty b; return b[2LL]; }
+
+// PR4339
+typedef float vec4 __attribute__((vector_size(16)));
+
+void vac ( vec4* a, char b, float c )
+{
+	(*a)[b] = c;
+}





More information about the cfe-commits mailing list