[all-commits] [llvm/llvm-project] b33a13: [mlir][arith] Add support for expanding arith.maxn...
Han-Chung Wang via All-commits
all-commits at lists.llvm.org
Wed Dec 20 10:35:26 PST 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b33a131c828437efff36179458562e62774da881
https://github.com/llvm/llvm-project/commit/b33a131c828437efff36179458562e62774da881
Author: Han-Chung Wang <hanhan0912 at gmail.com>
Date: 2023-12-20 (Wed, 20 Dec 2023)
Changed paths:
M mlir/lib/Dialect/Arith/Transforms/ExpandOps.cpp
M mlir/test/Dialect/Arith/expand-ops.mlir
Log Message:
-----------
[mlir][arith] Add support for expanding arith.maxnumf/minnumf ops. (#75989)
The maxnum/minnum semantics can be found at
https://llvm.org/docs/LangRef.html#llvm-minnum-intrinsic.
The revision also updates function names in lit tests to match op name.
Take arith.maxnumf as example:
```
func.func @maxnumf(%lhs: f32, %rhs: f32) -> f32 {
%result = arith.maxnumf %lhs, %rhs : f32
return %result : f32
}
```
will be expanded to
```
func.func @maxnumf(%lhs: f32, %rhs: f32) -> f32 {
%0 = arith.cmpf ugt, %lhs, %rhs : f32
%1 = arith.select %0, %lhs, %rhs : f32
%2 = arith.cmpf uno, %lhs, %lhs : f32
%3 = arith.select %2, %rhs, %1 : f32
return %3 : f32
}
```
Case 1: Both LHS and RHS are not NaN; LHS > RHS
In this case, `%1` is LHS. `%3` and `%1` have the same value, so `%3` is
LHS.
Case 2: LHS is NaN and RHS is not NaN
In this case, `%2` is true, so `%3` is always RHS.
Case 3: LHS is not NaN and RHS is NaN
In this case, `%0` is true and `%1` is LHS. `%2` is false, so `%3` and
`%1` have the same value, which is LHS.
Case 4: Both LHS and RHS are NaN:
`%1` and RHS are all NaN, so the result is still NaN.
More information about the All-commits
mailing list