[all-commits] [llvm/llvm-project] 526244: [Matrix] Add first set of matrix intrinsics and in...

Florian Hahn via All-commits all-commits at lists.llvm.org
Thu Dec 12 07:42:39 PST 2019


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 526244b187d23351056de6aba715dc3d44668b1c
      https://github.com/llvm/llvm-project/commit/526244b187d23351056de6aba715dc3d44668b1c
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2019-12-12 (Thu, 12 Dec 2019)

  Changed paths:
    M llvm/docs/LangRef.rst
    M llvm/include/llvm/IR/Intrinsics.td
    M llvm/include/llvm/InitializePasses.h
    M llvm/include/llvm/Transforms/Scalar.h
    A llvm/include/llvm/Transforms/Scalar/LowerMatrixIntrinsics.h
    M llvm/lib/Passes/PassBuilder.cpp
    M llvm/lib/Passes/PassRegistry.def
    M llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
    M llvm/lib/Transforms/Scalar/CMakeLists.txt
    A llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
    M llvm/lib/Transforms/Scalar/Scalar.cpp
    A llvm/test/Transforms/LowerMatrixIntrinsics/bigger-expressions-double.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/multiply-double.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/multiply-float.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/multiply-i32.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/strided-load-double.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/strided-load-float.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/strided-load-i32.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/strided-store-double.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/strided-store-float.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/strided-store-i32.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/transpose-double.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/transpose-float.ll
    A llvm/test/Transforms/LowerMatrixIntrinsics/transpose-i32.ll

  Log Message:
  -----------
  [Matrix] Add first set of matrix intrinsics and initial lowering pass.

This is the first patch adding an initial set of matrix intrinsics and a
corresponding lowering pass. This has been discussed on llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2019-October/136240.html

The first patch introduces four new intrinsics (transpose, multiply,
columnwise load and store) and a LowerMatrixIntrinsics pass, that
lowers those intrinsics to vector operations.

Matrixes are embedded in a 'flat' vector (e.g. a 4 x 4 float matrix
embedded in a <16 x float> vector) and the intrinsics take the dimension
information as parameters. Those parameters need to be ConstantInt.
For the memory layout, we initially assume column-major, but in the RFC
we also described how to extend the intrinsics to support row-major as
well.

For the initial lowering, we split the input of the intrinsics into a
set of column vectors, transform those column vectors and concatenate
the result columns to a flat result vector.

This allows us to lower the intrinsics without any shape propagation, as
mentioned in the RFC. In follow-up patches, we plan to submit the
following improvements:
 * Shape propagation to eliminate the embedding/splitting for each
   intrinsic.
 * Fused & tiled lowering of multiply and other operations.
 * Optimization remarks highlighting matrix expressions and costs.
 * Generate loops for operations on large matrixes.
 * More general block processing for operation on large vectors,
   exploiting shape information.

We would like to add dedicated transpose, columnwise load and store
intrinsics, even though they are not strictly necessary. For example, we
could instead emit a large shufflevector instruction instead of the
transpose. But we expect that to
  (1) become unwieldy for larger matrixes (even for 16x16 matrixes,
      the resulting shufflevector masks would be huge),
  (2) risk instcombine making small changes, causing us to fail to
      detect the transpose, preventing better lowerings

For the load/store, we are additionally planning on exploiting the
intrinsics for better alias analysis.

Reviewers: anemet, Gerolf, reames, hfinkel, andrew.w.kaylor, efriedma, rengolin

Reviewed By: anemet

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




More information about the All-commits mailing list