1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=gvn -S < %s | FileCheck %s
5 declare i32 @"personality_function"()
7 define i1 @test_trivial(ptr addrspace(1) %in) gc "statepoint-example" {
8 ; CHECK-LABEL: @test_trivial(
10 ; CHECK-NEXT: [[SAFEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) [[IN:%.*]]) ]
11 ; CHECK-NEXT: [[A:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 0, i32 0)
12 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq ptr addrspace(1) [[A]], null
13 ; CHECK-NEXT: ret i1 [[CMP1]]
16 %safepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %in)]
17 %a = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
18 %b = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
19 %cmp1 = icmp eq ptr addrspace(1) %a, null
20 %cmp2 = icmp eq ptr addrspace(1) %b, null
21 %cmp = and i1 %cmp1, %cmp2
25 @G = external global i32
27 define i1 @test_readnone(ptr addrspace(1) %in) gc "statepoint-example" {
28 ; CHECK-LABEL: @test_readnone(
30 ; CHECK-NEXT: [[SAFEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) [[IN:%.*]]) ]
31 ; CHECK-NEXT: [[A:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 0, i32 0)
32 ; CHECK-NEXT: store i32 0, ptr @G, align 4
33 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq ptr addrspace(1) [[A]], null
34 ; CHECK-NEXT: ret i1 [[CMP1]]
37 %safepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %in)]
38 %a = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
40 %b = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
41 %cmp1 = icmp eq ptr addrspace(1) %a, null
42 %cmp2 = icmp eq ptr addrspace(1) %b, null
43 %cmp = and i1 %cmp1, %cmp2
47 define i1 @test_call(ptr addrspace(1) %in) gc "statepoint-example" {
48 ; CHECK-LABEL: @test_call(
50 ; CHECK-NEXT: [[SAFEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) [[IN:%.*]], ptr addrspace(1) [[IN]]) ]
51 ; CHECK-NEXT: [[BASE:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 0, i32 0)
52 ; CHECK-NEXT: [[SAFEPOINT_TOKEN2:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) [[BASE]], ptr addrspace(1) [[BASE]]) ]
53 ; CHECK-NEXT: [[BASE_RELOC:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN2]], i32 0, i32 0)
54 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq ptr addrspace(1) [[BASE_RELOC]], null
55 ; CHECK-NEXT: ret i1 [[CMP1]]
58 %safepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %in, ptr addrspace(1) %in)]
59 %base = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
60 %derived = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 1)
61 %safepoint_token2 = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %base, ptr addrspace(1) %derived)]
65 %base_reloc = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2, i32 0, i32 0)
66 %derived_reloc = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2, i32 0, i32 1)
67 %cmp1 = icmp eq ptr addrspace(1) %base_reloc, null
68 %cmp2 = icmp eq ptr addrspace(1) %derived_reloc, null
69 %cmp = and i1 %cmp1, %cmp2
73 ; Negative test: Check that relocates from different statepoints are not CSE'd
74 define i1 @test_two_calls(ptr addrspace(1) %in1, ptr addrspace(1) %in2) gc "statepoint-example" {
75 ; CHECK-LABEL: @test_two_calls(
77 ; CHECK-NEXT: [[SAFEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) [[IN1:%.*]], ptr addrspace(1) [[IN2:%.*]]) ]
78 ; CHECK-NEXT: [[IN1_RELOC1:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 0, i32 0)
79 ; CHECK-NEXT: [[IN2_RELOC1:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 1, i32 1)
80 ; CHECK-NEXT: [[SAFEPOINT_TOKEN2:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) [[IN1_RELOC1]], ptr addrspace(1) [[IN2_RELOC1]]) ]
81 ; CHECK-NEXT: [[IN1_RELOC2:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN2]], i32 0, i32 1)
82 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq ptr addrspace(1) [[IN1_RELOC2]], null
83 ; CHECK-NEXT: ret i1 [[CMP1]]
86 %safepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %in1, ptr addrspace(1) %in2)]
87 %in1.reloc1 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
88 %in2.reloc1 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 1, i32 1)
89 %safepoint_token2 = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %in1.reloc1, ptr addrspace(1) %in2.reloc1)]
90 %in1.reloc2 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2, i32 0, i32 1)
91 %in2.reloc2 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2, i32 0, i32 1)
92 %cmp1 = icmp eq ptr addrspace(1) %in1.reloc2, null
93 %cmp2 = icmp eq ptr addrspace(1) %in2.reloc2, null
94 %cmp = and i1 %cmp1, %cmp2
98 ; Negative test: Check that relocates from normal and exceptional pathes are not be CSE'd
99 define ptr addrspace(1) @test_invoke(ptr addrspace(1) %in) gc "statepoint-example" personality ptr @"personality_function" {
100 ; CHECK-LABEL: @test_invoke(
101 ; CHECK-NEXT: [[SAFEPOINT_TOKEN:%.*]] = invoke token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) [[IN:%.*]]) ]
102 ; CHECK-NEXT: to label [[INVOKE_NORMAL_DEST:%.*]] unwind label [[EXCEPTIONAL_RETURN:%.*]]
103 ; CHECK: invoke_normal_dest:
104 ; CHECK-NEXT: [[OUT:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 0, i32 0)
105 ; CHECK-NEXT: ret ptr addrspace(1) [[OUT]]
106 ; CHECK: exceptional_return:
107 ; CHECK-NEXT: [[LANDING_PAD:%.*]] = landingpad token
108 ; CHECK-NEXT: cleanup
109 ; CHECK-NEXT: [[OUT1:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[LANDING_PAD]], i32 0, i32 0)
110 ; CHECK-NEXT: ret ptr addrspace(1) [[OUT1]]
112 %safepoint_token = invoke token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %in)]
113 to label %invoke_normal_dest unwind label %exceptional_return
116 %out = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
117 ret ptr addrspace(1) %out
120 %landing_pad = landingpad token
122 %out1 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %landing_pad, i32 0, i32 0)
123 ret ptr addrspace(1) %out1
126 ; negative test - neither dominates the other
127 define i1 @test_non_dominating(i1 %c, ptr addrspace(1) %in) gc "statepoint-example" {
129 ; CHECK-LABEL: @test_non_dominating(
131 ; CHECK-NEXT: [[SAFEPOINT_TOKEN:%.*]] = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) [ "gc-live"(ptr addrspace(1) [[IN:%.*]]) ]
132 ; CHECK-NEXT: br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
134 ; CHECK-NEXT: [[A:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 0, i32 0)
135 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr addrspace(1) [[A]], null
136 ; CHECK-NEXT: ret i1 [[CMP]]
138 ; CHECK-NEXT: [[B:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 0, i32 0)
139 ; CHECK-NEXT: [[CMP2:%.*]] = icmp eq ptr addrspace(1) [[B]], null
140 ; CHECK-NEXT: ret i1 [[CMP2]]
143 %safepoint_token = call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(void ()) @func, i32 0, i32 0, i32 0, i32 0) ["gc-live"(ptr addrspace(1) %in)]
144 br i1 %c, label %taken, label %untaken
146 %a = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
147 %cmp = icmp eq ptr addrspace(1) %a, null
150 %b = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token, i32 0, i32 0)
151 %cmp2 = icmp eq ptr addrspace(1) %b, null
155 declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)
156 declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32)