Skip to content

Commit 611c96a

Browse files
authored
[flang] Schedule InlineHLFIRAssign after BufferizeHLFIR. (#121863)
This helps to get rid of *some* calls to AssignTemporary runtime that are appearing due to temporary_lhs hlfir.assign produced in BufferizeHLFIR. I only tested it on `tonto`, and did not see any performance changes. I will run more performance testing before merging this.
1 parent 9374453 commit 611c96a

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

flang/lib/Optimizer/Passes/Pipelines.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,16 @@ void createHLFIRToFIRPassPipeline(mlir::PassManager &pm, bool enableOpenMP,
240240
pm.addPass(hlfir::createLowerHLFIROrderedAssignments());
241241
pm.addPass(hlfir::createLowerHLFIRIntrinsics());
242242
pm.addPass(hlfir::createBufferizeHLFIR());
243+
// Run hlfir.assign inlining again after BufferizeHLFIR,
244+
// because the latter may introduce new hlfir.assign operations,
245+
// e.g. for copying an array into a temporary due to
246+
// hlfir.associate.
247+
// TODO: we can remove the previous InlineHLFIRAssign, when
248+
// FIR AliasAnalysis is good enough to say that a temporary
249+
// array does not alias with any user object.
250+
if (optLevel.isOptimizingForSpeed())
251+
addNestedPassToAllTopLevelOperations<PassConstructor>(
252+
pm, hlfir::createInlineHLFIRAssign);
243253
pm.addPass(hlfir::createConvertHLFIRtoFIR());
244254
if (enableOpenMP)
245255
pm.addPass(flangomp::createLowerWorkshare());

flang/test/Driver/mlir-pass-pipeline.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@
4949
! ALL: LowerHLFIROrderedAssignments
5050
! ALL-NEXT: LowerHLFIRIntrinsics
5151
! ALL-NEXT: BufferizeHLFIR
52+
! O2-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
53+
! O2-NEXT: 'fir.global' Pipeline
54+
! O2-NEXT: InlineHLFIRAssign
55+
! O2-NEXT: 'func.func' Pipeline
56+
! O2-NEXT: InlineHLFIRAssign
57+
! O2-NEXT: 'omp.declare_reduction' Pipeline
58+
! O2-NEXT: InlineHLFIRAssign
59+
! O2-NEXT: 'omp.private' Pipeline
60+
! O2-NEXT: InlineHLFIRAssign
5261
! ALL-NEXT: ConvertHLFIRtoFIR
5362
! ALL-NEXT: CSE
5463
! Ideally, we need an output with only the pass names, but

flang/test/Fir/basic-program.fir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ func.func @_QQmain() {
5050
// PASSES-NEXT: LowerHLFIROrderedAssignments
5151
// PASSES-NEXT: LowerHLFIRIntrinsics
5252
// PASSES-NEXT: BufferizeHLFIR
53+
// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
54+
// PASSES-NEXT: 'fir.global' Pipeline
55+
// PASSES-NEXT: InlineHLFIRAssign
56+
// PASSES-NEXT: 'func.func' Pipeline
57+
// PASSES-NEXT: InlineHLFIRAssign
58+
// PASSES-NEXT: 'omp.declare_reduction' Pipeline
59+
// PASSES-NEXT: InlineHLFIRAssign
60+
// PASSES-NEXT: 'omp.private' Pipeline
61+
// PASSES-NEXT: InlineHLFIRAssign
5362
// PASSES-NEXT: ConvertHLFIRtoFIR
5463
// PASSES-NEXT: LowerWorkshare
5564
// PASSES-NEXT: CSE

0 commit comments

Comments
 (0)