Skip to content

Commit

Permalink
Use a simpler (and more efficient) pattern to pad vectors.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150475 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
d0k committed Feb 14, 2012
1 parent 3164c14 commit 14c5982
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
6 changes: 2 additions & 4 deletions lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<llvm::Constant*, 4> 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,
Expand Down
7 changes: 3 additions & 4 deletions lib/CodeGen/CGExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,9 @@ class ConstExprEmitter :
// Copy initializer elements.
std::vector<llvm::Constant*> 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)
Expand All @@ -722,8 +722,7 @@ class ConstExprEmitter :
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
Expand Down
17 changes: 6 additions & 11 deletions lib/CodeGen/CGExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<llvm::ShuffleVectorInst>(V)->getOperand(0);
RHS = EI->getVectorOperand();
VIsUndefShuffle = false;
Expand Down Expand Up @@ -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<llvm::ShuffleVectorInst>(V)->getOperand(0);
Expand All @@ -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");
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 2 additions & 4 deletions lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down

0 comments on commit 14c5982

Please sign in to comment.