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

Hung-Kuan Tseng llvmlistbot at llvm.org
Mon Sep 14 08:04:57 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))
----------------
Tim096 wrote:

Done: `exp(log(a))` now folds only with `reassoc` on the exp and `reassoc`, `nnan`, `ninf` and `nsz` on the log, with a test where the log is missing each of them in turn. I've updated the PR description to say we are stricter than InstructionSimplify here on purpose.


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


More information about the Mlir-commits mailing list