[PATCH] D156471: [mlir] Support fast-math friendly constants for identity value

Quentin Colombet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 27 11:30:55 PDT 2023


qcolombet created this revision.
qcolombet added reviewers: mehdi_amini, nicolasvasilache, rengolin, chelini, ftynse.
qcolombet added a project: MLIR.
Herald added subscribers: bviyer, Moerafaat, zero9178, bzcheeseman, awarzynski, sdasgup3, wenzhicui, wrengr, jsetoain, hanchung, cota, mravishankar, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, rriddle.
Herald added a reviewer: aartbik.
Herald added a reviewer: bondhugula.
Herald added a reviewer: kuhar.
Herald added a project: All.
qcolombet requested review of this revision.
Herald added subscribers: wangpc, limo1996, stephenneuendorffer.
Herald added a reviewer: dcaballe.

Add an option to the family of `getIdentity` helper functions so that it is possible to produce fast-math friendly constants.

For instance, for `maxf` the identity value is `-inf`, however, if the related operations are lowered with fast-math (`noinf` in particular), then the value becomes `poison` and chances are the whole codegen is not going to do what we want.

To avoid this problem, we add an option to `getIdentity` and friends that specifies whether a finite value needs to be produced or not.

The patch is NFC for all the code but the lowering of `linalg::softmax` because we know we lower that with fast-math down the line.

I didn't audit the rest of the code to check if it would make sense to set this boolean in more places.

Note: It feels kind of wrong to have to know what the lowering may do, but I don't know what the right (at least short-term) solution is. Long term, we may want a special "neutral element" attribute for the respective ops. I didn't think too much about the implications for that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156471

Files:
  mlir/include/mlir/Dialect/Arith/IR/Arith.h
  mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp
  mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
  mlir/lib/Dialect/Arith/IR/ArithOps.cpp
  mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
  mlir/lib/Dialect/Linalg/Transforms/SplitReduction.cpp
  mlir/lib/Dialect/Linalg/Transforms/TilingInterfaceImpl.cpp
  mlir/test/Dialect/Linalg/transform-op-decompose.mlir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156471.544866.patch
Type: text/x-patch
Size: 11765 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230727/3ecc66ad/attachment.bin>


More information about the llvm-commits mailing list