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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebotcazou at gcc dot gnu.org

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
So interestingly distribute_notes sees

(gdb) p debug_rtx (i2)
(insn 78 22 24 3 (set (reg:XF 99)
        (float_extend:XF (mem/u/c:SF (symbol_ref/u:SI ("*.LC0") [flags 0x2]) [0
 S4 A32]))) 166 {*extendsfxf2_i387}
     (nil))

as may_trap_p (), but we did not place an EH note on this previously.  I'm not
sure how the RTL IL is sanitized but eventually we simply take what RTL
expansion yields as granted.

Given combine doesn't split blocks (otherwise it would have "fixed" this),
it might make more sense to always put the note on i3 or drop it if i3
cannot trap?

Alternatively we can of course fail the combination if there's any EH note
and it's not (only) i3 that may_trap_p ().

diff --git a/gcc/combine.cc b/gcc/combine.cc
index 53dcac92abc..65e11c3e682 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -14185,8 +14185,8 @@ distribute_notes (rtx notes, rtx_insn *from_insn,
rtx_insn *i3, rtx_insn *i2,
              gcc_assert (cfun->can_throw_non_call_exceptions);
              if (may_trap_p (i3))
                place = i3;
-             else if (i2 && may_trap_p (i2))
-               place = i2;
+             /* ???  Even if i2 may trap we cannot throw from there since
+                it will be not last in the BB.  Drop the EH in this case.  */
              /* ??? Otherwise assume we've combined things such that we
                 can now prove that the instructions can't trap.  Drop the
                 note in this case.  */

fixes the testcase (and loses the EH).

As said, I'm not sure about the EH state on RTL, insn_nothrow_p is false
on the original float_extent.

Reply via email to