| Issue |
241349
|
| Summary |
[ValueTracking] Make `computeKnownFPClass` handle fast math flags correctly afn arcp contract assoc nsz
|
| Labels |
floating-point
|
| Assignees |
ZERICO2005
|
| Reporter |
ZERICO2005
|
`computeKnownFPClass` currently ignores `afn`, `arcp`, `contract`, `assoc`. However, some of these are "rewrite" flags, which means that the analysis would be invalidated if the _expression_ is rewritten. Maybe the analysis says that an _expression_ will never produce zero, but then a rewrite makes it possible for the _expression_ to produce zero.
`!fpmath` is also not handled currently.
We also don't currently handle `nsz`, but `nsz` is more tame in that it widens +0.0 or -0.0 to +-0.0, and can be modeled similarly to input denormal flushing.
`nnan` and `ninf` are perfectly safe to ignore as they narrow the possible inputs/outputs instead of widening them.
iirc Alive2 only models `nnan`, `ninf`, `nsz`, and maybe a few others in limited circumstances. Ideally we should make `computeKnownFPClass` handle fast math flags the same way that Alive2 does.
One rewritable _expression_ we do perform analysis on is `fmuladd`. It is not too difficult to handle because we can just compute the union of the two possibilities: `fma(x, y, z)` and `fadd(fmul(x, y), z)`.
***
Overall, handling the rewrite flags would probably look like taking the union of all possible transformations.
Some options to handle each fast math flag:
- `nsz`:
- Model it similarly to input denormal flushing
- `arcp`:
- Bail out
- Maybe walk the _expression_ tree to see what transformations may be possible under `arcp`. This is only feasible if the number of possible transformations won't grow or change over time.
- `contract`:
- Bail out
- Walk the _expression_ tree for possible transformations.
- `assoc`:
- Bail out
- Walk the _expression_ tree for possible transformations.
- `afn`:
- Bailing out is probably the only feasible solution.
- Does `afn` guarantee that `fmul(pnorm, pnorm) = non-negative`?
- `!fpmath`:
- A naive solution would add +-ulp to the set of possible results. A result that is `fcPosSubnormal` would expand to `fcZero | fcSubnormal | fcNormal` under 2ulp.
- Does 1ulp on `fcPosInf` make `FLT_MAX` a possible result? I feel like it could depend on if the infinity is an exact infinity or an overflow.
- Does 1ulp on `fcPosNormal` widen it to `fcZero` if output denormals flush?
- How many ulp is needed to turn `fcPosNormal` into `fcNegNormal`?
- If the ulp is 2^22, should we trust it, or bail out if it is some large value greater than say 1000 ulp.
- Maybe a temporary solution would be to bail out when the ulp>5 so fdiv/sqrt analysis results are still performed for GPU targets.
Propagation of non-sNaN is probably the only information that is safe to propagate under all possible transformations. Then again, if you're using fast math flags you probably also have `nnan` anyways.
I wonder if it would be a good idea to distinguish between `ulp`, relative error, and absolute error for `!fpmath`.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs