-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GlobalOpt] support ConstantExpr use of global address for OptimizeGl…
…obalAddressOfMalloc I'm working on extending the OptimizeGlobalAddressOfMalloc to handle some more general cases. This is to add support of the ConstantExpr use of the global variables. The function allUsesOfLoadedValueWillTrapIfNull is now iterative with the added CE use of GV. Also, the recursive function valueIsOnlyUsedLocallyOrStoredToOneGlobal is changed to iterative using a worklist with the GEP case added. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D106589
- Loading branch information
Showing
3 changed files
with
130 additions
and
38 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,41 @@ | ||
; RUN: opt -globalopt -S < %s | FileCheck %s | ||
; RUN: opt -passes=globalopt -S < %s | FileCheck %s | ||
|
||
%s = type { i32 } | ||
@g = internal global %s* null, align 8 | ||
|
||
; Test code pattern for: | ||
; class s { int a; s() { a = 1;} }; | ||
; g = new s(); | ||
; | ||
|
||
define internal void @f() { | ||
; CHECK-LABEL: @f( | ||
; CHECK-NEXT: ret void | ||
; | ||
%1 = tail call i8* @_Znwm(i64 4) | ||
%2 = bitcast i8* %1 to %s* | ||
%3 = getelementptr inbounds %s, %s* %2, i64 0, i32 0 | ||
store i32 1, i32* %3, align 4 | ||
store i8* %1, i8** bitcast (%s** @g to i8**), align 8 | ||
ret void | ||
} | ||
|
||
define dso_local signext i32 @main() { | ||
; CHECK-LABEL: @main( | ||
; CHECK-NEXT: entry: | ||
; CHECK-NEXT: call fastcc void @f() | ||
; CHECK-NEXT: ret i32 1 | ||
; | ||
entry: | ||
call void @f() | ||
%0 = load %s*, %s** @g, align 4 | ||
%1 = getelementptr inbounds %s, %s* %0, i64 0, i32 0 | ||
%2 = load i32, i32* %1, align 4 | ||
ret i32 %2 | ||
} | ||
|
||
declare nonnull i8* @_Znwm(i64) | ||
|
||
declare signext i32 @printf(i8*, ...) | ||
|