3 Commits

Author SHA1 Message Date
Hank
e1b9d033cd
[MLIR][Math] Fix math.ceil expansion to avoid undefined behavior on Inf/NaN (#170028)
Fixes #151786

The original `ceilf` expansion lowers to `fptosi`, which produces poison
for Inf, and any subsequent use leads to undefined behavior. This patch
adds a safe path, similar to the existing `round` expansion, for large
or special inputs and avoids the UB.
2026-02-11 12:36:32 -05:00
Jack
4b8ff4c63d
[mlir][math] Fix the semantics of math.clampf (#175012)
The `math.clampf` op is semantically incorrect when compared to both the
CUDA reference implementation and the SPIRV spec, both of which have a
clamp op.
- Fix the definition of `math.clampf` to agree with CUDA and SPIRV
- Explicitly state when `math.clampf` produces `ub.poison`
- Update the ExpandOps pass to reflect the corrected semantics
2026-01-19 10:49:01 +00:00
Fabian Mora
51a1aab643
[mlir][math] Add clampf and clean math ExpandOps API (#151153)
This patch adds the `clampf` operation to the math dialect. The
semantics op are defined as:
```
clampf(x, min_v, max_v) = max(min(x, min_v), max_v) 
```

The reasoning behind adding this operation is that some GPU vendors
offer specialized intrinsics for this operation, or subsets of this
operation. For example,
[__saturatef](https://docs.nvidia.com/cuda/cuda-math-api/cuda_math_api/group__CUDA__MATH__INTRINSIC__SINGLE.html#group__cuda__math__intrinsic__single_1ga2c84f08e0db7117a14509d21c3aec04e)
in NVIDIA GPUs, or `__builtin_amdgcn_fmed3f` in AMD GPUs.

This patch also removes `test-expand-math` in favor of
`math-expand-ops`.
Finally, it removes individual expansion population API calls like
`populateExpandCoshPattern` in favor of:
```C++
void populateExpansionPatterns(RewritePatternSet &patterns,
                               ArrayRef<StringRef> opMnemonics = {});
```
2025-09-02 12:55:14 -04:00