aarch64: Prevent trapping FP comparisons from becoming conditional.
Ensures floating-point comparisons that can trap (e.g., with NaNs) remain unconditional on AArch64.
On AArch64, conditional floating-point comparisons can mask exceptions, such as those raised by quiet NaNs. This commit modifies the code generation to prevent such trapping comparisons from becoming conditional, preserving the expected exception behavior. It ensures that operations like (a < b) & (c < d) correctly raise exceptions if c or d is a quiet NaN when a < b is false. New tests are added to verify this behavior.
In Details
The aarch64_gen_ccmp_next hook is modified to reject FP comparisons that raise Invalid exceptions (marked by CCFPE) when they are converted into conditional comparisons. Conditional comparisons (cset after a preceding condition) do not evaluate their operands if the condition is false, thus failing to trigger the exception. This change preserves exception observability, particularly for quiet NaNs, unless options like -ffinite-math-only or -fno-trapping-math are used, which make exceptions unobservable. This is anchored with existing early-exit logic to avoid quadratic expansion.
- NaN
- Not a Number. A special floating-point value indicating an undefined or unrepresentable result, such as from dividing zero by zero. Quiet NaNs propagate through calculations without signaling exceptions, while signaling NaNs can raise exceptions.
- AArch64
- The 64-bit ARM architecture, commonly used in mobile devices and servers. GCC has specific code generation targets for this architecture.
- CCFPE
- A floating-point condition code mode on AArch64 that indicates a comparison which raises an Invalid exception for a quiet NaN. This is distinct from CCFPmode, which does not raise an exception for quiet NaNs.
- quiet NaN
- A type of NaN that propagates through floating-point operations without causing a floating-point exception. Signaling NaNs, in contrast, typically raise an exception upon use.