[PATCH] Preserve comparison operand order whem if-combining
Jeff Law
jeffrey.law@oss.qualcomm.com
Thu Oct 1 10:19:09 GMT 2026
On 9/29/26 4:24 AM, Richard Biener wrote:
> From: Gemini Reviewer <gemini@localhost>
>
> When combining conditions ifcombine_ifandif passes inner_cond_code as the
> first comparison and outer_cond_code as the second to
> maybe_fold_and_comparisons and maybe_fold_and_comparisons calls
> and_comparisons_1 with both comparison orders. Both defeats preserving
> IEEE exceptions of trapping outer comparisons which combine_comparisons
> handles, but only when the order of the comparisons is preserved correctly.
>
> This disables some optimization in and_comparisons_1 which only looks
> through SSA defs for the first comparison. This requires larger
> refactoring and the overall design seems dubious with recursions
> going in ways that with the swapping look exponential.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
>
> OK?
>
> Thanks,
> Richard.
>
> PR tree-optimization/53805
> * tree-ssa-ifcombine.cc (ifcombine_ifandif): Pass comparisons
> in the correct order.
> * gimple-fold.cc (and_comparisons_1): Add FIXME comment.
> (maybe_fold_and_comparisons): Do not call and_comparisons_1 with
> swapped comparisons.
>
> * gcc.dg/tree-ssa/fp-trapping-cmp-6.c: New testcase
> * gcc.dg/tree-ssa/fp-trapping-cmp-7.c: Likewise.
I kind of expected some fallout for the potential missed optimization
case, but I guess it never got covered.
OK for the trunk.
jeff
More information about the Gcc-patches
mailing list