Fix for PR2969: generate a memcpy from a constant for constant
initializers. llvm-gcc appears to be more aggressive, but incorrect,
for constructs like "const int a[] = {1,2,3};"; that said, current
optimizers will do the appropriate optimizations when safe.
llvm-svn: 60270
This commit is contained in:
@@ -369,12 +369,21 @@ void AggExprEmitter::VisitInitListExpr(InitListExpr *E) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: For constant expressions, call into const expr emitter so
|
// If we can, prefer a copy from a global; this is a lot less
|
||||||
// that we can emit a memcpy instead of storing the individual
|
// code for long globals, and it's easier for the current optimizers
|
||||||
// members. This is purely for perf; both codepaths lead to
|
// to analyze.
|
||||||
// equivalent (although not necessarily identical) code. It's worth
|
// FIXME: Should we really be doing this? Should we try to avoid
|
||||||
// noting that LLVM keeps on getting smarter, though, so it might
|
// cases where we emit a global with a lot of zeros? Should
|
||||||
// not be worth bothering.
|
// we try to avoid short globals?
|
||||||
|
if (E->isConstantExpr(CGF.getContext(), 0)) {
|
||||||
|
llvm::Constant* C = CGF.CGM.EmitConstantExpr(E, &CGF);
|
||||||
|
llvm::GlobalVariable* GV =
|
||||||
|
new llvm::GlobalVariable(C->getType(), true,
|
||||||
|
llvm::GlobalValue::InternalLinkage,
|
||||||
|
C, "", &CGF.CGM.getModule(), 0);
|
||||||
|
CGF.EmitAggregateCopy(DestPtr, GV, E->getType());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Handle initialization of an array.
|
// Handle initialization of an array.
|
||||||
if (E->getType()->isArrayType()) {
|
if (E->getType()->isArrayType()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user