[Mlir-commits] [mlir] [mlir][tosa][tosa-to-linalg] Add NaN Mode Lowering (PR #125668)
Suraj Sudhir
llvmlistbot at llvm.org
Thu Feb 13 11:31:34 PST 2025
================
@@ -36,6 +36,47 @@
using namespace mlir;
using namespace mlir::tosa;
+// Helper function to materialize the semantically correct compare and select
+// operations a binary operation with a specific NaN propagation mode.
+//
+// In the case of "PROPAGATE" semantics no compare and selection is required and
+// this function does nothing.
+//
+// In the case of "IGNORE" semantics this function materializes a comparison of
+// the current operands to the op which will return true for any NaN
+// argument and then selects between the non-NaN operation argument and the
+// calculated result based on whether the lhs or rhs is NaN or not. In pseudo
+// code:
+//
+// binary<op>(lhs, rhs):
+// result = op(lhs, rhs)
+// if lhs == NaN return rhs
+// if rhs == NaN return lhs
+// return result
+static Value materializeBinaryNanCheckIfRequired(Operation *op,
+ PatternRewriter &rewriter,
+ Value lhs, Value rhs,
+ Value result) {
+ const auto nanMode = getNanMode(op, rewriter);
+ if (!nanMode)
+ return {};
----------------
sjarus wrote:
Isn't the absence of the parameter equivalent to PROPAGATE generally ? Also, {} ought to return the default initialized value. Is that what makes sense to return rather than std::optional<Value> ?
https://github.com/llvm/llvm-project/pull/125668
More information about the Mlir-commits
mailing list