[all-commits] [llvm/llvm-project] ddff37: [MLIR] Simplify affine maps + operands exploiting ...

Uday Bondhugula via All-commits all-commits at lists.llvm.org
Tue Oct 4 05:51:43 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ddff3766b78d1b1d2c003639ab44c8afd1e458c1
      https://github.com/llvm/llvm-project/commit/ddff3766b78d1b1d2c003639ab44c8afd1e458c1
  Author: Uday Bondhugula <uday at polymagelabs.com>
  Date:   2022-10-04 (Tue, 04 Oct 2022)

  Changed paths:
    M mlir/include/mlir/IR/AffineMap.h
    M mlir/lib/Dialect/Affine/IR/AffineOps.cpp
    M mlir/lib/IR/AffineMap.cpp
    M mlir/test/Dialect/Affine/canonicalize.mlir

  Log Message:
  -----------
  [MLIR] Simplify affine maps + operands exploiting IV info

Simplify affine expressions and maps while exploiting simple range and
step info of any IVs that are operands. This simplification is local,
O(1) and practically useful in several scenarios. Accesses with
floordiv's and mod's where the LHS is non-negative and bounded or is a
known multiple of a constant can often be simplified. This is
implemented as a canonicalization for all affine ops in a generic way:
all affine.load/store, vector_load/store, affine.apply, affine.min/max,
etc. ops.

Eg: For tiled loop nests accessing buffers this way:

affine.for %i = 0 to 1024 step 32 {
  affine.for %ii = 0 to 32 {
    affine.load [(%i + %ii) floordiv 32, (%i + %ii) mod 32]
  }
}

// Note that %i is a multiple of 32 and %ii < 32, hence:

(%i + %ii) floordiv 32 is the same as %i floordiv 32
(%i + %ii) mod 32 is the same as %ii mod 32.

The simplification leads to simpler index/subscript arithmetic for
multi-dimensional arrays and also in turn enables detection of spatial
locality (for vectorization for eg.), temporal locality or loop
invariance for hoisting or scalar replacement.

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




More information about the All-commits mailing list