[Mlir-commits] [mlir] [mlir][math] Fix `math.powf(a, b)` expansion for negative base (PR #193231)

Benoit Jacob llvmlistbot at llvm.org
Mon Apr 27 05:42:50 PDT 2026


bjacob wrote:

The math dialect has two distinct power ops: `powf` and `fpowi`.

These correspond to the two distinct mathematical power concepts: `a^b is well-defined when:
* Either a is positive , and b can be anything:(then `a^b=exp(b*log(a))`.  This is m̀ath.powf`.
* Or b is any integer (negative or positive) and a can be anything. Then `a^b` is defined by repeated multiplication of a or 1/a. This is m̀ath.fpowi`.

Thus the two MLIR math dialect ops already map very well to these two distinct math concepts.

Unfortunately, the MLIR documentation doesn`t reflect that.

I believe that the ideal fix here would be to update MLIR documentation, and design a strategy of gradually enforcing the restriction that math.powf requires a to be a positive real number.

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


More information about the Mlir-commits mailing list