[InstCombine] X - 0 is equal to X, not undef
[oota-llvm.git] / test / Transforms / RewriteStatepointsForGC / live-vector.ll
1 ; Test that we can correctly handle vectors of pointers in statepoint 
2 ; rewriting.  Currently, we scalarize, but that's an implementation detail.
3 ; RUN: opt %s -rewrite-statepoints-for-gc -S | FileCheck  %s
4
5 ; A non-vector relocation for comparison
6 define i64 addrspace(1)* @test(i64 addrspace(1)* %obj) gc "statepoint-example" {
7 ; CHECK-LABEL: test
8 ; CHECK: gc.statepoint
9 ; CHECK-NEXT: gc.relocate
10 ; CHECK-NEXT: bitcast
11 ; CHECK-NEXT: ret i64 addrspace(1)* %obj.relocated.casted
12 entry:
13   %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0)
14   ret i64 addrspace(1)* %obj
15 }
16
17 ; A base vector from a argument
18 define <2 x i64 addrspace(1)*> @test2(<2 x i64 addrspace(1)*> %obj) gc "statepoint-example" {
19 ; CHECK-LABEL: test2
20 ; CHECK: extractelement
21 ; CHECK-NEXT: extractelement
22 ; CHECK-NEXT: gc.statepoint
23 ; CHECK-NEXT: gc.relocate
24 ; CHECK-NEXT: bitcast
25 ; CHECK-NEXT: gc.relocate
26 ; CHECK-NEXT: bitcast
27 ; CHECK-NEXT: insertelement
28 ; CHECK-NEXT: insertelement
29 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*> %7
30 entry:
31   %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0)
32   ret <2 x i64 addrspace(1)*> %obj
33 }
34
35 ; A base vector from a load
36 define <2 x i64 addrspace(1)*> @test3(<2 x i64 addrspace(1)*>* %ptr) gc "statepoint-example" {
37 ; CHECK-LABEL: test3
38 ; CHECK: load
39 ; CHECK-NEXT: extractelement
40 ; CHECK-NEXT: extractelement
41 ; CHECK-NEXT: gc.statepoint
42 ; CHECK-NEXT: gc.relocate
43 ; CHECK-NEXT: bitcast
44 ; CHECK-NEXT: gc.relocate
45 ; CHECK-NEXT: bitcast
46 ; CHECK-NEXT: insertelement
47 ; CHECK-NEXT: insertelement
48 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*> %7
49 entry:
50   %obj = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
51   %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0)
52   ret <2 x i64 addrspace(1)*> %obj
53 }
54
55 declare i32 @fake_personality_function()
56
57 ; When a statepoint is an invoke rather than a call
58 define <2 x i64 addrspace(1)*> @test4(<2 x i64 addrspace(1)*>* %ptr) gc "statepoint-example" {
59 ; CHECK-LABEL: test4
60 ; CHECK: load
61 ; CHECK-NEXT: extractelement
62 ; CHECK-NEXT: extractelement
63 ; CHECK-NEXT: gc.statepoint
64 entry:
65   %obj = load <2 x i64 addrspace(1)*>, <2 x i64 addrspace(1)*>* %ptr
66   invoke i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0)
67           to label %normal_return unwind label %exceptional_return
68
69 ; CHECK-LABEL: normal_return:
70 ; CHECK: gc.relocate
71 ; CHECK-NEXT: bitcast
72 ; CHECK-NEXT: gc.relocate
73 ; CHECK-NEXT: bitcast
74 ; CHECK-NEXT: insertelement
75 ; CHECK-NEXT: insertelement
76 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*> %8
77 normal_return:                                    ; preds = %entry
78   ret <2 x i64 addrspace(1)*> %obj
79
80 ; CHECK-LABEL: exceptional_return:
81 ; CHECK: gc.relocate
82 ; CHECK-NEXT: bitcast
83 ; CHECK-NEXT: gc.relocate
84 ; CHECK-NEXT: bitcast
85 ; CHECK-NEXT: insertelement
86 ; CHECK-NEXT: insertelement
87 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*> %14
88 exceptional_return:                               ; preds = %entry
89   %landing_pad4 = landingpad { i8*, i32 } personality i32 ()* @fake_personality_function
90           cleanup
91   ret <2 x i64 addrspace(1)*> %obj
92 }
93
94 ; Can we handle an insert element with a constant offset?  This effectively
95 ; tests both the equal and inequal case since we have to relocate both indices
96 ; in the vector.
97 define <2 x i64 addrspace(1)*> @test5(i64 addrspace(1)* %p) 
98      gc "statepoint-example" {
99 ; CHECK-LABEL: test5
100 ; CHECK: insertelement
101 ; CHECK-NEXT: extractelement
102 ; CHECK-NEXT: extractelement
103 ; CHECK-NEXT: gc.statepoint
104 ; CHECK-NEXT: gc.relocate
105 ; CHECK-NEXT: bitcast
106 ; CHECK-NEXT: gc.relocate
107 ; CHECK-NEXT: bitcast
108 ; CHECK-NEXT: gc.relocate
109 ; CHECK-NEXT: bitcast
110 ; CHECK-NEXT: insertelement
111 ; CHECK-NEXT: insertelement
112 ; CHECK-NEXT: ret <2 x i64 addrspace(1)*> %7
113 entry:
114   %vec = insertelement <2 x i64 addrspace(1)*> undef, i64 addrspace(1)* %p, i32 0
115   %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* @do_safepoint, i32 0, i32 0, i32 0, i32 0)
116   ret <2 x i64 addrspace(1)*> %vec
117 }
118
119 declare void @do_safepoint()
120
121 declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)