diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc --- a/flang/include/flang/Tools/CLOptions.inc +++ b/flang/include/flang/Tools/CLOptions.inc @@ -154,10 +154,12 @@ // simplify the IR mlir::GreedyRewriteConfig config; config.enableRegionSimplification = false; + pm.addPass(mlir::createCSEPass()); fir::addAVC(pm); pm.addNestedPass(fir::createCharacterConversionPass()); pm.addPass(mlir::createCanonicalizerPass(config)); pm.addPass(fir::createSimplifyRegionLitePass()); + pm.addPass(mlir::createCSEPass()); fir::addMemoryAllocationOpt(pm); // The default inliner pass adds the canonicalizer pass with the default @@ -173,6 +175,7 @@ pm.addPass(mlir::createCanonicalizerPass(config)); pm.addPass(fir::createSimplifyRegionLitePass()); + pm.addPass(mlir::createCSEPass()); } #if !defined(FLANG_EXCLUDE_CODEGEN) diff --git a/flang/test/Driver/mlir-pass-pipeline.f90 b/flang/test/Driver/mlir-pass-pipeline.f90 --- a/flang/test/Driver/mlir-pass-pipeline.f90 +++ b/flang/test/Driver/mlir-pass-pipeline.f90 @@ -5,11 +5,13 @@ ! CHECK: Pass statistics report +! CHECK: CSE ! CHECK-LABEL: 'func.func' Pipeline ! CHECK: ArrayValueCopy ! CHECK: CharacterConversion ! CHECK: Canonicalizer ! CHECK: SimplifyRegionLite +! CHECK: CSE ! CHECK-LABEL: 'func.func' Pipeline ! CHECK: MemoryAllocationOpt @@ -21,6 +23,7 @@ ! CHECK: SCFToControlFlow ! CHECK: Canonicalizer ! CHECK: SimplifyRegionLite +! CHECK: CSE ! CHECK: BoxedProcedurePass ! CHECK-LABEL: 'func.func' Pipeline diff --git a/flang/test/Fir/basic-program.fir b/flang/test/Fir/basic-program.fir --- a/flang/test/Fir/basic-program.fir +++ b/flang/test/Fir/basic-program.fir @@ -14,11 +14,13 @@ // PASSES: Pass statistics report +// PASSES: CSE // PASSES-LABEL: 'func.func' Pipeline // PASSES: ArrayValueCopy // PASSES: CharacterConversion // PASSES: Canonicalizer // PASSES: SimplifyRegionLite +// PASSES: CSE // PASSES-LABEL: 'func.func' Pipeline // PASSES: MemoryAllocationOpt @@ -30,6 +32,7 @@ // PASSES: SCFToControlFlow // PASSES: Canonicalizer // PASSES: SimplifyRegionLite +// PASSES: CSE // PASSES: BoxedProcedurePass // PASSES-LABEL: 'func.func' Pipeline