[PATCH][RTL] Fix PR87852

Richard Biener rguenther@suse.de
Fri Nov 2 13:40:00 GMT 2018


The following fixes PR87852, a latent bug in fwprop which when verifying
whether it may propagate a use from its definition site has a shortcut

  /* Check if the reg in USE has only one definition.  We already
     know that this definition reaches use, or we wouldn't be here.
     However, this is invalid for hard registers because if they are
     live at the beginning of the function it does not mean that we
     have an uninitialized access.  */
  regno = DF_REF_REGNO (use);
  def = DF_REG_DEF_CHAIN (regno);
  if (def
      && DF_REF_NEXT_REG (def) == NULL
      && regno >= FIRST_PSEUDO_REGISTER)
    return false;

not considering the case of a loop where the def might not dominate
the use.  In fact earlier code in the very same function does
handle this case but only for the case where we'd try propagating
a later def into an earlier use.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

OK for trunk?

Thanks,
Richard.

2018-11-02  Richard Biener  <rguenther@suse.de>

	PR rtl-optimization/87852
	* fwprop.c (use_killed_between): Only consider single-defs of the
	use in the definition stmt that dominate it.

diff --git a/gcc/fwprop.c b/gcc/fwprop.c
index 0fca0f1edbc..cd44c0ef637 100644
--- a/gcc/fwprop.c
+++ b/gcc/fwprop.c
@@ -767,7 +767,11 @@ use_killed_between (df_ref use, rtx_insn *def_insn, rtx_insn *target_insn)
   def = DF_REG_DEF_CHAIN (regno);
   if (def
       && DF_REF_NEXT_REG (def) == NULL
-      && regno >= FIRST_PSEUDO_REGISTER)
+      && regno >= FIRST_PSEUDO_REGISTER
+      && (BLOCK_FOR_INSN (DF_REF_INSN (def)) == def_bb
+	  ? DF_INSN_LUID (DF_REF_INSN (def)) < DF_INSN_LUID (def_insn)
+	  : dominated_by_p (CDI_DOMINATORS,
+			    def_bb, BLOCK_FOR_INSN (DF_REF_INSN (def)))))
     return false;
 
   /* Check locally if we are in the same basic block.  */



More information about the Gcc-patches mailing list