@@ -3782,6 +3782,7 @@ void
df_note_add_problem (void)
{
df_add_problem (&problem_NOTE);
+ df->can_trust_reg_unused_notes = true;
}
@@ -614,6 +614,10 @@ public:
/* True if someone added or deleted something from regs_ever_live so
that the entry and exit blocks need be reprocessed. */
bool redo_entry_and_exit;
+
+ /* True if REG_UNUSED notes are up-to-date enough to be free of false
+ positives. */
+ bool can_trust_reg_unused_notes;
};
#define DF_SCAN_BB_INFO(BB) (df_scan_get_bb_info ((BB)->index))
@@ -2640,6 +2640,9 @@ execute_one_pass (opt_pass *pass)
/* Do it! */
todo_after = pass->execute (cfun);
+ if (df)
+ df->can_trust_reg_unused_notes = false;
+
if (todo_after & TODO_discard_function)
{
/* Stop timevar. */
@@ -820,6 +820,7 @@ copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
if (set
&& !RTX_FRAME_RELATED_P (insn)
&& NONJUMP_INSN_P (insn)
+ && df->can_trust_reg_unused_notes
&& !may_trap_p (set)
&& find_reg_note (insn, REG_UNUSED, SET_DEST (set))
&& !side_effects_p (SET_SRC (set))
@@ -878,7 +879,8 @@ copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
would clobbers. */
for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
{
- if (REG_NOTE_KIND (link) == REG_UNUSED)
+ if (df->can_trust_reg_unused_notes
+ && REG_NOTE_KIND (link) == REG_UNUSED)
{
kill_value (XEXP (link, 0), vd);
/* Furthermore, if the insn looked like a single-set,
@@ -1572,7 +1572,9 @@ single_set_2 (const rtx_insn *insn, const_rtx pat)
sets are found in the insn, we check them. */
if (!set_verified)
{
- if (find_reg_note (insn, REG_UNUSED, SET_DEST (set))
+ if (df
+ && df->can_trust_reg_unused_notes
+ && find_reg_note (insn, REG_UNUSED, SET_DEST (set))
&& !side_effects_p (set))
set = NULL;
else
@@ -1580,7 +1582,9 @@ single_set_2 (const rtx_insn *insn, const_rtx pat)
}
if (!set)
set = sub, set_verified = 0;
- else if (!find_reg_note (insn, REG_UNUSED, SET_DEST (sub))
+ else if (!df
+ || !df->can_trust_reg_unused_notes
+ || !find_reg_note (insn, REG_UNUSED, SET_DEST (sub))
|| side_effects_p (sub))
return NULL_RTX;
break;
new file mode 100644
@@ -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 ();
+}