In https://gcc.gnu.org/ml/gcc-patches/2012-01/msg00363.html, Tom reported an
ICE in the DWARF CFI pass because a frame-related insn was speculated by the
reorg pass and, therefore, disabled the optimization. It turns out that the
same code (when condition == const_true_rtx) can also duplicate frame-related
insns, leading to the same ICE in the DWARF CFI pass; we have run into that
building newlib for a port we are about to contribute.
Hence the attached patch, which disables the optimization in this case too and
adds a comment for both. Tested on SPARC/Solaris, applied on the mainline.
2014-11-11 Eric Botcazou <ebotca...@adacore.com>
* reorg.c (fill_slots_from_thread): Do not copy frame-related insns.
--
Eric Botcazou
Index: reorg.c
===================================================================
--- reorg.c (revision 217259)
+++ reorg.c (working copy)
@@ -2501,9 +2501,11 @@ fill_slots_from_thread (rtx_insn *insn,
/* There are two ways we can win: If TRIAL doesn't set anything
needed at the opposite thread and can't trap, or if it can
- go into an annulled delay slot. */
+ go into an annulled delay slot. But we want neither to copy
+ nor to speculate frame-related insns. */
if (!must_annul
- && (condition == const_true_rtx
+ && ((condition == const_true_rtx
+ && (own_thread || !RTX_FRAME_RELATED_P (trial)))
|| (! insn_sets_resource_p (trial, &opposite_needed, true)
&& ! may_trap_or_fault_p (pat)
&& ! RTX_FRAME_RELATED_P (trial))))