diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-03-28 14:50:09 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-03-28 14:50:09 +0000 |
commit | aa9e4a5e590985f9e58a1efb83cb5cb10964fbbf (patch) | |
tree | 6896b7b433b8e6c2da260bd026d8201306510ad8 /llvm/lib/Transforms/IPO | |
parent | ce9978ff1f751b30f52d309756015489146b48bc (diff) | |
download | bcm5719-llvm-aa9e4a5e590985f9e58a1efb83cb5cb10964fbbf.tar.gz bcm5719-llvm-aa9e4a5e590985f9e58a1efb83cb5cb10964fbbf.zip |
GlobalOpt: If we have an inbounds GEP from a ConstantAggregateZero global that we just determined to be constant, replace all loads from it with a zero value.
llvm-svn: 153576
Diffstat (limited to 'llvm/lib/Transforms/IPO')
-rw-r--r-- | llvm/lib/Transforms/IPO/GlobalOpt.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/GlobalOpt.cpp b/llvm/lib/Transforms/IPO/GlobalOpt.cpp index a32e5509545..1522aa408b6 100644 --- a/llvm/lib/Transforms/IPO/GlobalOpt.cpp +++ b/llvm/lib/Transforms/IPO/GlobalOpt.cpp @@ -341,6 +341,12 @@ static bool CleanupConstantGlobalUsers(Value *V, Constant *Init, dyn_cast_or_null<ConstantExpr>(ConstantFoldInstruction(GEP, TD, TLI)); if (Init && CE && CE->getOpcode() == Instruction::GetElementPtr) SubInit = ConstantFoldLoadThroughGEPConstantExpr(Init, CE); + + // If the initializer is an all-null value and we have an inbounds GEP, + // we already know what the result of any load from that GEP is. + // TODO: Handle splats. + if (Init && isa<ConstantAggregateZero>(Init) && GEP->isInBounds()) + SubInit = Constant::getNullValue(GEP->getType()->getElementType()); } Changed |= CleanupConstantGlobalUsers(GEP, SubInit, TD, TLI); |