Cryolitia commented on issue #12681:
URL: https://github.com/apache/arrow/issues/12681#issuecomment-7125607220

   > Thank you [@Cryolitia](https://github.com/Cryolitia) . I'm not sure 
whether you are able to investigate any further, but I'm curious why 
`_GLIBCXX_ASSERTIONS` would trigger floating-point precision issues.
   For curiosity:
   
   ---
   
   
[`convert_mult_to_fma()`](https://github.com/gcc-mirror/gcc/blob/13a6f9865aa6d938389a8361159b32a715d072f1/gcc/tree-ssa-math-opts.cc#L3471-L3481)
 explicitly requires the multiplication and its consuming addition to belong to 
the same GIMPLE basic block:
   
   ```cpp
   if (gimple_bb (use_stmt) != gimple_bb (mul_stmt))
     return false;
   ```
   
   With `_GLIBCXX_ASSERTIONS`, the vector bounds checks [expand into 
conditional 
branches](https://github.com/gcc-mirror/gcc/blob/13a6f9865aa6d938389a8361159b32a715d072f1/libstdc%2B%2B-v3/include/bits/c%2B%2Bconfig#L642-L649).
 In the reference expression,
   
   ```cpp
   f * input[i + 1] + (1 - f) * input[i]
   ```
   
   the first multiplication ends up before the second bounds-check branch, 
while the addition is in the successor block. GCC therefore rejects contracting 
that multiplication. The second multiplication remains in the addition’s block 
and can be contracted instead.
   
   Without those branches, both multiplications are in the addition’s block. 
The pass [visits statements in 
order](https://github.com/gcc-mirror/gcc/blob/13a6f9865aa6d938389a8361159b32a715d072f1/gcc/tree-ssa-math-opts.cc#L6524-L6545),
 allowing the first multiplication to be contracted.
   
   This changes which intermediate product is rounded. Writing `R` for binary64 
rounding and `c` for the already-evaluated `1-f`, the two forms are:
   
   ```text
   R(f*h + R(c*l))
   R(R(f*h) + c*l)
   ```
   
   FMA rounds its combined multiplication and addition only once. Moving the 
intermediate rounding between the two products can therefore change the final 
result by 1 ULP. The assertion changes the control-flow graph and hence the 
eligible contraction; the resulting rounding difference explains why exact 
equality fails here.
   
   ---
   
   Generated by ChatGPT 6.1 Sol
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to