[llvm] [llvm] Don't combine repeated subnormal divisors (PR #149333)
Asher Mancinelli via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 17 17:50:11 PDT 2025
ashermancinelli wrote:
> To clarify, does this issue only occur when using DAZ? If you're using DAZ, the testcase here doesn't have the correct denormal-fp-math mode applied.
No, it occurs with DAZ and without. The failure mode of test the program is that a relative error calculation is (roughly) folded like so:
```
Where relerr, actual, expect, are all len4 vectors:
relerr = abs((actual-expect)/expect)
=> transformed by repeated fp divisors
relerr = abs((actual-expect)*(1/expect))
=> one element of expect is subnormal, so 1/expect -> inf
relerr = abs((actual-expect)*<INF, x, x, x>)
=> The ninf FMF causes INF -> poison
relerr = abs((actual-expect)*<poison, x, x, x>)
=> (actual-expect)*x is folded to y for the latter 3 elements of the vector
relerr = abs(<poison, y, y, y>)
=> with avx2, that poison is optimized to y so a broadcast can be used
relerr = abs(broadcast(y))
=> at runtime, the value of y in the first lane causes a failure
```
When the poison makes it all the way to codegen, it becomes a 0 which is fine for the purposes of the error calculation (`relerr = abs(0)`, which is fine) but when the broadcast optimization triggers it takes on the value of `y`, which is invalid, so the test fails. This is why the floating point control register doesn't really help us; the incorrect relative error calculation is in the data section already.
Does this answer your question? Apologies if I misunderstood!
https://github.com/llvm/llvm-project/pull/149333
More information about the llvm-commits
mailing list