Fixes miscompilation in spaceship_replacement optimization.
Corrects an optimization that incorrectly simplified multiple comparisons.
An optimization pass, phiopt, incorrectly simplified sequences of three comparisons (e.g., checking if a value is equal to, less than, or greater than another) into a single comparison. This led to miscompilation, particularly when dealing with floating-point comparisons and HONOR_NANS. The fix ensures that the optimization correctly distinguishes between different comparison outcomes and preserves the necessary checks, resolving the issue for the affected test cases.
In Details
The phiopt pass's spaceship_replacement optimization, intended to reduce three-way comparisons (e.g., <=>) to a single comparison, had a bug. It incorrectly handled the logic for distinguishing between comparison outcomes, especially when HONOR_NANS was involved and when intermediate basic blocks were present. The bug manifested as incorrect checks for whether comparisons were distinct, leading to the removal of necessary checks and subsequent miscompilation. The patch corrects the logic for determining the distinctness of comparisons and correctly handling edge cases related to `HONO…
- phiopt
- An optimization pass in GCC that deals with PHI nodes, which are used to represent values that may come from different control flow paths.
- spaceship_replacement
- An optimization within
phioptthat attempts to replace multiple conditional branches representing comparisons (like<,>,==) with a more efficient single comparison or equivalent construct. - PHI node
- A construct in Static Single Assignment (SSA) form that merges values from different control-flow paths. For example,
x = PHI(a, b)meansxisaif control came from one path, andbif control came from another. - HONOR_NANS
- A target-specific macro or setting that indicates whether floating-point comparisons should correctly handle Not-a-Number (NaN) values according to IEEE 754 standards.
- miscompilation
- When a compiler produces incorrect or unexpected output code for a given source code input.