public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] pro_and_epilogue: Call df_note_add_problem () if SHRINK_WRAPPING_ENABLED [PR112760]
@ 2023-12-02 10:44 Jakub Jelinek
  2023-12-02 11:04 ` Richard Sandiford
  0 siblings, 1 reply; 10+ messages in thread
From: Jakub Jelinek @ 2023-12-02 10:44 UTC (permalink / raw)
  To: Richard Sandiford, Eric Botcazou, Segher Boessenkool, Jeff Law
  Cc: gcc-patches

Hi!

The following testcase ICEs on x86_64-linux since df_note_add_problem ()
call has been added to mode switching.
The problem is that the pro_and_epilogue pass in
prepare_shrink_wrap -> copyprop_hardreg_forward_bb_without_debug_insn
uses regcprop.cc infrastructure which relies on accurate REG_DEAD/REG_UNUSED
notes.  E.g. regcprop.cc
  /* We need accurate notes.  Earlier passes such as if-conversion may
     leave notes in an inconsistent state.  */
  df_note_add_problem ();
documents that.  On the testcase below it is in particular the
      /* Detect obviously dead sets (via REG_UNUSED notes) and remove them.  */
      if (set
          && !RTX_FRAME_RELATED_P (insn)
          && NONJUMP_INSN_P (insn)
          && !may_trap_p (set)
          && find_reg_note (insn, REG_UNUSED, SET_DEST (set))
          && !side_effects_p (SET_SRC (set))
          && !side_effects_p (SET_DEST (set)))
        {
          bool last = insn == BB_END (bb);
          delete_insn (insn);
          if (last)
            break;
          continue;
        } 
case where a stale REG_UNUSED note breaks stuff up (added in vzeroupper
pass, redundant insn after it deleted later).

The following patch makes sure the notes are not stale if shrink wrapping
is enabled.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-12-02  Jakub Jelinek  <jakub@redhat.com>

	PR rtl-optimization/112760
	* function.cc (thread_prologue_and_epilogue_insns): If
	SHRINK_WRAPPING_ENABLED, call df_note_add_problem before calling
	df_analyze.

	* gcc.dg/pr112760.c: New test.

--- gcc/function.cc.jj	2023-11-07 08:32:01.699254744 +0100
+++ gcc/function.cc	2023-12-01 13:42:51.885189341 +0100
@@ -6036,6 +6036,11 @@ make_epilogue_seq (void)
 void
 thread_prologue_and_epilogue_insns (void)
 {
+  /* prepare_shrink_wrap uses copyprop_hardreg_forward_bb_without_debug_insn
+     which uses regcprop.cc functions which rely on accurate REG_UNUSED
+     and REG_DEAD notes.  */
+  if (SHRINK_WRAPPING_ENABLED)
+    df_note_add_problem ();
   df_analyze ();
 
   /* Can't deal with multiple successors of the entry block at the
--- gcc/testsuite/gcc.dg/pr112760.c.jj	2023-12-01 13:46:57.444746529 +0100
+++ gcc/testsuite/gcc.dg/pr112760.c	2023-12-01 13:46:36.729036971 +0100
@@ -0,0 +1,22 @@
+/* PR rtl-optimization/112760 */
+/* { dg-do run } */
+/* { dg-options "-O2 -fno-dce -fno-guess-branch-probability --param=max-cse-insns=0" } */
+/* { dg-additional-options "-m8bit-idiv -mavx" { target i?86-*-* x86_64-*-* } } */
+
+unsigned g;
+
+__attribute__((__noipa__)) unsigned short
+foo (unsigned short a, unsigned short b)
+{
+  unsigned short x = __builtin_add_overflow_p (a, g, (unsigned short) 0);
+  g -= g / b;
+  return x;
+}
+
+int
+main ()
+{
+  unsigned short x = foo (40, 6);
+  if (x != 0)
+    __builtin_abort ();
+}

	Jakub


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-12-04 19:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-02 10:44 [PATCH] pro_and_epilogue: Call df_note_add_problem () if SHRINK_WRAPPING_ENABLED [PR112760] Jakub Jelinek
2023-12-02 11:04 ` Richard Sandiford
2023-12-02 12:15   ` Eric Botcazou
2023-12-02 13:15     ` Richard Sandiford
2023-12-02 19:30       ` Richard Biener
2023-12-02 22:45   ` Jakub Jelinek
2023-12-04 10:59     ` Richard Sandiford
2023-12-04 17:30       ` [PATCH] Maintain a validity flag for REG_UNUSED notes [PR112760] (was Re: [PATCH] pro_and_epilogue: Call df_note_add_problem () if SHRINK_WRAPPING_ENABLED [PR112760]) Richard Sandiford
2023-12-04 19:34         ` Jakub Jelinek
2023-12-04  2:56   ` [PATCH] pro_and_epilogue: Call df_note_add_problem () if SHRINK_WRAPPING_ENABLED [PR112760] Andrew Pinski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).