1 ; RUN: opt -S -rewrite-statepoints-for-gc < %s | FileCheck %s
2 ; RUN: opt -S -passes=rewrite-statepoints-for-gc < %s | FileCheck %s
4 ; This test checks that metadata that's invalid after RS4GC is dropped.
5 ; We can miscompile if optimizations scheduled after RS4GC uses the
6 ; metadata that's infact invalid.
10 declare void @baz(i32)
11 ; Confirm that loadedval instruction does not contain invariant.load metadata.
12 ; but contains the range metadata.
13 ; Since loadedval is not marked invariant, it will prevent incorrectly sinking
14 ; %loadedval in LICM and avoid creation of an unrelocated use of %baseaddr.
15 define void @test_invariant_load() gc "statepoint-example" {
16 ; CHECK-LABEL: @test_invariant_load
17 ; CHECK: %loadedval = load i32, i32 addrspace(1)* %baseaddr, align 8, !range !0
19 br label %outerloopHdr
21 outerloopHdr: ; preds = %bb6, %bb
22 %baseaddr = phi i32 addrspace(1)* [ undef, %bb ], [ %tmp4, %bb6 ]
23 ; LICM may sink this load to exit block after RS4GC because it's tagged invariant.
24 %loadedval = load i32, i32 addrspace(1)* %baseaddr, align 8, !range !0, !invariant.load !1
25 br label %innerloopHdr
27 innerloopHdr: ; preds = %innerlooplatch, %outerloopHdr
28 %tmp4 = phi i32 addrspace(1)* [ %baseaddr, %outerloopHdr ], [ %gep, %innerlooplatch ]
29 br label %innermostloophdr
31 innermostloophdr: ; preds = %bb6, %innerloopHdr
32 br i1 undef, label %exitblock, label %bb6
34 bb6: ; preds = %innermostloophdr
35 switch i32 undef, label %innermostloophdr [
36 i32 0, label %outerloopHdr
37 i32 1, label %innerlooplatch
40 innerlooplatch: ; preds = %bb6
42 %gep = getelementptr inbounds i32, i32 addrspace(1)* %tmp4, i64 8
43 br label %innerloopHdr
45 exitblock: ; preds = %innermostloophdr
46 %tmp13 = add i32 42, %loadedval
47 call void @baz(i32 %tmp13)
51 ; drop the noalias metadata.
52 define void @test_noalias(i32 %x, i32 addrspace(1)* %p, i32 addrspace(1)* %q) gc "statepoint-example" {
53 ; CHECK-LABEL: test_noalias
54 ; CHECK: %y = load i32, i32 addrspace(1)* %q, align 16
55 ; CHECK: gc.statepoint
57 ; CHECK-NEXT: %p.relocated.casted = bitcast i8 addrspace(1)* %p.relocated to i32 addrspace(1)*
58 ; CHECK-NEXT: store i32 %x, i32 addrspace(1)* %p.relocated.casted, align 16
60 %y = load i32, i32 addrspace(1)* %q, align 16, !noalias !3
61 call void @baz(i32 %x)
62 store i32 %x, i32 addrspace(1)* %p, align 16, !noalias !4
66 ; drop the dereferenceable metadata
67 define void @test_dereferenceable(i32 addrspace(1)* addrspace(1)* %p, i32 %x, i32 addrspace(1)* %q) gc "statepoint-example" {
68 ; CHECK-LABEL: test_dereferenceable
69 ; CHECK: %v1 = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(1)* %p
70 ; CHECK-NEXT: %v2 = load i32, i32 addrspace(1)* %v1
71 ; CHECK: gc.statepoint
72 %v1 = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(1)* %p, !dereferenceable !5
73 %v2 = load i32, i32 addrspace(1)* %v1
74 call void @baz(i32 %x)
75 store i32 %v2, i32 addrspace(1)* %q, align 16
79 ; invariant.start allows us to sink the load past the baz statepoint call into taken block, which is
80 ; incorrect. remove the invariant.start and RAUW undef.
81 define void @test_inv_start(i1 %cond, i32 addrspace(1)* addrspace(1)* %p, i32 %x, i32 addrspace(1)* %q) gc "statepoint-example" {
82 ; CHECK-LABEL: test_inv_start
83 ; CHECK-NOT: invariant.start
84 ; CHECK: gc.statepoint
85 %v1 = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(1)* %p
86 %invst = call {}* @llvm.invariant.start.p1i32(i64 1, i32 addrspace(1)* %v1)
87 %v2 = load i32, i32 addrspace(1)* %v1
88 call void @baz(i32 %x)
89 br i1 %cond, label %taken, label %untaken
92 store i32 %v2, i32 addrspace(1)* %q, align 16
93 call void @llvm.invariant.end.p1i32({}* %invst, i64 4, i32 addrspace(1)* %v1)
96 ; CHECK-LABEL: untaken:
97 ; CHECK: gc.statepoint
99 %foo = call i32 @escaping.invariant.start({}* %invst)
100 call void @dummy(i32 %foo)
104 ; invariant.start is removed and the uses are undef'ed.
105 define void @test_inv_start2(i1 %cond, i32 addrspace(1)* addrspace(1)* %p, i32 %x, i32 addrspace(1)* %q) gc "statepoint-example" {
106 ; CHECK-LABEL: test_inv_start2
107 ; CHECK-NOT: invariant.start
108 ; CHECK: gc.statepoint
109 %v1 = load i32 addrspace(1)*, i32 addrspace(1)* addrspace(1)* %p
110 %invst = call {}* @llvm.invariant.start.p1i32(i64 1, i32 addrspace(1)* %v1)
111 %v2 = load i32, i32 addrspace(1)* %v1
112 call void @baz(i32 %x)
113 br i1 %cond, label %taken, label %untaken
116 store i32 %v2, i32 addrspace(1)* %q, align 16
117 call void @llvm.invariant.end.p1i32({}* %invst, i64 4, i32 addrspace(1)* %v1)
123 declare {}* @llvm.invariant.start.p1i32(i64, i32 addrspace(1)* nocapture) nounwind readonly
124 declare void @llvm.invariant.end.p1i32({}*, i64, i32 addrspace(1)* nocapture) nounwind
125 declare i32 @escaping.invariant.start({}*) nounwind
126 declare void @dummy(i32)
127 declare token @llvm.experimental.gc.statepoint.p0f_isVoidi32f(i64, i32, void (i32)*, i32, i32, ...)
129 ; Function Attrs: nounwind readonly
130 declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32) #0
132 declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
134 attributes #0 = { nounwind readonly }
136 !0 = !{i32 0, i32 2147483647}
138 !2 = !{i32 10, i32 1}