[flang-commits] [flang] 244bd7c - [flang] Runs FIR SimplifyRegionLitePass pass after calling the inliner

Jean Perier via flang-commits flang-commits at lists.llvm.org
Mon Jul 25 10:40:49 PDT 2022


Author: Jean Perier
Date: 2022-07-25T19:38:59+02:00
New Revision: 244bd7cba7cba6abf889d594cc94355d958a9308

URL: https://github.com/llvm/llvm-project/commit/244bd7cba7cba6abf889d594cc94355d958a9308
DIFF: https://github.com/llvm/llvm-project/commit/244bd7cba7cba6abf889d594cc94355d958a9308.diff

LOG: [flang] Runs FIR SimplifyRegionLitePass pass after calling the inliner

In flang pipeline, the inliner calls createCanonicalizerPass with the region
simplification disabled. The inliner pass does canonicalization even if
no inlining happens. After canonicalization, FIR lite region simplification
must be called to get rid of unreachable regions.
This code exposes the need to run SimplifyRegionLitePass after the inliner is
called with FIR pipeline.

Differential Revision: https://reviews.llvm.org/D130484

Added: 
    flang/test/Fir/simplify-region-lite-after-inliner.fir

Modified: 
    flang/include/flang/Tools/CLOptions.inc
    flang/test/Driver/bbc-mlir-pass-pipeline.f90
    flang/test/Driver/mlir-pass-pipeline.f90
    flang/test/Fir/basic-program.fir

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc
index 6d5ed9cbee871..5cf89d79ffc85 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -176,6 +176,7 @@ inline void createDefaultFIROptimizerPassPipeline(
   llvm::StringMap<mlir::OpPassManager> pipelines;
   pm.addPass(
       mlir::createInlinerPass(pipelines, defaultFlangInlinerOptPipeline));
+  pm.addPass(fir::createSimplifyRegionLitePass());
   pm.addPass(mlir::createCSEPass());
 
   // convert control flow to CFG form

diff  --git a/flang/test/Driver/bbc-mlir-pass-pipeline.f90 b/flang/test/Driver/bbc-mlir-pass-pipeline.f90
index 45ff3ebfbc22a..388cc0574145d 100644
--- a/flang/test/Driver/bbc-mlir-pass-pipeline.f90
+++ b/flang/test/Driver/bbc-mlir-pass-pipeline.f90
@@ -32,6 +32,7 @@
 ! CHECK-NEXT:   MemoryAllocationOpt
 
 ! CHECK-NEXT: Inliner
+! CHECK-NEXT: SimplifyRegionLite
 ! CHECK-NEXT: CSE
 ! CHECK-NEXT:   (S) 0 num-cse'd - Number of operations CSE'd
 ! CHECK-NEXT:   (S) 0 num-dce'd - Number of operations DCE'd

diff  --git a/flang/test/Driver/mlir-pass-pipeline.f90 b/flang/test/Driver/mlir-pass-pipeline.f90
index 78104285db577..5d9f0ce32b795 100644
--- a/flang/test/Driver/mlir-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-pass-pipeline.f90
@@ -35,6 +35,7 @@
 ! ALL-NEXT:   MemoryAllocationOpt
 
 ! ALL-NEXT: Inliner
+! ALL-NEXT: SimplifyRegionLite
 ! ALL-NEXT: CSE
 ! ALL-NEXT:   (S) 0 num-cse'd - Number of operations CSE'd
 ! ALL-NEXT:   (S) 0 num-dce'd - Number of operations DCE'd

diff  --git a/flang/test/Fir/basic-program.fir b/flang/test/Fir/basic-program.fir
index 8d1aab12c9a0e..29efa845fafac 100644
--- a/flang/test/Fir/basic-program.fir
+++ b/flang/test/Fir/basic-program.fir
@@ -35,6 +35,7 @@ func.func @_QQmain() {
 // PASSES-NEXT:   MemoryAllocationOpt
 
 // PASSES-NEXT: Inliner
+// PASSES-NEXT: SimplifyRegionLite
 // PASSES-NEXT: CSE
 // PASSES-NEXT:   (S) 0 num-cse'd - Number of operations CSE'd
 // PASSES-NEXT:   (S) 0 num-dce'd - Number of operations DCE'd

diff  --git a/flang/test/Fir/simplify-region-lite-after-inliner.fir b/flang/test/Fir/simplify-region-lite-after-inliner.fir
new file mode 100644
index 0000000000000..c09612b5dabed
--- /dev/null
+++ b/flang/test/Fir/simplify-region-lite-after-inliner.fir
@@ -0,0 +1,36 @@
+// RUN: tco %s | FileCheck %s
+
+
+// In flang pipeline, the inliner calls createCanonicalizerPass with the region
+// simplification disabled. The inliner pass does canonicalization even if
+// no inlining happens. After canonicalization, FIR lite region simplification
+// must be called to get rid of unreachable regions.
+// This code exposes the need to run SimplifyRegionLitePass after the inliner is
+// called with FIR pipeline.
+
+
+func.func @repro(%arg0: i8, %arg1: i8) {
+  %c34_i8 = arith.constant 34 : i8
+  %c-1_i8 = arith.constant -1 : i8
+  %2 = arith.xori %c34_i8, %c-1_i8 : i8
+  %3 = arith.andi %arg0, %c34_i8 : i8
+  %4 = arith.andi %arg1, %2 : i8
+  %5 = arith.ori %3, %4 : i8
+  %c34_i8_0 = arith.constant 34 : i8
+  %7 = arith.andi %arg0, %c34_i8_0 : i8
+  %c-35_i8 = arith.constant -35 : i8
+  %9 = arith.andi %arg1, %c-35_i8 : i8
+  %10 = arith.ori %7, %9 : i8
+  %11 = arith.cmpi ne, %5, %10 : i8
+  cf.cond_br %11, ^bb1, ^bb2
+^bb1:  // pred: ^bb0
+  %13 = func.call @foo() : () -> none
+  cf.br ^bb2
+^bb2:  // pred: ^bb0, ^bb2
+  return
+}
+func.func private @foo() -> none
+
+
+// CHECK: define void @repro(i8 %0, i8 %1)
+//   CHECK-NEXT  ret void


        


More information about the flang-commits mailing list