Add support for invariant.start inside the static constructor evaluator. 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
This commit is contained in:
Nick Lewycky
2012-02-17 06:59:21 +00:00
parent 38bdc5762f
commit 81266c5c93
2 changed files with 81 additions and 12 deletions

View File

@@ -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 } ]