Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GlobalOpt] recognize dead struct fields and propagate values
Summary: Allow struct fields SRA and dead stores. This works by considering fields accesses from getElementPtr to be considered as a possible pointer root that can be cleaned up. We check that the variable can be SRA by recursively checking the sub expressions with the new isSafeSubSROAGEP function. basically this allows the array in following C code to be optimized out struct Expr { int a[2]; int b; }; static struct Expr e; int foo (int i) { e.b = 2; e.a[i] = 1; return e.b; } Reviewers: greened, bkramer, nicholas, jmolloy Reviewed By: jmolloy Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D61911 llvm-svn: 361460
- Loading branch information
Christian Bruel
committed
May 23, 2019
1 parent
202dc12
commit 4a7da98
Showing
3 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
; RUN: opt < %s -globalopt -S | FileCheck %s | ||
|
||
%struct.Expr = type { [1 x i32], i32 } | ||
|
||
@e = internal global %struct.Expr zeroinitializer, align 4 | ||
; CHECK-NOT: @e = internal global %struct.Expr zeroinitializer, align 4 | ||
|
||
define dso_local i32 @foo(i32 %i) { | ||
entry: | ||
%i.addr = alloca i32, align 4 | ||
store i32 %i, i32* %i.addr, align 4 | ||
%0 = load i32, i32* %i.addr, align 4 | ||
%arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* getelementptr inbounds (%struct.Expr, %struct.Expr* @e, i32 0, i32 0), i32 0, i32 %0 | ||
store i32 57005, i32* %arrayidx, align 4 | ||
%1 = load i32, i32* getelementptr inbounds (%struct.Expr, %struct.Expr* @e, i32 0, i32 1), align 4 | ||
ret i32 %1 | ||
; CHECK: ret i32 0 | ||
} |