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

Hung-Kuan Tseng llvmlistbot at llvm.org
Fri Sep 11 07:36:20 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:

Good point, thanks. It now checks `reassoc` on the exp instead, as LLVM does for the real `exp(log(x))` in `simplifyUnaryIntrinsic`. That fold has the same behaviour for a negative or non-finite `x`, where `log(x)` is not finite either, so I read `reassoc` as covering it. If you would rather also require `nnan` and `ninf` here, I can add that.

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


More information about the Mlir-commits mailing list