[flang-commits] [flang] 11db65b - [flang] Control SUM simplification with a pass option.

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Wed Aug 17 13:39:17 PDT 2022


Author: Slava Zakharin
Date: 2022-08-17T13:37:44-07:00
New Revision: 11db65bab85a3a8c51ae5de9305ac2b76ccc2477

URL: https://github.com/llvm/llvm-project/commit/11db65bab85a3a8c51ae5de9305ac2b76ccc2477
DIFF: https://github.com/llvm/llvm-project/commit/11db65bab85a3a8c51ae5de9305ac2b76ccc2477.diff

LOG: [flang] Control SUM simplification with a pass option.

The current code may not always work correctly, e.g.:
https://github.com/llvm/llvm-project/issues/57201

I added 'enable-experimental' pass option so that SUM simplification
may be enabled in LIT tests, but it is not enabled when the pass
is added to the passes pipeline.

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

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Transforms/Passes.td
    flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
    flang/test/Transforms/simplifyintrinsics.fir

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td
index b60de00838cae..cb0df9cd630c4 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.td
+++ b/flang/include/flang/Optimizer/Transforms/Passes.td
@@ -186,6 +186,12 @@ def SimplifyIntrinsics : Pass<"simplify-intrinsics", "mlir::ModuleOp"> {
     This function can be inlined by a general purpose inlining pass.
   }];
   let constructor = "::fir::createSimplifyIntrinsicsPass()";
+
+  let options = [
+    Option<"enableExperimental", "enable-experimental", "bool",
+           /*default=*/"false",
+           "Enable experimental code that may not always work correctly">
+  ];
 }
 
 def MemoryAllocationOpt : Pass<"memory-allocation-opt", "mlir::func::FuncOp"> {

diff  --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
index 223140d01415e..ed1d1be4b90c4 100644
--- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
+++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
@@ -385,7 +385,10 @@ void SimplifyIntrinsicsPass::runOnOperation() {
         // Prototype for runtime call (from sum.cpp):
         // RTNAME(Sum<T>)(const Descriptor &x, const char *source, int line,
         //                int dim, const Descriptor *mask)
-        if (funcName.startswith("_FortranASum")) {
+        //
+        // Disable SUM inlining by default, because it fatally fails on some
+        // FIR yet.
+        if (enableExperimental && funcName.startswith("_FortranASum")) {
           mlir::Operation::operand_range args = call.getArgs();
           // args[1] and args[2] are source filename and line number, ignored.
           const mlir::Value &dim = args[3];

diff  --git a/flang/test/Transforms/simplifyintrinsics.fir b/flang/test/Transforms/simplifyintrinsics.fir
index 3580da70d1ef0..f51d82f6959a0 100644
--- a/flang/test/Transforms/simplifyintrinsics.fir
+++ b/flang/test/Transforms/simplifyintrinsics.fir
@@ -1,4 +1,4 @@
-// RUN: fir-opt --split-input-file --simplify-intrinsics %s | FileCheck %s
+// RUN: fir-opt --split-input-file --simplify-intrinsics='enable-experimental=true' %s | FileCheck %s
 
 // Call to SUM with 1D I32 array is replaced.
 module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.target_triple = "native"} {


        


More information about the flang-commits mailing list