Skip to content

Commit 0387679

Browse files
committed
[Coroutines] Presubmit retcon without suspend test
The test gets incorrectly optimized to unreachable.
1 parent e82b5b5 commit 0387679

File tree

1 file changed

+75
-3
lines changed

1 file changed

+75
-3
lines changed

llvm/test/Transforms/Coroutines/coro-retcon.ll

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; First example from Doc/Coroutines.rst (two block loop) converted to retcon
33
; RUN: opt < %s -passes='default<O2>' -S | FileCheck %s
4+
; RUN: opt < %s -passes='module(coro-early),cgscc(coro-split),module(coro-cleanup)' -S | FileCheck --check-prefix=CORO %s
45

56
define i8* @f(i8* %buffer, i32 %n) {
67
; CHECK-LABEL: @f(
@@ -10,6 +11,15 @@ define i8* @f(i8* %buffer, i32 %n) {
1011
; CHECK-NEXT: tail call void @print(i32 [[N]])
1112
; CHECK-NEXT: ret i8* bitcast (i8* (i8*, i1)* @f.resume.0 to i8*)
1213
;
14+
; CORO-LABEL: @f(
15+
; CORO-NEXT: entry:
16+
; CORO-NEXT: [[FRAMEPTR:%.*]] = bitcast i8* [[BUFFER:%.*]] to %f.Frame*
17+
; CORO-NEXT: [[N_VAL_SPILL_ADDR:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], %f.Frame* [[FRAMEPTR]], i32 0, i32 0
18+
; CORO-NEXT: store i32 [[N:%.*]], i32* [[N_VAL_SPILL_ADDR]], align 4
19+
; CORO-NEXT: call void @print(i32 [[N]])
20+
; CORO-NEXT: [[TMP0:%.*]] = bitcast i8* (i8*, i1)* @f.resume.0 to i8*
21+
; CORO-NEXT: ret i8* [[TMP0]]
22+
;
1323
entry:
1424
%id = call token @llvm.coro.id.retcon(i32 8, i32 4, i8* %buffer, i8* bitcast (i8* (i8*, i1)* @prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
1525
%hdl = call i8* @llvm.coro.begin(token %id, i8* null)
@@ -35,11 +45,24 @@ cleanup:
3545
define i32 @main() {
3646
; CHECK-LABEL: @main(
3747
; CHECK-NEXT: entry:
38-
; CHECK-NEXT: call void @print(i32 4)
39-
; CHECK-NEXT: call void @print(i32 5), !noalias !0
40-
; CHECK-NEXT: call void @print(i32 6), !noalias !3
48+
; CHECK-NEXT: tail call void @print(i32 4)
49+
; CHECK-NEXT: tail call void @print(i32 5), !noalias !0
50+
; CHECK-NEXT: tail call void @print(i32 6), !noalias !3
4151
; CHECK-NEXT: ret i32 0
4252
;
53+
; CORO-LABEL: @main(
54+
; CORO-NEXT: entry:
55+
; CORO-NEXT: [[TMP0:%.*]] = alloca [8 x i8], align 4
56+
; CORO-NEXT: [[BUFFER:%.*]] = bitcast [8 x i8]* [[TMP0]] to i8*
57+
; CORO-NEXT: [[CONT0:%.*]] = call i8* @f(i8* [[BUFFER]], i32 4)
58+
; CORO-NEXT: [[CONT0_CAST:%.*]] = bitcast i8* [[CONT0]] to i8* (i8*, i1)*
59+
; CORO-NEXT: [[CONT1:%.*]] = call i8* [[CONT0_CAST]](i8* [[BUFFER]], i1 zeroext false)
60+
; CORO-NEXT: [[CONT1_CAST:%.*]] = bitcast i8* [[CONT1]] to i8* (i8*, i1)*
61+
; CORO-NEXT: [[CONT2:%.*]] = call i8* [[CONT1_CAST]](i8* [[BUFFER]], i1 zeroext false)
62+
; CORO-NEXT: [[CONT2_CAST:%.*]] = bitcast i8* [[CONT2]] to i8* (i8*, i1)*
63+
; CORO-NEXT: [[TMP1:%.*]] = call i8* [[CONT2_CAST]](i8* [[BUFFER]], i1 zeroext true)
64+
; CORO-NEXT: ret i32 0
65+
;
4366
entry:
4467
%0 = alloca [8 x i8], align 4
4568
%buffer = bitcast [8 x i8]* %0 to i8*
@@ -70,6 +93,22 @@ define hidden { i8*, i8* } @g(i8* %buffer, i16* %ptr) {
7093
; CHECK-NEXT: [[TMP3:%.*]] = insertvalue { i8*, i8* } { i8* bitcast ({ i8*, i8* } (i8*, i1)* @g.resume.0 to i8*), i8* undef }, i8* [[TMP2]], 1
7194
; CHECK-NEXT: ret { i8*, i8* } [[TMP3]]
7295
;
96+
; CORO-LABEL: @g(
97+
; CORO-NEXT: entry:
98+
; CORO-NEXT: [[TMP0:%.*]] = call i8* @allocate(i32 8)
99+
; CORO-NEXT: [[TMP1:%.*]] = bitcast i8* [[BUFFER:%.*]] to i8**
100+
; CORO-NEXT: store i8* [[TMP0]], i8** [[TMP1]], align 8
101+
; CORO-NEXT: [[FRAMEPTR:%.*]] = bitcast i8* [[TMP0]] to %g.Frame*
102+
; CORO-NEXT: [[PTR_SPILL_ADDR:%.*]] = getelementptr inbounds [[G_FRAME:%.*]], %g.Frame* [[FRAMEPTR]], i32 0, i32 0
103+
; CORO-NEXT: store i16* [[PTR:%.*]], i16** [[PTR_SPILL_ADDR]], align 8
104+
; CORO-NEXT: [[PTR_RELOAD_ADDR:%.*]] = getelementptr inbounds [[G_FRAME]], %g.Frame* [[FRAMEPTR]], i32 0, i32 0
105+
; CORO-NEXT: [[PTR_RELOAD:%.*]] = load i16*, i16** [[PTR_RELOAD_ADDR]], align 8
106+
; CORO-NEXT: [[PTR2:%.*]] = bitcast i16* [[PTR_RELOAD]] to i8*
107+
; CORO-NEXT: [[TMP2:%.*]] = bitcast { i8*, i8* } (i8*, i1)* @g.resume.0 to i8*
108+
; CORO-NEXT: [[TMP3:%.*]] = insertvalue { i8*, i8* } undef, i8* [[TMP2]], 0
109+
; CORO-NEXT: [[TMP4:%.*]] = insertvalue { i8*, i8* } [[TMP3]], i8* [[PTR2]], 1
110+
; CORO-NEXT: ret { i8*, i8* } [[TMP4]]
111+
;
73112
entry:
74113
%id = call token @llvm.coro.id.retcon(i32 8, i32 4, i8* %buffer, i8* bitcast ({ i8*, i8* } (i8*, i1)* @g_prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
75114
%hdl = call i8* @llvm.coro.begin(token %id, i8* null)
@@ -88,12 +127,45 @@ cleanup:
88127
unreachable
89128
}
90129

130+
define i8* @nosuspend(i8* %buffer, i32 %n) {
131+
; CHECK-LABEL: @nosuspend(
132+
; CHECK-NEXT: entry:
133+
; CHECK-NEXT: unreachable
134+
;
135+
; CORO-LABEL: @nosuspend(
136+
; CORO-NEXT: entry:
137+
; CORO-NEXT: [[FRAMEPTR:%.*]] = bitcast i8* undef to %nosuspend.Frame*
138+
; CORO-NEXT: [[A:%.*]] = getelementptr inbounds [[NOSUSPEND_FRAME:%.*]], %nosuspend.Frame* [[FRAMEPTR]], i32 0, i32 0
139+
; CORO-NEXT: store i32 [[N:%.*]], i32* [[A]], align 4
140+
; CORO-NEXT: call void @use_var_ptr(i32* [[A]])
141+
; CORO-NEXT: [[AL:%.*]] = load i32, i32* [[A]], align 4
142+
; CORO-NEXT: call void @use_var(i32 [[AL]])
143+
; CORO-NEXT: ret i8* null
144+
;
145+
entry:
146+
%id = call token @llvm.coro.id.retcon(i32 8, i32 4, i8* %buffer, i8* bitcast (i8* (i8*, i1)* @prototype to i8*), i8* bitcast (i8* (i32)* @allocate to i8*), i8* bitcast (void (i8*)* @deallocate to i8*))
147+
%hdl = call i8* @llvm.coro.begin(token %id, i8* null)
148+
%a = alloca i32
149+
store i32 %n, i32* %a
150+
br label %cleanup
151+
152+
cleanup:
153+
call void @use_var_ptr(i32* %a)
154+
%al = load i32, i32* %a
155+
call void @use_var(i32 %al)
156+
call i1 @llvm.coro.end(i8* %hdl, i1 0)
157+
ret i8* %hdl
158+
}
159+
91160
declare token @llvm.coro.id.retcon(i32, i32, i8*, i8*, i8*, i8*)
92161
declare i8* @llvm.coro.begin(token, i8*)
93162
declare i1 @llvm.coro.suspend.retcon.i1(...)
94163
declare i1 @llvm.coro.end(i8*, i1)
95164
declare i8* @llvm.coro.prepare.retcon(i8*)
96165

166+
declare void @use_var(i32)
167+
declare void @use_var_ptr(i32*)
168+
97169
declare i8* @prototype(i8*, i1 zeroext)
98170
declare {i8*,i8*} @g_prototype(i8*, i1 zeroext)
99171

0 commit comments

Comments
 (0)