From 0eb47fc01849a94bac7fda236134f9301eff688b Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Thu, 19 May 2011 00:37:32 +0000 Subject: Make __builtin_shufflevector and -ftrapv work correctly together. PR9945. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131611 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExprScalar.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'lib/CodeGen/CGExprScalar.cpp') diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index abc375871f..fcada3a92a 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -758,19 +758,13 @@ Value *ScalarExprEmitter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { 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(V1->getType()); llvm::SmallVector indices; for (unsigned i = 2; i < E->getNumSubExprs(); i++) { - llvm::Constant *C = cast(CGF.EmitScalarExpr(E->getExpr(i))); - const llvm::VectorType *VTy = cast(V1->getType()); - if (VTy->getNumElements() == 3) { - if (llvm::ConstantInt *CI = dyn_cast(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); -- cgit v1.2.3