[mlir] [VectorOps] Add the ability to mark FP reductions with "reassociate" attribute
authoraartbik <ajcbik@google.com>
Fri, 26 Jun 2020 18:03:11 +0000 (11:03 -0700)
committeraartbik <ajcbik@google.com>
Fri, 26 Jun 2020 18:03:14 +0000 (11:03 -0700)
commitceb1b327b53c82203deaa0b0ede3fb07ec8f823a
treef3f20aa72a93fa7e3edc0094f630933b2bae4b56
parentfa0da7ec6a3b6dafe5ddd33125264c4b131523c2
[mlir] [VectorOps] Add the ability to mark FP reductions with "reassociate" attribute

Rationale:
In general, passing "fastmath" from MLIR to LLVM backend is not supported, and even just providing such a feature for experimentation is under debate. However, passing fine-grained fastmath related attributes on individual operations is generally accepted. This CL introduces an option to instruct the vector-to-llvm lowering phase to annotate floating-point reductions with the "reassociate" fastmath attribute, which allows the LLVM backend to use SIMD implementations for such constructs. Oher lowering passes can start using this mechanism right away in cases where reassociation is allowed.

Benefit:
For some microbenchmarks on x86-avx2, speedups over 20 were observed for longer vector (due to cleaner, spill-free and SIMD exploiting code).

Usage:
mlir-opt --convert-vector-to-llvm="reassociate-fp-reductions"

Reviewed By: ftynse, mehdi_amini

Differential Revision: https://reviews.llvm.org/D82624
mlir/include/mlir/Conversion/Passes.td
mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h
mlir/include/mlir/Dialect/LLVMIR/LLVMOpBase.td
mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
mlir/test/Conversion/VectorToLLVM/vector-reduction-to-llvm.mlir [new file with mode: 0644]
mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
mlir/test/Target/llvmir-intrinsics.mlir