diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp index 20e4599587c4b2..e1d7376ec3805d 100644 --- a/flang/lib/Optimizer/Passes/Pipelines.cpp +++ b/flang/lib/Optimizer/Passes/Pipelines.cpp @@ -240,6 +240,16 @@ void createHLFIRToFIRPassPipeline(mlir::PassManager &pm, bool enableOpenMP, pm.addPass(hlfir::createLowerHLFIROrderedAssignments()); pm.addPass(hlfir::createLowerHLFIRIntrinsics()); pm.addPass(hlfir::createBufferizeHLFIR()); + // Run hlfir.assign inlining again after BufferizeHLFIR, + // because the latter may introduce new hlfir.assign operations, + // e.g. for copying an array into a temporary due to + // hlfir.associate. + // TODO: we can remove the previous InlineHLFIRAssign, when + // FIR AliasAnalysis is good enough to say that a temporary + // array does not alias with any user object. + if (optLevel.isOptimizingForSpeed()) + addNestedPassToAllTopLevelOperations( + pm, hlfir::createInlineHLFIRAssign); pm.addPass(hlfir::createConvertHLFIRtoFIR()); if (enableOpenMP) pm.addPass(flangomp::createLowerWorkshare()); diff --git a/flang/test/Driver/mlir-pass-pipeline.f90 b/flang/test/Driver/mlir-pass-pipeline.f90 index 9655afce96d927..55e86da2dfdf14 100644 --- a/flang/test/Driver/mlir-pass-pipeline.f90 +++ b/flang/test/Driver/mlir-pass-pipeline.f90 @@ -49,6 +49,15 @@ ! ALL: LowerHLFIROrderedAssignments ! ALL-NEXT: LowerHLFIRIntrinsics ! ALL-NEXT: BufferizeHLFIR +! O2-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private'] +! O2-NEXT: 'fir.global' Pipeline +! O2-NEXT: InlineHLFIRAssign +! O2-NEXT: 'func.func' Pipeline +! O2-NEXT: InlineHLFIRAssign +! O2-NEXT: 'omp.declare_reduction' Pipeline +! O2-NEXT: InlineHLFIRAssign +! O2-NEXT: 'omp.private' Pipeline +! O2-NEXT: InlineHLFIRAssign ! ALL-NEXT: ConvertHLFIRtoFIR ! ALL-NEXT: CSE ! Ideally, we need an output with only the pass names, but diff --git a/flang/test/Fir/basic-program.fir b/flang/test/Fir/basic-program.fir index 620882ebbed2a9..29a0f661579710 100644 --- a/flang/test/Fir/basic-program.fir +++ b/flang/test/Fir/basic-program.fir @@ -50,6 +50,15 @@ func.func @_QQmain() { // PASSES-NEXT: LowerHLFIROrderedAssignments // PASSES-NEXT: LowerHLFIRIntrinsics // PASSES-NEXT: BufferizeHLFIR +// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private'] +// PASSES-NEXT: 'fir.global' Pipeline +// PASSES-NEXT: InlineHLFIRAssign +// PASSES-NEXT: 'func.func' Pipeline +// PASSES-NEXT: InlineHLFIRAssign +// PASSES-NEXT: 'omp.declare_reduction' Pipeline +// PASSES-NEXT: InlineHLFIRAssign +// PASSES-NEXT: 'omp.private' Pipeline +// PASSES-NEXT: InlineHLFIRAssign // PASSES-NEXT: ConvertHLFIRtoFIR // PASSES-NEXT: LowerWorkshare // PASSES-NEXT: CSE