[Mlir-commits] [mlir] [mlir][complex] Require fastmath for the add/sub and exp/log folds (PR #221384)

Mattéo Rizza Murgier llvmlistbot at llvm.org
Mon Sep 14 00:27:43 PDT 2026


================
@@ -313,8 +322,12 @@ OpFoldResult NegOp::fold(FoldAdaptor adaptor) {
 
 OpFoldResult ExpOp::fold(FoldAdaptor adaptor) {
   // complex.exp(complex.log(a)) -> a
+  // exp(log(a)) is only an approximation of a, so both ops need `afn`.
   if (auto logOp = getOperand().getDefiningOp<LogOp>())
-    return logOp.getOperand();
+    if (arith::bitEnumContainsAll(getFastmath(), arith::FastMathFlags::afn) &&
+        arith::bitEnumContainsAll(logOp.getFastmath(),
+                                  arith::FastMathFlags::afn))
----------------
matteo-rm wrote:

I think the flags we should check are:
exp: `reassoc`
log: `reassoc`, `nnan`, `ninf`, `nsz`
LLVM not requiring `reassoc` on the log is incoherent with the language reference.

https://github.com/llvm/llvm-project/pull/221384


More information about the Mlir-commits mailing list