[cfe-commits] r131611 - in /cfe/trunk: lib/CodeGen/CGExprScalar.cpp test/CodeGen/builtinshufflevector.c

Eli Friedman eli.friedman at gmail.com
Wed May 18 17:37:32 PDT 2011


Author: efriedma
Date: Wed May 18 19:37:32 2011
New Revision: 131611

URL: http://llvm.org/viewvc/llvm-project?rev=131611&view=rev
Log:
Make __builtin_shufflevector and -ftrapv work correctly together.  PR9945.


Modified:
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp
    cfe/trunk/test/CodeGen/builtinshufflevector.c

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=131611&r1=131610&r2=131611&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Wed May 18 19:37:32 2011
@@ -758,19 +758,13 @@
   Value* V2 = CGF.EmitScalarExpr(E->getExpr(1));
   
   // Handle vec3 special since the index will be off by one for the RHS.
+  const llvm::VectorType *VTy = cast<llvm::VectorType>(V1->getType());
   llvm::SmallVector<llvm::Constant*, 32> indices;
   for (unsigned i = 2; i < E->getNumSubExprs(); i++) {
-    llvm::Constant *C = cast<llvm::Constant>(CGF.EmitScalarExpr(E->getExpr(i)));
-    const llvm::VectorType *VTy = cast<llvm::VectorType>(V1->getType());
-    if (VTy->getNumElements() == 3) {
-      if (llvm::ConstantInt *CI = dyn_cast<llvm::ConstantInt>(C)) {
-        uint64_t cVal = CI->getZExtValue();
-        if (cVal > 3) {
-          C = llvm::ConstantInt::get(C->getType(), cVal-1);
-        }
-      }
-    }
-    indices.push_back(C);
+    unsigned Idx = E->getShuffleMaskIdx(CGF.getContext(), i-2);
+    if (VTy->getNumElements() == 3 && Idx > 3)
+      Idx -= 1;
+    indices.push_back(Builder.getInt32(Idx));
   }
 
   Value *SV = llvm::ConstantVector::get(indices);

Modified: cfe/trunk/test/CodeGen/builtinshufflevector.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtinshufflevector.c?rev=131611&r1=131610&r2=131611&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtinshufflevector.c (original)
+++ cfe/trunk/test/CodeGen/builtinshufflevector.c Wed May 18 19:37:32 2011
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -emit-llvm < %s | grep 'shufflevector' | count 1
+// RUN: %clang_cc1 -emit-llvm -ftrapv < %s | grep 'shufflevector' | count 1
 typedef int v4si __attribute__ ((vector_size (16)));
 
-v4si a(v4si x, v4si y) {return __builtin_shufflevector(x, y, 3, 2, 5, 7);}
+v4si a(v4si x, v4si y) {return __builtin_shufflevector(x, y, 3, 2, 5, (2*3)+1);}
 





More information about the cfe-commits mailing list