[all-commits] [llvm/llvm-project] 0301bf: [MLIR] Lower `math.powf(x, 3.0)` to `x * x * x`. (...

Benoit Jacob via All-commits all-commits at lists.llvm.org
Fri Feb 14 12:25:22 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0301bf977aa9842003462a2a7a3c3ce56abfaae0
      https://github.com/llvm/llvm-project/commit/0301bf977aa9842003462a2a7a3c3ce56abfaae0
  Author: Benoit Jacob <jacob.benoit.1 at gmail.com>
  Date:   2025-02-14 (Fri, 14 Feb 2025)

  Changed paths:
    M mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp
    M mlir/test/Dialect/Math/expand-math.mlir

  Log Message:
  -----------
  [MLIR] Lower `math.powf(x, 3.0)` to `x * x * x`. (#127256)

`math.powf(x, y)` never really supported negative values of `x`, but
that was unclear (happened to work for some values of `y`) until
https://github.com/llvm/llvm-project/pull/126338 was merged yesterday
and lowered it to the usual `exp(y * log(x))` outside of a few special
exponent values, such as y == 2.0` lowering to `x * x`.

It turns out that code in the wild has been relying on `math.powf(x, y)`
with negative `x` for some integral values of `y` for which a lowering
to muls was intended: https://github.com/iree-org/iree/issues/19996

This PR adds such a lowering for `y == 3.0`. It "fixes" such cases, and
it is a more efficient lowering anyway.

There needs to be a wider project to stop altogether using `powf` with
negative `x`, use `math.fpowi` for that.

Signed-off-by: Benoit Jacob <jacob.benoit.1 at gmail.com>



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list