[RewriteStatepointsForGC] Exclude constant values from being considered live at a...
[oota-llvm.git] / test / Transforms / RewriteStatepointsForGC / constants.ll
1 ; RUN: opt -S -rewrite-statepoints-for-gc %s | FileCheck %s
2
3 declare void @foo()
4 declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()*, i32, i32, ...)
5
6 ; constants don't get relocated.
7 define i8 @test() gc "statepoint-example" {
8 ; CHECK-LABEL: @test
9 ; CHECK: gc.statepoint
10 ; CHECK-NEXT: load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
11 entry:
12   call i32 (void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 0, i32 0)
13   %res = load i8, i8 addrspace(1)* inttoptr (i64 15 to i8 addrspace(1)*)
14   ret i8 %res
15 }
16
17
18 ; Mostly just here to show reasonable code test can come from.  
19 define i8 @test2(i8 addrspace(1)* %p) gc "statepoint-example" {
20 ; CHECK-LABEL: @test2
21 ; CHECK: gc.statepoint
22 ; CHECK-NEXT: gc.relocate
23 ; CHECK-NEXT: icmp
24 entry:
25   call i32 (void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 0, i32 0)
26   %cmp = icmp eq i8 addrspace(1)* %p, null
27   br i1 %cmp, label %taken, label %not_taken
28
29 taken:
30   ret i8 0
31
32 not_taken:
33   %cmp2 = icmp ne i8 addrspace(1)* %p, null
34   br i1 %cmp2, label %taken, label %dead
35
36 dead:
37   ; We see that dead can't be reached, but the optimizer might not.  It's 
38   ; completely legal for it to exploit the fact that if dead executed, %p 
39   ; would have to equal null.  This can produce intermediate states which 
40   ; look like that of test above, even if arbitrary constant addresses aren't
41   ; legal in the source language
42   %addr = getelementptr i8, i8 addrspace(1)* %p, i32 15
43   %res = load i8, i8addrspace(1)* %addr
44   ret i8 %res
45 }
46
47 @G = addrspace(1) global i8 5
48
49 ; Globals don't move and thus don't get relocated
50 define i8 @test3(i1 %always_true) gc "statepoint-example" {
51 ; CHECK-LABEL: @test3
52 ; CHECK: gc.statepoint
53 ; CHECK-NEXT: load i8, i8 addrspace(1)* @G
54 entry:
55   call i32 (void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(void ()* @foo, i32 0, i32 0, i32 0)
56   %res = load i8, i8 addrspace(1)* @G, align 1
57   ret i8 %res
58 }
59
60
61