From cfa07e3519cff1c69cd39d02c80263fd6469c3db Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 27 Aug 2012 21:35:58 +0000 Subject: CodeGen: When emitting stores for an initializer, only emit a GEP if we really need the store. This avoids emitting many dead GEPs for large zero-initialized arrays. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162701 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDecl.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'lib/CodeGen') diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index be6638e0e5..8543ca8eef 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -719,10 +719,11 @@ static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc, dyn_cast(Init)) { for (unsigned i = 0, e = CDS->getNumElements(); i != e; ++i) { llvm::Constant *Elt = CDS->getElementAsConstant(i); - - // Get a pointer to the element and emit it. - emitStoresForInitAfterMemset(Elt, Builder.CreateConstGEP2_32(Loc, 0, i), - isVolatile, Builder); + + // If necessary, get a pointer to the element and emit it. + if (!Elt->isNullValue() && !isa(Elt)) + emitStoresForInitAfterMemset(Elt, Builder.CreateConstGEP2_32(Loc, 0, i), + isVolatile, Builder); } return; } @@ -732,9 +733,11 @@ static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc, for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) { llvm::Constant *Elt = cast(Init->getOperand(i)); - // Get a pointer to the element and emit it. - emitStoresForInitAfterMemset(Elt, Builder.CreateConstGEP2_32(Loc, 0, i), - isVolatile, Builder); + + // If necessary, get a pointer to the element and emit it. + if (!Elt->isNullValue() && !isa(Elt)) + emitStoresForInitAfterMemset(Elt, Builder.CreateConstGEP2_32(Loc, 0, i), + isVolatile, Builder); } } -- cgit v1.2.3-70-g09d2