Issue 234364
Summary [KnownFPClass] Add `KnownFPClass::fadd(x, CRHS)` to rule out subnormal results.
Labels llvm:support, floating-point, llvm:analysis
Assignees
Reporter ZERICO2005
    A `KnownFPClass::fadd(x, CRHS)` routine would be useful for ruling out subnormal classes.

If C is sufficiently large, then `x + C` will never be subnormal, and will only produce zero if `x == -C`.

`C` is "sufficiently large" if `|C| > T` where `T` is `2^(expMin + precision - 1)`. Here is what the value of `T` is for the following types:
```
half     : |C| > 2^-4 (0.0625)
bfloat   : |C| > 2^-119
float    : |C| > 2^-103
double   : |C| > 2^-970
x86_fp80 : |C| > 2^-16319
fp128    : |C| > 2^-16270
```

Since `T` is a power of two, you can perform `|C| > T` by doing `ilogb(C) > ThresholdExp || (ilogb(C) == ThresholdExp && C.getExactLog2Abs() == INT_MIN)`, where `ThresholdExp` is `expMin + precision - 1`. 

To reduce complexity, we should only handle `fcNormal` constants, and should bail out for the `PPCDoubleDouble` type.

If you work on this, leave `KnownFPClass::fsub(x, CRHS)` and `KnownFPClass::fsub(CLHS, y)` for a future PR:
- `fsub(x, C)` most likely canonicalizes to `fadd(x, -C)`. They only differ in behavior for directed rounding modes, or when `C` is a negative-subnormal and denormals are flushed to positive-zero.
- `fsub(C, y)` has some utility for handling `1.0 - y`, but it would probably be good to implement and test that separately in a follow-up PR.

Also make sure you test these edge cases (also test negative constants too):
- `fadd(x, nextup(T))` rules out subnormal.
- `fadd(x, 2.0 * T)` rules out subnormal.
- `fadd(x, T)` cannot unconditionally rule out subnormal.
- `fadd(x, nextdown(T))` cannot unconditionally rule out subnormal.

Note that the threshold to rule out subnormal for `fma(x, y, C)` is different from `fadd(x, C)`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to