https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91425

Drea Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |126138

--- Comment #13 from Drea Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Drea Pinski from comment #11)
> 
> And invert_tree_comparison returns ERROR_MARK_NODE because the invert of `a
> u>= b` is `a < b` but > traps while u>= does not.
> 
> I think I know how to handle this. Basically invert_tree_comparison needs an
> extra argument where we can ignore trapping difference for phiopt/ifcombine
> since we are already doing the combining with a possible trapping case.
> Though only for `||` and only in the outer condition.

This worked:
```
diff --git a/gcc/tree-ssa-ifcombine.cc b/gcc/tree-ssa-ifcombine.cc
index 829baa66416..60f03d3e5fd 100644
--- a/gcc/tree-ssa-ifcombine.cc
+++ b/gcc/tree-ssa-ifcombine.cc
@@ -896,8 +896,11 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool
inner_inv,
          else if (inner_cond_code1 == ERROR_MARK)
            {
              // a && !b -> !(!a || b)
+             auto saved = flag_trapping_math;
+             flag_trapping_math = 0;
              outer_cond_code1 = invert_tree_comparison (outer_cond_code,
                                                         HONOR_NANS (larg));
+             flag_trapping_math = saved;
              if (outer_cond_code1 != ERROR_MARK)
                res = combine_comparisons (UNKNOWN_LOCATION, TRUTH_ORIF_EXPR,
                                           outer_cond_code1, inner_cond_code,
```

This is the patch on top of the patch set in PR 126138. phiopt needs a similar
one too. But we should have a better interface here ...


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126138
[Bug 126138] `fp0 == fp1 || fp0 CMP fp1` can be combined always even with
trapping

Reply via email to