History log of /llvm-project/mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp (Results 1 – 25 of 33)
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 3a337757 29-Jan-2025 Hyunsung Lee <ita9naiwa@gmail.com>

[mlir][math]Update `convertPowfOp` `ExpandPatterns.cpp` (#124402)

The current implementation of `convertPowfOp` requires a calculation of
`a * a` but, max\<fp16\> ~= 65,504, and if `a` is about 16,

[mlir][math]Update `convertPowfOp` `ExpandPatterns.cpp` (#124402)

The current implementation of `convertPowfOp` requires a calculation of
`a * a` but, max\<fp16\> ~= 65,504, and if `a` is about 16, it will
overflow so get INF in fp8 or fp16 easily.


Remove support when `a < 0`. Overhead of handling negative value of `a`
is large and easy to overflow;

- related issue in iree:
https://github.com/iree-org/iree/issues/15936

show more ...


Revision tags: llvmorg-21-init
# 45d83ae7 24-Jan-2025 donald chen <chenxunyu1993@gmail.com>

[mlir] [math] Fix the precision issue of expand math (#120865)

The convertFloorOp pattern incurs precision loss when floating-point
numbers exceed the representable range of int64. This pattern sho

[mlir] [math] Fix the precision issue of expand math (#120865)

The convertFloorOp pattern incurs precision loss when floating-point
numbers exceed the representable range of int64. This pattern should be
removed.

Fixes https://github.com/llvm/llvm-project/issues/119836

show more ...


Revision tags: llvmorg-19.1.7, llvmorg-19.1.6
# a92e3df3 09-Dec-2024 Christopher Bate <cbate@nvidia.com>

[mlir][math] Fix `math.powf` expansion case for `pow(x, 0)` (#119015)

Lowering `math.powf` to `llvm.intr.powf` will result in `pow(x, 0) =
1`, even for `x=0`. When using the Math dialect expansion

[mlir][math] Fix `math.powf` expansion case for `pow(x, 0)` (#119015)

Lowering `math.powf` to `llvm.intr.powf` will result in `pow(x, 0) =
1`, even for `x=0`. When using the Math dialect expansion patterns,
`pow(0, 0)` will result in `-nan`, however, This change adds two
additional instructions to the lowering to ensure the `pow(x, 0)` case
lowers to to `1` regardless of the value of `x`.

Resolves https://github.com/llvm/llvm-project/issues/118945.

show more ...


Revision tags: llvmorg-19.1.5, llvmorg-19.1.4, llvmorg-19.1.3, llvmorg-19.1.2, llvmorg-19.1.1, llvmorg-19.1.0, llvmorg-19.1.0-rc4, llvmorg-19.1.0-rc3, llvmorg-19.1.0-rc2, llvmorg-19.1.0-rc1, llvmorg-20-init, llvmorg-18.1.8, llvmorg-18.1.7, llvmorg-18.1.6
# 279a659e 13-May-2024 Corentin Ferry <corentin.ferry@amd.com>

[mlir][math] lower rsqrt to sqrt + fdiv (#91344)

This commit creates an expansion pattern to lower math.rsqrt(x) into
fdiv(1, sqrt(x)).


# a62a7024 07-May-2024 jinchen <49575973+jinchen62@users.noreply.github.com>

[mlir][math] Add expand patterns for acosh, asinh, atanh (#90718)


Revision tags: llvmorg-18.1.5, llvmorg-18.1.4
# 5b702be1 03-Apr-2024 Prashant Kumar <pk5561@gmail.com>

[mlir][math] Convert math.fpowi to math.powf in case of non constant (#87472)

Convert math.fpowi to math.powf by converting dtype of power operand to
floating point.


Revision tags: llvmorg-18.1.3
# 10a57f3a 01-Apr-2024 Prashant Kumar <pk5561@gmail.com>

[mlir][math] Expand powfI operation for constant power operand. (#87081)

-- Convert `math.fpowi` to a series of `arith.mulf` operations.
-- If the power is negative, we divide the result by 1.


Revision tags: llvmorg-18.1.2
# d39ac3a8 17-Mar-2024 srcarroll <50210727+srcarroll@users.noreply.github.com>

[mlir][math] Reland 58ef9bec071383744fb703ff08df9806f25e4095 (#85436)

The previous implementation decomposes tanh(x) into
`(exp(2x) - 1)/(exp(2x)+1), x < 0`
`(1 - exp(-2x))/(1 + exp(-2x)), x >= 0`

[mlir][math] Reland 58ef9bec071383744fb703ff08df9806f25e4095 (#85436)

The previous implementation decomposes tanh(x) into
`(exp(2x) - 1)/(exp(2x)+1), x < 0`
`(1 - exp(-2x))/(1 + exp(-2x)), x >= 0`
This is fine as it avoids overflow with the exponential, but the whole
decomposition is computed for both cases unconditionally, then the
result is chosen based off the sign of the input. This results in doing
two expensive exp computations.

The proposed change avoids doing the whole computation twice by
exploiting the reflection symmetry `tanh(-x) = -tanh(x)`. We can
"normalize" the input to be positive by setting `y = sign(x) * x`, where
the sign of `x` is computed as `sign(x) = (float)(x > 0) * (-2) + 1`.
Then compute `z = tanh(y) `with the decomposition above for `x >=0` and
"denormalize" the result `z * sign(x)` to retain the sign. The reason it
is done this way is that it is very amenable to vectorization.

This method trades the duplicate decomposition computations (which takes
5 instructions including an extra expensive exp and div) for 4 cheap
instructions to compute the signs value

`arith.cmpf `(which is a pre-existing instruction in the previous impl)
`arith.sitofp`
`arith.mulf`
`arith.addf`
and 1 more instruction to get the right sign in the result
5. `arith.mulf`.
Moreover, numerically, this implementation will yield the exact same
results as the previous implementation.

As part of the relanding, a casting issue from the original commit has
been fixed, i.e. casting bool to float with `uitofp`. Additionally a
correctness test with `mlir-cpu-runner` has been added.

show more ...


# f75d164e 15-Mar-2024 srcarroll <50210727+srcarroll@users.noreply.github.com>

Revert "[mlir][math] Implement alternative decomposition for tanh (#8… (#85429)

…5025)"

This reverts commit 58ef9bec071383744fb703ff08df9806f25e4095.

There is a bool to float casting issue that ne

Revert "[mlir][math] Implement alternative decomposition for tanh (#8… (#85429)

…5025)"

This reverts commit 58ef9bec071383744fb703ff08df9806f25e4095.

There is a bool to float casting issue that needs to be sorted out to
make sure this is target independent

show more ...


# 58ef9bec 15-Mar-2024 srcarroll <50210727+srcarroll@users.noreply.github.com>

[mlir][math] Implement alternative decomposition for tanh (#85025)

The previous implementation decomposes `tanh(x)` into
`(exp(2x) - 1)/(exp(2x)+1), x < 0`
`(1 - exp(-2x))/(1 + exp(-2x)), x >= 0`

[mlir][math] Implement alternative decomposition for tanh (#85025)

The previous implementation decomposes `tanh(x)` into
`(exp(2x) - 1)/(exp(2x)+1), x < 0`
`(1 - exp(-2x))/(1 + exp(-2x)), x >= 0`
This is fine as it avoids overflow with the exponential, but the whole
decomposition is computed for both cases unconditionally, then the
result is chosen based off the sign of the input. This results in doing
two expensive `exp` computations.

The proposed change avoids doing the whole computation twice by
exploiting the reflection symmetry `tanh(-x) = -tanh(x)`. We can
"normalize" the input to be positive by setting `y = sign(x) * x`, where
the sign of `x` is computed as `sign(x) = (float)(x > 0) * (-2) + 1`.
Then compute `z = tanh(y)` with the decomposition above for `x >=0` and
"denormalize" the result `z * sign(x)` to retain the sign. The reason it
is done this way is that it is very amenable to vectorization.

This method trades the duplicate decomposition computations (which takes
5 instructions including an extra expensive `exp` and `div`) for 4 cheap
instructions to compute the signs value
1. `arith.cmpf` (which is a pre-existing instruction in the previous
impl)
2. `arith.sitofp`
3. `arith.mulf`
4. `arith.addf`

and 1 more instruction to get the right sign in the result
5. `arith.mulf`. Moreover, numerically, this implementation will yield
the exact same results as the previous implementation.

show more ...


Revision tags: llvmorg-18.1.1, llvmorg-18.1.0, llvmorg-18.1.0-rc4, llvmorg-18.1.0-rc3, llvmorg-18.1.0-rc2, llvmorg-18.1.0-rc1, llvmorg-19-init
# aa165edc 15-Dec-2023 Rob Suderman <rob.suderman@gmail.com>

[mlir][math] Added `math.sinh` with expansions to `math.exp` (#75517)

Includes end-to-end tests for the cpu running, folders using `libm` and
lowerings to the corresponding `libm` operations.


Revision tags: llvmorg-17.0.6, llvmorg-17.0.5, llvmorg-17.0.4, llvmorg-17.0.3, llvmorg-17.0.2, llvmorg-17.0.1, llvmorg-17.0.0, llvmorg-17.0.0-rc4
# f66e4bd6 25-Aug-2023 Balaji V. Iyer <bviyer@gmail.com>

[mlir][math] Modify math.powf to handle negative bases.

Powf expansion currently returns NaN when the base is negative.
This is because taking natural log of a negative number gives
NaN. This patch

[mlir][math] Modify math.powf to handle negative bases.

Powf expansion currently returns NaN when the base is negative.
This is because taking natural log of a negative number gives
NaN. This patch will square the base and half the exponent, thereby
getting around the negative base problem.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D158797

show more ...


# fe355a44 24-Aug-2023 Alexander Shaposhnikov <ashaposhnikov@google.com>

[MLIR][Math] Add support for f64 in the expansion of math.roundeven

Add support for f64 in the expansion of math.roundeven.
Associated GitHub issue: https://github.com/openxla/iree/issues/13522
This

[MLIR][Math] Add support for f64 in the expansion of math.roundeven

Add support for f64 in the expansion of math.roundeven.
Associated GitHub issue: https://github.com/openxla/iree/issues/13522
This is based on the offline discussion and essentially recommits
https://reviews.llvm.org/D158234.

Test plan: ninja check-mlir check-all

show more ...


Revision tags: llvmorg-17.0.0-rc3
# d22883e3 18-Aug-2023 Alexander Shaposhnikov <ashaposhnikov@google.com>

Revert "[MLIR][Math] Add support for f16 in the expansion of math.roundeven"

This reverts commit 40bf36319e383b7b5f2ffbee9abc18d93e1e07b4.
The build bot ppc64le-mlir-rhel-test got broken by these ch

Revert "[MLIR][Math] Add support for f16 in the expansion of math.roundeven"

This reverts commit 40bf36319e383b7b5f2ffbee9abc18d93e1e07b4.
The build bot ppc64le-mlir-rhel-test got broken by these changes,
see https://lab.llvm.org/buildbot#builders/88/builds/61048 .

show more ...


# 40bf3631 18-Aug-2023 Alexander Shaposhnikov <ashaposhnikov@google.com>

[MLIR][Math] Add support for f16 in the expansion of math.roundeven

Add support for f16 in the expansion of math.roundeven.
Associated GitHub issue: https://github.com/openxla/iree/issues/13522
This

[MLIR][Math] Add support for f16 in the expansion of math.roundeven

Add support for f16 in the expansion of math.roundeven.
Associated GitHub issue: https://github.com/openxla/iree/issues/13522
This version addresses the build issues on Windows reported on
https://reviews.llvm.org/D157204

Test plan: ninja check-mlir check-all

Differential revision: https://reviews.llvm.org/D158234

show more ...


# f745c91f 17-Aug-2023 Alexander Shaposhnikov <ashaposhnikov@google.com>

Revert "[MLIR][Math] Add support for f16 in the expansion of math.roundeven"

This reverts commit b96f6cf62902ca96ed5aa62d4e158292280284e1
since it has broken some Windows build bots
(see https://rev

Revert "[MLIR][Math] Add support for f16 in the expansion of math.roundeven"

This reverts commit b96f6cf62902ca96ed5aa62d4e158292280284e1
since it has broken some Windows build bots
(see https://reviews.llvm.org/D157204).
Will recommit a fixed version later.

show more ...


# b96f6cf6 17-Aug-2023 Alexander Shaposhnikov <ashaposhnikov@google.com>

[MLIR][Math] Add support for f16 in the expansion of math.roundeven

Add support for f16 in the expansion of math.roundeven.
Associated GitHub issue: https://github.com/openxla/iree/issues/13522

Tes

[MLIR][Math] Add support for f16 in the expansion of math.roundeven

Add support for f16 in the expansion of math.roundeven.
Associated GitHub issue: https://github.com/openxla/iree/issues/13522

Test plan: ninja check-mlir check-all

Differential revision: https://reviews.llvm.org/D157204

show more ...


Revision tags: llvmorg-17.0.0-rc2, llvmorg-17.0.0-rc1, llvmorg-18-init, llvmorg-16.0.6, llvmorg-16.0.5, llvmorg-16.0.4, llvmorg-16.0.3
# 44baa655 22-Apr-2023 Ramiro Leal-Cavazos <ramiroleal050@gmail.com>

Revert "Revert "Fix handling of special and large vals in expand pattern for `round`" and "Add pattern that expands `math.roundeven` into `math.round` + arith""

This reverts commit 87cef78fa1c7bf6ef

Revert "Revert "Fix handling of special and large vals in expand pattern for `round`" and "Add pattern that expands `math.roundeven` into `math.round` + arith""

This reverts commit 87cef78fa1c7bf6efc544e990894a6062d56abec.

The issue in the original revert is that a lit test expecting a `-nan`
as an output was failing on M2. Since the IEEE 754-2008 standard does
not require the sign to be printed when displaying a `nan`, this
commit changes the `CHECK` for `-nan` to one that checks the result
value bitcasted to an `i32` to ensure that input is being left
unchanged. This check should now be independent of platform being used
to run test.

Reviewed By: jpienaar, mehdi_amini

Differential Revision: https://reviews.llvm.org/D148941

show more ...


# 87cef78f 21-Apr-2023 Mehdi Amini <joker.eph@gmail.com>

Revert "Fix handling of special and large vals in expand pattern for `round`" and "Add pattern that expands `math.roundeven` into `math.round` + arith"

This reverts commit 8d2bae9abdc30e104bab00a4dd

Revert "Fix handling of special and large vals in expand pattern for `round`" and "Add pattern that expands `math.roundeven` into `math.round` + arith"

This reverts commit 8d2bae9abdc30e104bab00a4dd0f9d39f5bdda6e and
commit ab2fc9521ec606603412645d4a4b3cf456acd153.

Tests are broken on Mac M2

show more ...


# 8d2bae9a 20-Apr-2023 Ramiro Leal-Cavazos <ramiroleal050@gmail.com>

Add pattern that expands `math.roundeven` into `math.round` + arith

This commit adds a pattern that expands `math.roundeven` into
`math.round` + some ops from `arith`. This is needed to be able to r

Add pattern that expands `math.roundeven` into `math.round` + arith

This commit adds a pattern that expands `math.roundeven` into
`math.round` + some ops from `arith`. This is needed to be able to run
`math.roundeven` in a vectorized manner.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D148285

show more ...


# ab2fc952 20-Apr-2023 Ramiro Leal-Cavazos <ramiroleal050@gmail.com>

Fix handling of special and large vals in expand pattern for `round`

The current expand pattern for `math.round` does not handle the
special values -0.0, +-inf, and +-nan correctly. It also does not

Fix handling of special and large vals in expand pattern for `round`

The current expand pattern for `math.round` does not handle the
special values -0.0, +-inf, and +-nan correctly. It also does not
properly handle values with magnitude |x| >= 2^23. Lastly, the pattern
generates invalid IR when the input to `math.round` is a vector. This
patch fixes these issues.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D148398

show more ...


Revision tags: llvmorg-16.0.2
# 2d4e8567 14-Apr-2023 Balaji V. Iyer <bviyer@gmail.com>

[mlir][math] Expand math.powf to exp, log and multiply

Powf functions are pushed directly to libm. This is problematic for
situations where libm is not available. This patch will decompose the
powf

[mlir][math] Expand math.powf to exp, log and multiply

Powf functions are pushed directly to libm. This is problematic for
situations where libm is not available. This patch will decompose the
powf function into log of exponent multiplied by log of base and raise
it to the exp.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D148164

show more ...


# be911578 13-Apr-2023 Balaji V. Iyer <bviyer@gmail.com>

[mlir][math] Expand math.round to truncate, compare and increment.

Round functions are pushed directly to libm. This is problematic for
situations where libm is not available. This patch will decomp

[mlir][math] Expand math.round to truncate, compare and increment.

Round functions are pushed directly to libm. This is problematic for
situations where libm is not available. This patch will decompose the
roundf function by adding 0.5 to positive number to input
(subtracting for negative) following by a truncate.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D148026

show more ...


# 4da96515 13-Apr-2023 Balaji V. Iyer <bviyer@gmail.com>

[mlir][math] Expand math.exp2 to use math.exp.

Exp2 functions are pushed directly to libm. This is problematic for
situations where libm is not available. This patch will expand the exp2
function to

[mlir][math] Expand math.exp2 to use math.exp.

Exp2 functions are pushed directly to libm. This is problematic for
situations where libm is not available. This patch will expand the exp2
function to use exp2 with the input multiplied by ln2 (natural log).

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D148064

show more ...


# 2217888d 11-Apr-2023 Balaji V. Iyer <bviyer@gmail.com>

[mlir][math] Expand math.ceilf to truncate, compares and increments

Ceilf are pushed directly to libm. This is problematic for
situations where libm is not available. This patch will break down
a ce

[mlir][math] Expand math.ceilf to truncate, compares and increments

Ceilf are pushed directly to libm. This is problematic for
situations where libm is not available. This patch will break down
a ceilf function to truncate followed by an increment if the
truncated value is smaller than the input value.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D147974

show more ...


12