Skip to content

Commit 7d40f56

Browse files
committed
[Pipelines] Hoist CoroCleanup to avoid blocking optimizations
CoroCleanup is designed to lowering all the remaining coroutine intrinsics. It is required to run after CoroSplit only. However, the position of CoroCleanup now is far too late. The downside here is that the unlowered coroutine instrincs might blocking other optimizations too. So it should be a pure win to hoist the position of CoroCleanup. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D124360
1 parent 6c10014 commit 7d40f56

11 files changed

+23
-61
lines changed

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,8 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
989989
else
990990
MPM.addPass(buildInlinerPipeline(Level, Phase));
991991

992+
MPM.addPass(createModuleToFunctionPassAdaptor(CoroCleanupPass()));
993+
992994
if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
993995
MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
994996
MPM.addPass(ModuleMemProfilerPass());
@@ -1246,8 +1248,6 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
12461248
OptimizePM.addPass(
12471249
SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
12481250

1249-
OptimizePM.addPass(CoroCleanupPass());
1250-
12511251
// Add the core optimizing pipeline.
12521252
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(OptimizePM),
12531253
PTO.EagerlyInvalidateAnalyses));
@@ -1372,11 +1372,6 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
13721372
// Reduce the size of the IR as much as possible.
13731373
MPM.addPass(GlobalOptPass());
13741374

1375-
// Module simplification splits coroutines, but does not fully clean up
1376-
// coroutine intrinsics. To ensure ThinLTO optimization passes don't trip up
1377-
// on these, we schedule the cleanup here.
1378-
MPM.addPass(createModuleToFunctionPassAdaptor(CoroCleanupPass()));
1379-
13801375
if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
13811376
PGOOpt->Action == PGOOptions::SampleUse)
13821377
MPM.addPass(PseudoProbeUpdatePass());

llvm/test/Other/new-pm-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
; CHECK-EP-PEEPHOLE-NEXT: Running pass: NoOpFunctionPass
216216
; CHECK-O-NEXT: Running pass: CoroSplitPass
217217
; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis
218+
; CHECK-O-NEXT: Running pass: CoroCleanupPass
218219
; CHECK-O-NEXT: Running pass: GlobalOptPass
219220
; CHECK-O-NEXT: Running pass: GlobalDCEPass
220221
; CHECK-DEFAULT-NEXT: Running pass: EliminateAvailableExternallyPass
@@ -259,7 +260,6 @@
259260
; CHECK-O-NEXT: Running pass: InstSimplifyPass
260261
; CHECK-O-NEXT: Running pass: DivRemPairsPass
261262
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
262-
; CHECK-O-NEXT: Running pass: CoroCleanupPass
263263
; CHECK-EP-OPTIMIZER-LAST: Running pass: NoOpModulePass
264264
; CHECK-HOT-COLD-SPLIT-NEXT: Running pass: HotColdSplittingPass
265265
; CHECK-IR-OUTLINER-NEXT: Running pass: IROutlinerPass

llvm/test/Other/new-pm-thinlto-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@
184184
; CHECK-O-NEXT: Running pass: InstCombinePass
185185
; CHECK-O-NEXT: Running pass: CoroSplitPass
186186
; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis
187+
; CHECK-O-NEXT: Running pass: CoroCleanupPass
187188
; CHECK-PRELINK-O-NEXT: Running pass: GlobalOptPass
188189
; CHECK-POSTLINK-O-NEXT: Running pass: GlobalOptPass
189190
; CHECK-POSTLINK-O-NEXT: Running pass: GlobalDCEPass
@@ -223,7 +224,6 @@
223224
; CHECK-POSTLINK-O-NEXT: Running pass: InstSimplifyPass
224225
; CHECK-POSTLINK-O-NEXT: Running pass: DivRemPairsPass
225226
; CHECK-POSTLINK-O-NEXT: Running pass: SimplifyCFGPass
226-
; CHECK-O-NEXT: Running pass: CoroCleanupPass
227227
; CHECK-POSTLINK-O-NEXT: Running pass: CGProfilePass
228228
; CHECK-POSTLINK-O-NEXT: Running pass: GlobalDCEPass
229229
; CHECK-POSTLINK-O-NEXT: Running pass: ConstantMergePass

llvm/test/Other/new-pm-thinlto-postlink-pgo-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
; CHECK-O-NEXT: Running pass: InstCombinePass
157157
; CHECK-O-NEXT: Running pass: CoroSplitPass
158158
; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis
159+
; CHECK-O-NEXT: Running pass: CoroCleanupPass
159160
; CHECK-O-NEXT: Running pass: GlobalOptPass
160161
; CHECK-O-NEXT: Running pass: GlobalDCEPass
161162
; CHECK-O-NEXT: Running pass: EliminateAvailableExternallyPass
@@ -192,7 +193,6 @@
192193
; CHECK-O-NEXT: Running pass: InstSimplifyPass
193194
; CHECK-O-NEXT: Running pass: DivRemPairsPass
194195
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
195-
; CHECK-O-NEXT: Running pass: CoroCleanupPass
196196
; CHECK-O-NEXT: Running pass: CGProfilePass
197197
; CHECK-O-NEXT: Running pass: GlobalDCEPass
198198
; CHECK-O-NEXT: Running pass: ConstantMergePass

llvm/test/Other/new-pm-thinlto-postlink-samplepgo-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
; CHECK-O3-NEXT: Running analysis: DominanceFrontierAnalysis on foo
169169
; CHECK-O-NEXT: Running pass: CoroSplitPass
170170
; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis
171+
; CHECK-O-NEXT: Running pass: CoroCleanupPass
171172
; CHECK-O-NEXT: Running pass: GlobalOptPass
172173
; CHECK-O-NEXT: Running pass: GlobalDCEPass
173174
; CHECK-O-NEXT: Running pass: EliminateAvailableExternallyPass
@@ -204,7 +205,6 @@
204205
; CHECK-O-NEXT: Running pass: InstSimplifyPass
205206
; CHECK-O-NEXT: Running pass: DivRemPairsPass
206207
; CHECK-O-NEXT: Running pass: SimplifyCFGPass
207-
; CHECK-O-NEXT: Running pass: CoroCleanupPass
208208
; CHECK-O-NEXT: Running pass: CGProfilePass
209209
; CHECK-O-NEXT: Running pass: GlobalDCEPass
210210
; CHECK-O-NEXT: Running pass: ConstantMergePass

llvm/test/Other/new-pm-thinlto-prelink-pgo-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@
197197
; CHECK-O3-NEXT: Running analysis: DominanceFrontierAnalysis on foo
198198
; CHECK-O-NEXT: Running pass: CoroSplitPass
199199
; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis
200+
; CHECK-O-NEXT: Running pass: CoroCleanupPass
200201
; CHECK-O-NEXT: Running pass: GlobalOptPass
201202
; CHECK-O-NEXT: Running analysis: TargetLibraryAnalysis on bar
202203
; CHECK-EXT: Running pass: {{.*}}::Bye
203-
; CHECK-O-NEXT: Running pass: CoroCleanupPass
204204
; CHECK-O-NEXT: Running pass: AnnotationRemarksPass on foo
205205
; CHECK-O-NEXT: Running pass: CanonicalizeAliasesPass
206206
; CHECK-O-NEXT: Running pass: NameAnonGlobalPass

llvm/test/Other/new-pm-thinlto-prelink-samplepgo-defaults.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@
162162
; CHECK-O3-NEXT: Running analysis: DominanceFrontierAnalysis on foo
163163
; CHECK-O-NEXT: Running pass: CoroSplitPass
164164
; CHECK-O-NEXT: Invalidating analysis: InlineAdvisorAnalysis
165-
; CHECK-O-NEXT: Running pass: GlobalOptPass
166165
; CHECK-O-NEXT: Running pass: CoroCleanupPass
166+
; CHECK-O-NEXT: Running pass: GlobalOptPass
167167
; CHECK-O-NEXT: Running pass: AnnotationRemarksPass on foo
168168
; CHECK-O-NEXT: Running pass: CanonicalizeAliasesPass
169169
; CHECK-O-NEXT: Running pass: NameAnonGlobalPass

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,9 @@ cleanup: ; preds = %loop
3333
define i32 @main() {
3434
; CHECK-LABEL: @main(
3535
; CHECK-NEXT: entry:
36-
; CHECK-NEXT: [[TMP0:%.*]] = alloca [8 x i8], align 4
37-
; CHECK-NEXT: store i32 4, ptr [[TMP0]], align 4
3836
; CHECK-NEXT: call void @print(i32 4)
39-
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META0:![0-9]+]])
40-
; CHECK-NEXT: [[N_VAL_RELOAD_I:%.*]] = load i32, ptr [[TMP0]], align 4, !alias.scope !0
41-
; CHECK-NEXT: [[INC_I:%.*]] = add i32 [[N_VAL_RELOAD_I]], 1
42-
; CHECK-NEXT: store i32 [[INC_I]], ptr [[TMP0]], align 4, !alias.scope !0
43-
; CHECK-NEXT: call void @print(i32 [[INC_I]]), !noalias !0
44-
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META3:![0-9]+]])
45-
; CHECK-NEXT: [[N_VAL_RELOAD_I1:%.*]] = load i32, ptr [[TMP0]], align 4, !alias.scope !3
46-
; CHECK-NEXT: [[INC_I2:%.*]] = add i32 [[N_VAL_RELOAD_I1]], 1
47-
; CHECK-NEXT: call void @print(i32 [[INC_I2]]), !noalias !3
37+
; CHECK-NEXT: call void @print(i32 5), !noalias !0
38+
; CHECK-NEXT: call void @print(i32 6), !noalias !3
4839
; CHECK-NEXT: ret i32 0
4940
;
5041
entry:

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,20 @@ define i32 @main() {
3939
; CHECK-LABEL: @main(
4040
; CHECK-NEXT: entry:
4141
; CHECK-NEXT: [[TMP0:%.*]] = alloca i8*, align 8
42-
; CHECK-NEXT: [[DOTSUB:%.*]] = bitcast i8** [[TMP0]] to i8*
4342
; CHECK-NEXT: [[TMP1:%.*]] = tail call i8* @allocate(i32 12)
4443
; CHECK-NEXT: store i8* [[TMP1]], i8** [[TMP0]], align 8
4544
; CHECK-NEXT: [[N_SPILL_ADDR_I:%.*]] = bitcast i8* [[TMP1]] to i32*
4645
; CHECK-NEXT: store i32 1, i32* [[N_SPILL_ADDR_I]], align 4
47-
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META0:![0-9]+]])
4846
; CHECK-NEXT: [[TMP2:%.*]] = bitcast i8** [[TMP0]] to %f.Frame**
49-
; CHECK-NEXT: [[FRAMEPTR_I:%.*]] = load %f.Frame*, %f.Frame** [[TMP2]], align 8, !alias.scope !0
50-
; CHECK-NEXT: [[N_RELOAD_ADDR_I:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], %f.Frame* [[FRAMEPTR_I]], i64 0, i32 0
51-
; CHECK-NEXT: [[N_RELOAD_I:%.*]] = load i32, i32* [[N_RELOAD_ADDR_I]], align 4, !noalias !0
52-
; CHECK-NEXT: [[N_VAL3_SPILL_ADDR_I:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR_I]], i64 0, i32 1
53-
; CHECK-NEXT: store i32 [[N_RELOAD_I]], i32* [[N_VAL3_SPILL_ADDR_I]], align 4, !noalias !0
54-
; CHECK-NEXT: [[INPUT_SPILL_ADDR_I:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR_I]], i64 0, i32 2
55-
; CHECK-NEXT: store i32 2, i32* [[INPUT_SPILL_ADDR_I]], align 4, !noalias !0
47+
; CHECK-NEXT: [[N_VAL3_SPILL_ADDR_I:%.*]] = getelementptr inbounds i8, i8* [[TMP1]], i64 4
48+
; CHECK-NEXT: [[TMP3:%.*]] = bitcast i8* [[N_VAL3_SPILL_ADDR_I]] to i32*
49+
; CHECK-NEXT: store i32 1, i32* [[TMP3]], align 4, !noalias !0
50+
; CHECK-NEXT: [[INPUT_SPILL_ADDR_I:%.*]] = getelementptr inbounds i8, i8* [[TMP1]], i64 8
51+
; CHECK-NEXT: [[TMP4:%.*]] = bitcast i8* [[INPUT_SPILL_ADDR_I]] to i32*
52+
; CHECK-NEXT: store i32 2, i32* [[TMP4]], align 4, !noalias !0
5653
; CHECK-NEXT: call void @llvm.experimental.noalias.scope.decl(metadata [[META3:![0-9]+]])
5754
; CHECK-NEXT: [[FRAMEPTR_I1:%.*]] = load %f.Frame*, %f.Frame** [[TMP2]], align 8, !alias.scope !3
58-
; CHECK-NEXT: [[INPUT_RELOAD_ADDR13_I:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR_I1]], i64 0, i32 2
55+
; CHECK-NEXT: [[INPUT_RELOAD_ADDR13_I:%.*]] = getelementptr inbounds [[F_FRAME:%.*]], %f.Frame* [[FRAMEPTR_I1]], i64 0, i32 2
5956
; CHECK-NEXT: [[INPUT_RELOAD14_I:%.*]] = load i32, i32* [[INPUT_RELOAD_ADDR13_I]], align 4, !noalias !3
6057
; CHECK-NEXT: [[N_VAL3_RELOAD_ADDR11_I:%.*]] = getelementptr inbounds [[F_FRAME]], %f.Frame* [[FRAMEPTR_I1]], i64 0, i32 1
6158
; CHECK-NEXT: [[N_VAL3_RELOAD12_I:%.*]] = load i32, i32* [[N_VAL3_RELOAD_ADDR11_I]], align 4, !noalias !3
@@ -70,8 +67,8 @@ define i32 @main() {
7067
; CHECK-NEXT: [[N_VAL3_RELOAD12_I6:%.*]] = load i32, i32* [[N_VAL3_RELOAD_ADDR11_I5]], align 4, !noalias !6
7168
; CHECK-NEXT: [[SUM7_I7:%.*]] = add i32 [[N_VAL3_RELOAD12_I6]], [[INPUT_RELOAD14_I4]]
7269
; CHECK-NEXT: call void @print(i32 [[SUM7_I7]]), !noalias !6
73-
; CHECK-NEXT: [[TMP3:%.*]] = bitcast %f.Frame* [[FRAMEPTR_I2]] to i8*
74-
; CHECK-NEXT: call void @deallocate(i8* [[TMP3]]), !noalias !6
70+
; CHECK-NEXT: [[TMP5:%.*]] = bitcast %f.Frame* [[FRAMEPTR_I2]] to i8*
71+
; CHECK-NEXT: call void @deallocate(i8* [[TMP5]]), !noalias !6
7572
; CHECK-NEXT: ret i32 0
7673
;
7774
entry:

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,9 @@ cleanup:
3535
define i32 @main() {
3636
; CHECK-LABEL: @main(
3737
; CHECK-NEXT: entry:
38-
; CHECK-NEXT: [[TMP0:%.*]] = alloca [8 x i8], align 4
39-
; CHECK-NEXT: [[DOTSUB:%.*]] = getelementptr inbounds [8 x i8], [8 x i8]* [[TMP0]], i64 0, i64 0
40-
; CHECK-NEXT: [[N_VAL_SPILL_ADDR_I:%.*]] = bitcast [8 x i8]* [[TMP0]] to i32*
41-
; CHECK-NEXT: store i32 4, i32* [[N_VAL_SPILL_ADDR_I]], align 4
4238
; CHECK-NEXT: call void @print(i32 4)
43-
; CHECK-NEXT: [[N_VAL_RELOAD_I:%.*]] = load i32, i32* [[N_VAL_SPILL_ADDR_I]], align 4, !alias.scope !0
44-
; CHECK-NEXT: [[INC_I:%.*]] = add i32 [[N_VAL_RELOAD_I]], 1
45-
; CHECK-NEXT: store i32 [[INC_I]], i32* [[N_VAL_SPILL_ADDR_I]], align 4, !alias.scope !0
46-
; CHECK-NEXT: call void @print(i32 [[INC_I]])
47-
; CHECK-NEXT: [[N_VAL_RELOAD_I3:%.*]] = load i32, i32* [[N_VAL_SPILL_ADDR_I]], align 4, !alias.scope !3
48-
; CHECK-NEXT: [[INC_I4:%.*]] = add i32 [[N_VAL_RELOAD_I3]], 1
49-
; CHECK-NEXT: store i32 [[INC_I4]], i32* [[N_VAL_SPILL_ADDR_I]], align 4, !alias.scope !3
50-
; CHECK-NEXT: call void @print(i32 [[INC_I4]])
39+
; CHECK-NEXT: call void @print(i32 5)
40+
; CHECK-NEXT: call void @print(i32 6)
5141
; CHECK-NEXT: ret i32 0
5242
;
5343
entry:

0 commit comments

Comments
 (0)