aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms/GlobalOpt
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2012-02-17 06:59:21 +0000
committerNick Lewycky <nicholas@mxc.ca>2012-02-17 06:59:21 +0000
commit81266c5c9358d71331886a98e750ac9409cc640c (patch)
tree70d61056257c6a311e8353773fef542a13adf21f /test/Transforms/GlobalOpt
parent38bdc5762f58b64d652864d154bf1b4dffb5ed39 (diff)
downloadexternal_llvm-81266c5c9358d71331886a98e750ac9409cc640c.zip
external_llvm-81266c5c9358d71331886a98e750ac9409cc640c.tar.gz
external_llvm-81266c5c9358d71331886a98e750ac9409cc640c.tar.bz2
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
Diffstat (limited to 'test/Transforms/GlobalOpt')
-rw-r--r--test/Transforms/GlobalOpt/invariant.ll34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/Transforms/GlobalOpt/invariant.ll b/test/Transforms/GlobalOpt/invariant.ll
new file mode 100644
index 0000000..2662d60
--- /dev/null
+++ b/test/Transforms/GlobalOpt/invariant.ll
@@ -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 } ]