Skip to content

Commit 1c05ba5

Browse files
Merge pull request #3140 from aschwaighofer/fix_coro_rematerialization
[coro] Correct CurrentBlock tracking bug recently introduced
2 parents 785b460 + 7b2661c commit 1c05ba5

File tree

2 files changed

+142
-5
lines changed

2 files changed

+142
-5
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,14 +1984,15 @@ static void rewriteMaterializableInstructions(IRBuilder<> &IRB,
19841984
if (CurrentBlock != U->getParent()) {
19851985

19861986
bool IsInCoroSuspendBlock = isa<AnyCoroSuspendInst>(U);
1987-
CurrentBlock = IsInCoroSuspendBlock
1988-
? U->getParent()->getSinglePredecessor()
1989-
: U->getParent();
1987+
CurrentBlock = U->getParent();
1988+
auto InsertBlock = IsInCoroSuspendBlock
1989+
? CurrentBlock->getSinglePredecessor()
1990+
: CurrentBlock;
19901991
CurrentMaterialization = cast<Instruction>(Def)->clone();
19911992
CurrentMaterialization->setName(Def->getName());
19921993
CurrentMaterialization->insertBefore(
1993-
IsInCoroSuspendBlock ? CurrentBlock->getTerminator()
1994-
: &*CurrentBlock->getFirstInsertionPt());
1994+
IsInCoroSuspendBlock ? InsertBlock->getTerminator()
1995+
: &*InsertBlock->getFirstInsertionPt());
19951996
}
19961997
if (auto *PN = dyn_cast<PHINode>(U)) {
19971998
assert(PN->getNumIncomingValues() == 1 &&
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
; RUN: opt < %s -enable-coroutines -O0 -S
2+
3+
%async_func_ptr = type <{ i32, i32 }>
4+
%Tsq = type <{}>
5+
%swift.context = type { %swift.context*, void (%swift.context*)*, i64 }
6+
%swift.type = type { i64 }
7+
%FlatMapSeq = type <{}>
8+
%swift.error = type opaque
9+
%swift.opaque = type opaque
10+
11+
@repoTU = global %async_func_ptr <{ i32 trunc (i64 sub (i64 ptrtoint (void (%Tsq*, %swift.context*, %swift.type*, %FlatMapSeq*)* @repo to i64), i64 ptrtoint (%async_func_ptr* @repoTU to i64)) to i32), i32 20 }>, section "__TEXT,__const", align 8
12+
13+
; Function Attrs: nounwind
14+
declare token @llvm.coro.id.async(i32, i32, i32, i8*) #0
15+
16+
; Function Attrs: nounwind
17+
declare i8* @llvm.coro.begin(token, i8* writeonly) #0
18+
19+
; Function Attrs: nounwind
20+
declare i8* @llvm.coro.async.resume() #0
21+
22+
define hidden i8* @__swift_async_resume_project_context(i8* %0) {
23+
entry:
24+
ret i8* undef
25+
}
26+
27+
define swifttailcc void @repo(%Tsq* %0, %swift.context* %1, %swift.type* %arg, %FlatMapSeq* %2) #1 {
28+
entry:
29+
%swifterror = alloca swifterror %swift.error*, align 8
30+
%3 = call token @llvm.coro.id.async(i32 20, i32 16, i32 1, i8* bitcast (%async_func_ptr* @repoTU to i8*))
31+
%4 = call i8* @llvm.coro.begin(token %3, i8* null)
32+
%5 = bitcast i8* undef to %swift.opaque*
33+
br label %6
34+
35+
6: ; preds = %21, %15, %entry
36+
br i1 undef, label %7, label %23
37+
38+
7: ; preds = %6
39+
br i1 undef, label %8, label %16
40+
41+
8: ; preds = %7
42+
%initializeWithTake35 = bitcast i8* undef to %swift.opaque* (%swift.opaque*, %swift.opaque*, %swift.type*)*
43+
%9 = call %swift.opaque* %initializeWithTake35(%swift.opaque* noalias %5, %swift.opaque* noalias undef, %swift.type* undef) #0
44+
%10 = call i8* @llvm.coro.async.resume()
45+
%11 = bitcast i8* %10 to void (%swift.context*)*
46+
%12 = call { i8*, %swift.error* } (i32, i8*, i8*, ...) @llvm.coro.suspend.async.sl_p0i8p0s_swift.error.4.220.413.429.445.461.672.683ss(i32 256, i8* %10, i8* bitcast (i8* (i8*)* @__swift_async_resume_project_context to i8*), i8* bitcast (void (i8*, %Tsq*, %swift.context*, %swift.opaque*, %swift.type*, i8**)* @__swift_suspend_dispatch_5.23 to i8*), i8* undef, %Tsq* undef, %swift.context* undef, %swift.opaque* %5, %swift.type* undef, i8** undef)
47+
br i1 undef, label %25, label %13
48+
49+
13: ; preds = %8
50+
br i1 undef, label %14, label %15
51+
52+
14: ; preds = %13
53+
br label %24
54+
55+
15: ; preds = %13
56+
br label %6
57+
58+
16: ; preds = %7
59+
br i1 undef, label %26, label %17
60+
61+
17: ; preds = %16
62+
br i1 undef, label %18, label %22
63+
64+
18: ; preds = %17
65+
br i1 undef, label %27, label %19
66+
67+
19: ; preds = %18
68+
br i1 undef, label %20, label %21
69+
70+
20: ; preds = %19
71+
br label %24
72+
73+
21: ; preds = %19
74+
br label %6
75+
76+
22: ; preds = %17
77+
br label %24
78+
79+
23: ; preds = %6
80+
br label %24
81+
82+
24: ; preds = %23, %22, %20, %14
83+
unreachable
84+
85+
25: ; preds = %8
86+
br label %28
87+
88+
26: ; preds = %16
89+
br label %28
90+
91+
27: ; preds = %18
92+
br label %28
93+
94+
28: ; preds = %27, %26, %25
95+
unreachable
96+
}
97+
98+
define dso_local swifttailcc void @__swift_suspend_dispatch_2.18() {
99+
entry:
100+
ret void
101+
}
102+
103+
define dso_local swifttailcc void @__swift_suspend_dispatch_5.19() {
104+
entry:
105+
ret void
106+
}
107+
108+
define dso_local swifttailcc void @__swift_suspend_dispatch_2.20() {
109+
entry:
110+
ret void
111+
}
112+
113+
define dso_local swifttailcc void @__swift_suspend_dispatch_4.21() {
114+
entry:
115+
ret void
116+
}
117+
118+
define dso_local swifttailcc void @__swift_suspend_dispatch_5.22() {
119+
entry:
120+
ret void
121+
}
122+
123+
define dso_local swifttailcc void @__swift_suspend_dispatch_5.23(i8* %0, %Tsq* %1, %swift.context* %2, %swift.opaque* %3, %swift.type* %4, i8** %5) {
124+
entry:
125+
ret void
126+
}
127+
128+
; Function Attrs: nounwind
129+
declare { i8*, %swift.error* } @llvm.coro.suspend.async.sl_p0i8p0s_swift.error.4.220.413.429.445.461.672.683ss(i32, i8*, i8*, ...) #0
130+
131+
attributes #0 = { nounwind }
132+
attributes #1 = { "tune-cpu"="generic" }
133+
134+
!llvm.linker.options = !{!0}
135+
136+
!0 = !{!"-lobjc"}

0 commit comments

Comments
 (0)