forked from llvm-mirror/llvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for invariant.start inside the static constructor evaluat…
…or. This is useful to represent a variable that is const in the source but can't be constant in the IR because of a non-trivial constructor. If globalopt evaluates the constructor, and there was an invariant.start with no matching invariant.end possible, it will mark the global constant afterwards. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150794 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
2 changed files
with
81 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
; RUN: opt -globalopt -S -o - < %s | FileCheck %s | ||
|
||
declare {}* @llvm.invariant.start(i64 %size, i8* nocapture %ptr) | ||
|
||
define void @test1(i8* %ptr) { | ||
call {}* @llvm.invariant.start(i64 -1, i8* %ptr) | ||
ret void | ||
} | ||
|
||
@object1 = global i32 0 | ||
; CHECK: @object1 = constant i32 -1 | ||
define void @ctor1() { | ||
store i32 -1, i32* @object1 | ||
%A = bitcast i32* @object1 to i8* | ||
call void @test1(i8* %A) | ||
ret void | ||
} | ||
|
||
|
||
@object2 = global i32 0 | ||
; CHECK: @object2 = global i32 0 | ||
define void @ctor2() { | ||
store i32 -1, i32* @object2 | ||
%A = bitcast i32* @object2 to i8* | ||
%B = call {}* @llvm.invariant.start(i64 -1, i8* %A) | ||
; Why in the world does this pass the verifier? | ||
%C = bitcast {}* %B to i8* | ||
ret void | ||
} | ||
|
||
@llvm.global_ctors = appending constant | ||
[2 x { i32, void ()* }] | ||
[ { i32, void ()* } { i32 65535, void ()* @ctor1 }, | ||
{ i32, void ()* } { i32 65535, void ()* @ctor2 } ] |