From 14c598268ff7534d3753ae84eba9b8a81bf0bf8f Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 14 Feb 2012 12:06:21 +0000 Subject: [PATCH] Use a simpler (and more efficient) pattern to pad vectors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150475 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExpr.cpp | 6 ++---- lib/CodeGen/CGExprConstant.cpp | 7 +++---- lib/CodeGen/CGExprScalar.cpp | 17 ++++++----------- lib/Sema/SemaDeclCXX.cpp | 3 +-- lib/Sema/SemaExpr.cpp | 6 ++---- 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index ae4084ba6c..95bed1b0e6 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1181,11 +1181,9 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src, // FIXME: since we're shuffling with undef, can we just use the indices // into that? This could be simpler. SmallVector ExtMask; - unsigned i; - for (i = 0; i != NumSrcElts; ++i) + for (unsigned i = 0; i != NumSrcElts; ++i) ExtMask.push_back(Builder.getInt32(i)); - for (; i != NumDstElts; ++i) - ExtMask.push_back(llvm::UndefValue::get(Int32Ty)); + ExtMask.resize(NumDstElts, llvm::UndefValue::get(Int32Ty)); llvm::Value *ExtMaskV = llvm::ConstantVector::get(ExtMask); llvm::Value *ExtSrcVal = Builder.CreateShuffleVector(SrcVal, diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp index 0b3ac9cbe5..44531c0992 100644 --- a/lib/CodeGen/CGExprConstant.cpp +++ b/lib/CodeGen/CGExprConstant.cpp @@ -701,9 +701,9 @@ public: // Copy initializer elements. std::vector Elts; Elts.reserve(NumInitableElts + NumElements); - unsigned i = 0; + bool RewriteType = false; - for (; i < NumInitableElts; ++i) { + for (unsigned i = 0; i < NumInitableElts; ++i) { Expr *Init = ILE->getInit(i); llvm::Constant *C = CGM.EmitConstantExpr(Init, Init->getType(), CGF); if (!C) @@ -722,8 +722,7 @@ public: if (!fillC) return 0; RewriteType |= (fillC->getType() != ElemTy); - for (; i < NumElements; ++i) - Elts.push_back(fillC); + Elts.resize(NumElements, fillC); if (RewriteType) { // FIXME: Try to avoid packing the array diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 4047a39287..d9b0e21238 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -895,8 +895,7 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) { if (CurIdx == 0) { // insert into undef -> shuffle (src, undef) Args.push_back(C); - for (unsigned j = 1; j != ResElts; ++j) - Args.push_back(llvm::UndefValue::get(CGF.Int32Ty)); + Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty)); LHS = EI->getVectorOperand(); RHS = V; @@ -907,9 +906,8 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) { for (unsigned j = 0; j != CurIdx; ++j) Args.push_back(getMaskElt(SVV, j, 0, CGF.Int32Ty)); Args.push_back(Builder.getInt32(ResElts + C->getZExtValue())); - for (unsigned j = CurIdx + 1; j != ResElts; ++j) - Args.push_back(llvm::UndefValue::get(CGF.Int32Ty)); - + Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty)); + LHS = cast(V)->getOperand(0); RHS = EI->getVectorOperand(); VIsUndefShuffle = false; @@ -953,8 +951,7 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) { } for (unsigned j = 0, je = InitElts; j != je; ++j) Args.push_back(getMaskElt(SVI, j, Offset, CGF.Int32Ty)); - for (unsigned j = CurIdx + InitElts; j != ResElts; ++j) - Args.push_back(llvm::UndefValue::get(CGF.Int32Ty)); + Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty)); if (VIsUndefShuffle) V = cast(V)->getOperand(0); @@ -968,8 +965,7 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) { if (Args.empty()) { for (unsigned j = 0; j != InitElts; ++j) Args.push_back(Builder.getInt32(j)); - for (unsigned j = InitElts; j != ResElts; ++j) - Args.push_back(llvm::UndefValue::get(CGF.Int32Ty)); + Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty)); llvm::Constant *Mask = llvm::ConstantVector::get(Args); Init = Builder.CreateShuffleVector(Init, llvm::UndefValue::get(VVT), Mask, "vext"); @@ -979,8 +975,7 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr *E) { Args.push_back(Builder.getInt32(j)); for (unsigned j = 0; j != InitElts; ++j) Args.push_back(Builder.getInt32(j+Offset)); - for (unsigned j = CurIdx + InitElts; j != ResElts; ++j) - Args.push_back(llvm::UndefValue::get(CGF.Int32Ty)); + Args.resize(ResElts, llvm::UndefValue::get(CGF.Int32Ty)); } // If V is undef, make sure it ends up on the RHS of the shuffle to aid diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 4c3c538b61..68c938149e 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -9159,8 +9159,7 @@ Sema::CompleteConstructorCall(CXXConstructorDecl *Constructor, bool Invalid = GatherArgumentsForCall(Loc, Constructor, Proto, 0, Args, NumArgs, AllArgs, CallType); - for (unsigned i =0, size = AllArgs.size(); i < size; i++) - ConvertedArgs.push_back(AllArgs[i]); + ConvertedArgs.append(AllArgs.begin(), AllArgs.end()); return Invalid; } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index a67bcf413c..4dc8a7bedd 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -4227,8 +4227,7 @@ ExprResult Sema::BuildVectorLiteral(SourceLocation LParenLoc, return ExprError(); } else - for (unsigned i = 0, e = numExprs; i != e; ++i) - initExprs.push_back(exprs[i]); + initExprs.append(exprs, exprs + numExprs); } else { // For OpenCL, when the number of initializers is a single value, @@ -4245,8 +4244,7 @@ ExprResult Sema::BuildVectorLiteral(SourceLocation LParenLoc, return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Literal.take()); } - for (unsigned i = 0, e = numExprs; i != e; ++i) - initExprs.push_back(exprs[i]); + initExprs.append(exprs, exprs + numExprs); } // FIXME: This means that pretty-printing the final AST will produce curly // braces instead of the original commas. -- 2.40.0