This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Arith] Add arith.is_nan and arith.is_inf predicates
ClosedPublic

Authored by krzysz00 on Jul 24 2023, 2:24 PM.

Details

Summary

Both LLVM and SPIR-V have some form of "is this float a NaN/Inf"
operation (though LLVM's uses the rather opaque "is.fpclass"
intrinsic), which is not exposed in MLIR.

This has lead to awkward workarounds in -arith-expands-ops where a NaN
test was performed by comparing an operation to itself. This commit
resolves that issue.

Diff Detail

Event Timeline

krzysz00 created this revision.Jul 24 2023, 2:24 PM
Herald added a reviewer: ftynse. · View Herald Transcript
Herald added a reviewer: dcaballe. · View Herald Transcript
Herald added a reviewer: kuhar. · View Herald Transcript
Herald added a reviewer: kuhar. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
krzysz00 requested review of this revision.Jul 24 2023, 2:24 PM
kuhar added inline comments.Jul 24 2023, 2:40 PM
mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
991

nit: I wonder if we should call these 'is_nan` and is_inf in the name of readability. We already have a few airth ops with underscore in the name, e.g., index_cast or addi_extended.

mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
58

Would it be possible to use enums here instead of hardcoding the bitpatterns?

mlir/lib/Dialect/Arith/IR/ArithOps.cpp
1131–1132

nit: is there an overload that doesn't require the 'success' parameter that we could use here?

krzysz00 added inline comments.Jul 25 2023, 7:38 AM
mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
991

On the other hand, the relevant operations in C/C++/SPIR-V/... are without an underscore and this'll make it easier to find

mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
58

There doesn't seem to be one, given that flang uses 0b constants for the same purpose

mlir/lib/Dialect/Arith/IR/ArithOps.cpp
1131–1132

I don't think so, and I'm not sure it'd be worth adding one.

krzysz00 updated this revision to Diff 543986.Jul 25 2023, 8:08 AM

Update flang tests

Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 8:08 AM
kuhar accepted this revision.Jul 25 2023, 4:15 PM

LGTM for SPIR-V but please get at least one more approval from someone familiar with the LLVM lowering path

This revision is now accepted and ready to land.Jul 25 2023, 4:15 PM
dcaballe accepted this revision.Jul 28 2023, 10:16 AM

LGTM % the comments. Thanks for the contribution!

mlir/include/mlir/Conversion/ArithCommon/AttrToLLVMConverter.h
58

-> ///

mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
86

Is the comment correct?

991

+1 to using underscore, for consistency within the Arith dialect

mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
58

Yeah, an enum would be great or at least a comment explaining what each bitfield means.

krzysz00 updated this revision to Diff 546130.Aug 1 2023, 10:42 AM
krzysz00 marked 2 inline comments as done.

Address review comments

Address comments

krzysz00 retitled this revision from [mlir][Arith] Add arith.isnan and arith.isinf predicates to [mlir][Arith] Add arith.is_nan and arith.is_inf predicates.Aug 2 2023, 7:41 AM
This revision was landed with ongoing or failed builds.Aug 2 2023, 7:42 AM
This revision was automatically updated to reflect the committed changes.