gimple-fold: Improve boolean comparison handling
Fixes incorrect folding of boolean comparisons involving NaNs and outer comparisons.
This commit refines the same_bool_comparison_p function in gimple-fold to correctly test outer comparisons and handle NaNs when inverting boolean comparisons. Previously, incorrect folding occurred with certain comparisons involving NaNs or when boolean SSA names were defined by comparisons, potentially leading to wrong optimization results. New test cases are added to verify these fixes.
In Details
The gimple-fold pass's same_bool_comparison_p function incorrectly handled certain boolean comparisons. Specifically, it tested the code of the SSA name's definition instead of the outer comparison's code, and did not properly honor NaNs when inverting comparisons. This commit corrects these issues by testing the outer comparison's code and by passing HONOR_NANS to invert_tree_comparison. New tests cover these problematic cases.
- gimple-fold
- A GCC optimization pass that simplifies and transforms GIMPLE intermediate representation code.
- SSA name
- Static Single Assignment form. In SSA, every variable is assigned a unique version, denoted by an SSA name, each time it is assigned a value. This simplifies many optimizations.
- NaN
- Not a Number. A special floating-point value used to represent undefined or unrepresentable results, such as the result of 0/0. Comparisons involving NaNs have specific rules.