xref: /llvm-project/llvm/test/Transforms/EarlyCSE/gc_relocate.ll (revision ac696ac4530fb3df626195e94e83649bf7114754)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -passes=early-cse -earlycse-debug-hash -S < %s | FileCheck %s
3
4declare void @func()
5declare i32 @"personality_function"()
6
7define i1 @test_trivial(ptr addrspace(1) %in) gc "statepoint-example" {
8; CHECK-LABEL: @test_trivial(
9; CHECK-NEXT:  entry:
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]]
14;
15entry:
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
22  ret i1 %cmp
23}
24
25@G = external global i32
26
27define i1 @test_readnone(ptr addrspace(1) %in) gc "statepoint-example" {
28; CHECK-LABEL: @test_readnone(
29; CHECK-NEXT:  entry:
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]]
35;
36entry:
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)
39  store i32 0, ptr @G
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
44  ret i1 %cmp
45}
46
47define i1 @test_call(ptr addrspace(1) %in) gc "statepoint-example" {
48; CHECK-LABEL: @test_call(
49; CHECK-NEXT:  entry:
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:    br label [[NEXT:%.*]]
54; CHECK:       next:
55; CHECK-NEXT:    [[BASE_RELOC:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN2]], i32 0, i32 0)
56; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq ptr addrspace(1) [[BASE_RELOC]], null
57; CHECK-NEXT:    ret i1 [[CMP1]]
58;
59entry:
60  %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)]
61  %base = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token,  i32 0, i32 0)
62  %derived = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token,  i32 0, i32 1)
63  %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)]
64  br label %next
65
66next:
67  %base_reloc = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2,  i32 0, i32 0)
68  %derived_reloc = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2,  i32 0, i32 1)
69  %cmp1 = icmp eq ptr addrspace(1) %base_reloc, null
70  %cmp2 = icmp eq ptr addrspace(1) %derived_reloc, null
71  %cmp = and i1 %cmp1, %cmp2
72  ret i1 %cmp
73}
74
75; Negative test: Check that relocates from different statepoints are not CSE'd
76define i1 @test_two_calls(ptr addrspace(1) %in1, ptr addrspace(1) %in2) gc "statepoint-example" {
77; CHECK-LABEL: @test_two_calls(
78; CHECK-NEXT:  entry:
79; 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:%.*]]) ]
80; CHECK-NEXT:    [[IN1_RELOC1:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 0, i32 0)
81; CHECK-NEXT:    [[IN2_RELOC1:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 1, i32 1)
82; 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]]) ]
83; CHECK-NEXT:    [[IN1_RELOC2:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN2]], i32 0, i32 1)
84; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq ptr addrspace(1) [[IN1_RELOC2]], null
85; CHECK-NEXT:    ret i1 [[CMP1]]
86;
87entry:
88  %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)]
89  %in1.reloc1 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token,  i32 0, i32 0)
90  %in2.reloc1 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token,  i32 1, i32 1)
91  %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)]
92  %in1.reloc2 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2,  i32 0, i32 1)
93  %in2.reloc2 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token2,  i32 0, i32 1)
94  %cmp1 = icmp eq ptr addrspace(1) %in1.reloc2, null
95  %cmp2 = icmp eq ptr addrspace(1) %in2.reloc2, null
96  %cmp = and i1 %cmp1, %cmp2
97  ret i1 %cmp
98}
99
100; Negative test: Check that relocates from normal and exceptional pathes are not be CSE'd
101define ptr addrspace(1) @test_invoke(ptr addrspace(1) %in) gc "statepoint-example" personality ptr @"personality_function" {
102; CHECK-LABEL: @test_invoke(
103; 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:%.*]]) ]
104; CHECK-NEXT:    to label [[INVOKE_NORMAL_DEST:%.*]] unwind label [[EXCEPTIONAL_RETURN:%.*]]
105; CHECK:       invoke_normal_dest:
106; CHECK-NEXT:    [[OUT:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 0, i32 0)
107; CHECK-NEXT:    ret ptr addrspace(1) [[OUT]]
108; CHECK:       exceptional_return:
109; CHECK-NEXT:    [[LANDING_PAD:%.*]] = landingpad token
110; CHECK-NEXT:    cleanup
111; CHECK-NEXT:    [[OUT1:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[LANDING_PAD]], i32 0, i32 0)
112; CHECK-NEXT:    ret ptr addrspace(1) [[OUT1]]
113;
114  %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)]
115  to label %invoke_normal_dest unwind label %exceptional_return
116
117invoke_normal_dest:
118  %out = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token,  i32 0, i32 0)
119  ret ptr addrspace(1) %out
120
121exceptional_return:
122  %landing_pad = landingpad token
123  cleanup
124  %out1 = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %landing_pad, i32 0, i32 0)
125  ret ptr addrspace(1) %out1
126}
127
128; negative test - neither dominates the other
129define i1 @test_non_dominating(i1 %c, ptr addrspace(1) %in) gc "statepoint-example" {
130;
131; CHECK-LABEL: @test_non_dominating(
132; CHECK-NEXT:  entry:
133; 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:%.*]]) ]
134; CHECK-NEXT:    br i1 [[C:%.*]], label [[TAKEN:%.*]], label [[UNTAKEN:%.*]]
135; CHECK:       taken:
136; CHECK-NEXT:    [[A:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 0, i32 0)
137; CHECK-NEXT:    [[CMP:%.*]] = icmp eq ptr addrspace(1) [[A]], null
138; CHECK-NEXT:    ret i1 [[CMP]]
139; CHECK:       untaken:
140; CHECK-NEXT:    [[B:%.*]] = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token [[SAFEPOINT_TOKEN]], i32 0, i32 0)
141; CHECK-NEXT:    [[CMP2:%.*]] = icmp eq ptr addrspace(1) [[B]], null
142; CHECK-NEXT:    ret i1 [[CMP2]]
143;
144entry:
145  %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)]
146  br i1 %c, label %taken, label %untaken
147taken:
148  %a = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token,  i32 0, i32 0)
149  %cmp = icmp eq ptr addrspace(1) %a, null
150  ret i1 %cmp
151untaken:
152  %b = call ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token %safepoint_token,  i32 0, i32 0)
153  %cmp2 = icmp eq ptr addrspace(1) %b, null
154  ret i1 %cmp2
155}
156
157declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)
158declare ptr addrspace(1) @llvm.experimental.gc.relocate.p1(token, i32, i32)
159