mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-28 22:20:43 +00:00
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153576 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9b58464330
commit
c1ea16ec43
@ -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);
|
||||
|
||||
|
11
test/Transforms/GlobalOpt/zeroinitializer-gep-load.ll
Normal file
11
test/Transforms/GlobalOpt/zeroinitializer-gep-load.ll
Normal file
@ -0,0 +1,11 @@
|
||||
; RUN: opt < %s -S -globalopt | FileCheck %s
|
||||
|
||||
@zero = internal global [10 x i32] zeroinitializer
|
||||
|
||||
define i32 @test1(i64 %idx) nounwind {
|
||||
%arrayidx = getelementptr inbounds [10 x i32]* @zero, i64 0, i64 %idx
|
||||
%l = load i32* %arrayidx
|
||||
ret i32 %l
|
||||
; CHECK: @test1
|
||||
; CHECK: ret i32 0
|
||||
}
|
Loading…
Reference in New Issue
Block a user