Patchwork PATCH: Remove redundant instructions after regcprop

login
register
mail settings
Submitter Paulo J. Matos
Date Aug. 2, 2012, 1:55 p.m.
Message ID <jve0s5$r54$1@dough.gmane.org>
Download mbox | patch
Permalink /patch/174762/
State New
Headers show

Comments

Paulo J. Matos - Aug. 2, 2012, 1:55 p.m.
2012-08-02   Paulo Matos <Paulo.Matos@csr.com>

     PR middle-end/54154
     * regcprop.c (copy_value): remove check for redundant moves.
     * regcprop.c (copyprop_hardreg_forward_1): add check for redundant
     moves, remove instructions if redundant.

Patch

--- //depot/bc/main/devHost/gcc46/gcc/gcc/regcprop.c	2011-09-06 14:29:15.000000000 0100
+++ /home/pm18/p4ws/pm18_binutils/bc/main/devHost/gcc46/gcc/gcc/regcprop.c	2011-09-06 14:29:15.000000000 0100
@@ -301,11 +301,8 @@ 
   unsigned int dn, sn;
   unsigned int i;
 
-  /* ??? At present, it's possible to see noop sets.  It'd be nice if
-     this were cleaned up beforehand...  */
-  if (sr == dr)
-    return;
-
+  gcc_assert (dr != sr);
+  
   /* Do not propagate copies to the stack pointer, as that can leave
      memory accesses with no scheduling dependency on the stack update.  */
   if (dr == STACK_POINTER_REGNUM)
@@ -734,9 +731,9 @@ 
 copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
 {
   bool anything_changed = false;
-  rtx insn;
+  rtx insn, next;
 
-  for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn))
+  FOR_BB_INSNS_SAFE (bb, insn, next)
     {
       int n_ops, i, alt, predicated;
       bool is_asm, any_replacements;
@@ -755,10 +752,7 @@ 
 					   insn, vd);
 	    }
 
-	  if (insn == BB_END (bb))
-	    break;
-	  else
-	    continue;
+	  continue;
 	}
 
       set = single_set (insn);
@@ -966,10 +960,19 @@ 
 
       /* Notice copies.  */
       if (set && REG_P (SET_DEST (set)) && REG_P (SET_SRC (set)))
-	copy_value (SET_DEST (set), SET_SRC (set), vd);
-
-      if (insn == BB_END (bb))
-	break;
+      {
+        unsigned int dr = REGNO (SET_DEST (set));
+        unsigned int sr = REGNO (SET_SRC (set));
+        
+        if(dr == sr)
+        {
+          /* noop set */
+          delete_insn_and_edges(insn);
+        } 
+        else
+          copy_value (SET_DEST (set), SET_SRC (set), vd);
+      }
+      
     }
 
   return anything_changed;