diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-08-27 21:35:58 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-08-27 21:35:58 +0000 |
commit | cfa07e3519cff1c69cd39d02c80263fd6469c3db (patch) | |
tree | 4e75951cc9f4e9d2a4dd0fe9f3587eb5e8c3eda7 /lib/CodeGen | |
parent | 29760b452876548f59804e8c02c3276bc7281d5d (diff) |
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
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGDecl.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
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<llvm::ConstantDataSequential>(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<llvm::UndefValue>(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<llvm::Constant>(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<llvm::UndefValue>(Elt)) + emitStoresForInitAfterMemset(Elt, Builder.CreateConstGEP2_32(Loc, 0, i), + isVolatile, Builder); } } |