[all-commits] [llvm/llvm-project] 3f429e: Implement an scf.for range folding optimization pass.

anthonycanino1 via All-commits all-commits at lists.llvm.org
Wed Jun 23 18:07:47 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3f429e82d3ea1710ee0a841675acba9bb7b658d2
      https://github.com/llvm/llvm-project/commit/3f429e82d3ea1710ee0a841675acba9bb7b658d2
  Author: Anthony Canino <anthony.canino1 at gmail.com>
  Date:   2021-06-24 (Thu, 24 Jun 2021)

  Changed paths:
    M mlir/include/mlir/Dialect/SCF/Passes.h
    M mlir/include/mlir/Dialect/SCF/Passes.td
    M mlir/lib/Dialect/SCF/Transforms/CMakeLists.txt
    A mlir/lib/Dialect/SCF/Transforms/LoopRangeFolding.cpp
    A mlir/test/Dialect/SCF/loop-range.mlir

  Log Message:
  -----------
  Implement an scf.for range folding optimization pass.

In cases where arithmetic (addi/muli) ops are performed on an scf.for loops induction variable with a single use, we can fold those ops directly into the scf.for loop.

For example, in the following code:

```
scf.for %i = %c0 to %arg1 step %c1 {
  %0 = addi %arg2, %i : index
  %1 = muli %0, %c4 : index
  %2 = memref.load %arg0[%1] : memref<?xi32>
  %3 = muli %2, %2 : i32
  memref.store %3, %arg0[%1] : memref<?xi32>
}
```

we can lift `%0` up into the scf.for loop range, as it is the only user of %i:

```
%lb = addi %arg2, %c0 : index
%ub = addi %arg2, %i : index
scf.for %i = %lb to %ub step %c1 {
  %1 = muli %0, %c4 : index
  %2 = memref.load %arg0[%1] : memref<?xi32>
  %3 = muli %2, %2 : i32
  memref.store %3, %arg0[%1] : memref<?xi32>
}
```

Reviewed By: mehdi_amini, ftynse, Anthony

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




More information about the All-commits mailing list