MemRefDataFlowOpt

Hi @kiranchandramohan ,

There are some flang optimization work items you mentioned in the post Status of Flang's Optimization - #6 by kiranchandramohan
I am interested in the first item of productizing the MemRefDataFlowOpt pass.

After some investigations on the pass, I have the following questions:

  1. The pass aims to do the store/load forwarding and store elimination. Several passes in the LLVM mid-end are doing similar optimizations such as gvn. What would be the benefits or needs of implementing at the MLIR level?

  2. The pass is based on the MLIR’s AffineScalarReplacement. What do we need for “productizing” the pass? Could you please elaborate on it further?

Thanks for your interest in this work.

  1. I have seen some cases particularly in the OpenMP flow where LLVM was not able to remove some code. Using the MemrefDataflowOpt and some other changes this was achieved. See the discussion in the following two tickets.
    Fortran Array Descriptors in Tight Loop (flang-new) · Issue #63176 · llvm/llvm-project · GitHub
    Missing Constant Propagation in OpenMP Parallel Region · Issue #63130 · llvm/llvm-project · GitHub

  2. Productising includes all the work involved in switching ON the pass by default or with optimisation flags. This will involve making sure the pass works with all kinds of inputs and corner cases. If we switch ON the pass will all tests in the gfortran testsuite pass, will all the enabled applications pass? The pass was originally a prototype and some of the issues are discussed in the patch that upstreamed this.
    ⚙ D111288 [fir] Add data flow optimization pass

Recently a mem2reg pass was added to MLIR (⚙ D148109 [mlir] Add a generic mem2reg implementation.). Using this in Flang could be another way to achieve some of the things that the MemRefDataFlowOpt does.