[MLIR] Complex Dialect DivOp folder (original) (raw)

November 26, 2025, 6:49pm 1

Is there a reason we are not checking for NaN values in the DivOp folder? For example, here is the DivOp folder code ( llvm-project/mlir/lib/Dialect/Complex/IR/ComplexOps.cpp at 5ab3375b2cf461ab02704d129a1f4d5ba1a1e275 · llvm/llvm-project · GitHub )

auto rhs = adaptor.getRhs();
if (!rhs) return {};

ArrayAttr arrayAttr = dyn_cast<ArrayAttr>(rhs);
if (!arrayAttr || arrayAttr.size() != 2) return {};

APFloat real = cast<FloatAttr>(arrayAttr[0]).getValue();
APFloat imag = cast<FloatAttr>(arrayAttr[1]).getValue();

if (!imag.isZero()) return {};
if (real == APFloat(real.getSemantics(), 1)) return getLhs();
return {};

As far as I understand, that means Complex(NaN, 1) / Complex(1, 0) it will result in Complex(NaN, 1), which is the LHS, but I think the expected value should be Complex(NaN, NaN), right?! 🤔 similar to what we get from C++ with the default -complex-range 🤔.

Code sample in C++ that shows the expected result: Compiler Explorer

As with most things in MLIR: it’s likely just not implemented yet and “patch welcome”.

Thank you, I will submit a patch soon :+1: