• [ConstantFolding] Why are FP32 calls folded in double-precision? • It recently came up inMaking sure you’re not a bot!that GCC was folding pow(x, 2.0)→x * x, even when doing so caused -fmath-errno to no longer be honoured. • The issue seems to equally apply to Clang (example), due to: SimplifyLibCallsfolding pow(x, 2.0) → x * x irrespective of errno settings; ConstantFoldingevaluating pow expressions in double-precision, irrespective of the original call precision. • My question is whether it is intentional that ConstantFolding evaluates FP32 calls with FP64 functions. • This can run into situations (as in the example above) where the original FP32 call would have flagged ERANGE, but because the function is evaluated in higher precision, it doesn’t. • IMO even ignoring flags, this behaviors undesirable since folding shouldn’t result in a different result than evaluation at runtime.

Article Summaries:

  • Summary

Developers have reported that both GCC and Clang perform constant folding of pow(x, 2.0) into x * x even when the original call is a single‑precision (FP32) function. The folding occurs in SimplifyLibCalls and ConstantFolding, which evaluate the expression in double precision (FP64) regardless of the original precision or the -fmath-errno flag. This can suppress expected error flags such as ERANGE, leading to results that differ from a runtime evaluation. The community is questioning whether this behavior is intentional and whether it should be corrected to preserve precision and error handling.

Sources: