diff gcc/implicit-zee.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children
line wrap: on
line diff
--- a/gcc/implicit-zee.c	Tue May 25 18:58:51 2010 +0900
+++ b/gcc/implicit-zee.c	Tue Mar 22 17:18:12 2011 +0900
@@ -100,17 +100,17 @@
    }
    **********************************************
 
-   $ gcc -O2 -fsee bad_code.c (Turned on existing sign-extension elimination.)
+   $ gcc -O2 -fsee bad_code.c (Turned on existing sign-extension elimination)
      ........
      400315:       b8 4e 00 00 00          mov    $0x4e,%eax
      40031a:       0f af f8                imul   %eax,%edi
-     40031d:       89 ff                   mov    %edi,%edi  ---> Useless extend.
+     40031d:       89 ff                   mov    %edi,%edi  --> Useless extend
      40031f:       8b 04 bd 60 19 40 00    mov    0x401960(,%rdi,4),%eax
      400326:       c3                      retq
      ......
      400330:       ba 2d 00 00 00          mov    $0x2d,%edx
      400335:       0f af fa                imul   %edx,%edi
-     400338:       89 ff                   mov    %edi,%edi  ---> Useless extend.
+     400338:       89 ff                   mov    %edi,%edi  --> Useless extend
      40033a:       8b 04 bd 60 19 40 00    mov    0x401960(,%rdi,4),%eax
      400341:       c3                      retq
 
@@ -141,14 +141,14 @@
      return (unsigned long long)(z);
    }
 
-   $ gcc -O2 -fsee bad_code.c (Turned on existing sign-extension elimination.)
+   $ gcc -O2 -fsee bad_code.c (Turned on existing sign-extension elimination)
      ............
      400360:       8d 14 3e                lea    (%rsi,%rdi,1),%edx
      400363:       89 f8                   mov    %edi,%eax
      400365:       29 f0                   sub    %esi,%eax
      400367:       83 ff 65                cmp    $0x65,%edi
      40036a:       0f 43 c2                cmovae %edx,%eax
-     40036d:       89 c0                   mov    %eax,%eax ---> Useless extend.
+     40036d:       89 c0                   mov    %eax,%eax  --> Useless extend
      40036f:       c3                      retq
 
    $ gcc -O2 -fzee bad_code.c
@@ -165,16 +165,13 @@
    Usefulness :
    ----------
 
-   This pass reduces the dynamic instruction count of a compression benchmark by
-   2.8% and improves its run-time by about 1%.  The compression benchmark had the
-   following code sequence in a very hot region of code before ZEE optimized it :
+   This pass reduces the dynamic instruction count of a compression benchmark
+   by 2.8% and improves its run time by about 1%.  The compression benchmark
+   had the following code sequence in a very hot region of code before ZEE
+   optimized it :
 
    shr $0x5, %edx
-   mov %edx, %edx --> Useless zero-extend.
-
-   How to turn on ?
-   ----------------
-   -fzee -O2.  */
+   mov %edx, %edx --> Useless zero-extend  */
 
 
 #include "config.h"
@@ -193,7 +190,7 @@
 #include "expr.h"
 #include "insn-attr.h"
 #include "recog.h"
-#include "toplev.h"
+#include "diagnostic-core.h"
 #include "target.h"
 #include "timevar.h"
 #include "optabs.h"
@@ -240,31 +237,6 @@
   is_insn_merge_attempted[INSN_UID (insn)] = code;
 }
 
-/* Check to see if this zero-extend matches a pattern
-   that could be eliminated.  This is called via
-   for_each_rtx in function find_and_remove_ze.  */
-
-static int
-is_set_with_extension_DI (rtx *expr, void *data)
-{
-  /* Looking only for patterns of the type :
-     SET (REG:DI X) (ZERO_EXTEND (REG:SI x))
-   */
-
-  if (GET_CODE (*expr) == SET
-      && GET_MODE (SET_DEST (*expr)) == DImode
-      && GET_CODE (SET_DEST (*expr)) == REG
-      && GET_CODE (SET_SRC (*expr)) == ZERO_EXTEND
-      && GET_CODE (XEXP (SET_SRC (*expr),0)) == REG
-      && GET_MODE (XEXP (SET_SRC (*expr),0)) == SImode
-      && REGNO (SET_DEST (*expr)) == REGNO (XEXP (SET_SRC (*expr),0)))
-        {
-          *(rtx **)(data) = expr;
-          return 1;
-        }
-  return 0;
-}
-
 /* Given a insn (CURR_INSN) and a pointer to the SET rtx (ORIG_SET)
    that needs to be modified, this code modifies the SET rtx to a
    new SET rtx that zero_extends the right hand expression into a DImode
@@ -737,7 +709,7 @@
       VEC_free (rtx, heap, defs_list);
       VEC_free (rtx, heap, copies_list);
       if (dump_file)
-        fprintf (dump_file, "All definitions have been merged previously...\n");
+        fprintf (dump_file, "All definitions have been merged previously.\n");
       return true;
     }
 
@@ -754,7 +726,7 @@
      in this vector.  */
 
   vec = VEC_alloc (rtx, heap, 8);
-  for (defs_ix = 0; VEC_iterate (rtx, defs_list, defs_ix, def_insn); defs_ix++)
+  FOR_EACH_VEC_ELT (rtx, defs_list, defs_ix, def_insn)
     {
       merge_code = get_insn_status (def_insn);
       gcc_assert (merge_code == MERGE_NOT_ATTEMPTED);
@@ -773,7 +745,7 @@
 
   if (merge_successful)
     {
-      for (i = 0; VEC_iterate (rtx, copies_list, i, def_insn); i++)
+      FOR_EACH_VEC_ELT (rtx, copies_list, i, def_insn)
         {
           if (transform_ifelse (def_insn))
             {
@@ -800,7 +772,7 @@
           if (dump_file)
             fprintf (dump_file, "All merges were successful ....\n");
 
-          for (i = 0; VEC_iterate (rtx, vec, i, def_insn); i++)
+          FOR_EACH_VEC_ELT (rtx, vec, i, def_insn)
             {
               set_insn_status (def_insn, MERGE_SUCCESS);
             }
@@ -812,13 +784,13 @@
         }
       else
         {
-          /* Changes need not be cancelled explicitly as apply_change_group ()
-             does it.   Print list of definitions in the dump_file for debug
+          /* Changes need not be cancelled explicitly as apply_change_group
+             does it.  Print list of definitions in the dump_file for debug
              purposes.  This zero-extension cannot be deleted.  */
 
           if (dump_file)
             {
-              for (i = 0; VEC_iterate (rtx, vec, i, def_insn); i++)
+              FOR_EACH_VEC_ELT (rtx, vec, i, def_insn)
                 {
                   fprintf (dump_file, " Ummergable definitions : \n");
                   print_rtl_single (dump_file, def_insn);
@@ -838,50 +810,74 @@
   return false;
 }
 
-/* Goes through the instruction stream looking for zero-extends.  If the zero
-   extension instruction has atleast one def it adds it to a list of possible
-   candidates for deletion.  It returns the list of candidates.  */
+/* Carry information about zero-extensions while walking the RTL.  */
+
+struct zero_extend_info
+{
+  /* The insn where the zero-extension is.  */
+  rtx insn;
+
+  /* The list of candidates.  */
+  VEC (rtx, heap) *insn_list;
+};
+
+/* Add a zero-extend pattern that could be eliminated.  This is called via
+   note_stores from find_removable_zero_extends.  */
+
+static void
+add_removable_zero_extend (rtx x ATTRIBUTE_UNUSED, const_rtx expr, void *data)
+{
+  struct zero_extend_info *zei = (struct zero_extend_info *)data;
+  rtx src, dest;
+
+  /* We are looking for SET (REG:DI N) (ZERO_EXTEND (REG:SI N)).  */
+  if (GET_CODE (expr) != SET)
+    return;
+
+  src = SET_SRC (expr);
+  dest = SET_DEST (expr);
+
+  if (REG_P (dest)
+      && GET_MODE (dest) == DImode
+      && GET_CODE (src) == ZERO_EXTEND
+      && REG_P (XEXP (src, 0))
+      && GET_MODE (XEXP (src, 0)) == SImode
+      && REGNO (dest) == REGNO (XEXP (src, 0)))
+    {
+      if (get_defs (zei->insn, XEXP (src, 0), NULL))
+	VEC_safe_push (rtx, heap, zei->insn_list, zei->insn);
+      else if (dump_file)
+	{
+	  fprintf (dump_file, "Cannot eliminate zero-extension: \n");
+	  print_rtl_single (dump_file, zei->insn);
+	  fprintf (dump_file, "No defs. Could be extending parameters.\n");
+	}
+    }
+}
+
+/* Traverse the instruction stream looking for zero-extends and return the
+   list of candidates.  */
 
 static VEC (rtx,heap)*
 find_removable_zero_extends (void)
 {
-  VEC (rtx, heap) *zeinsn_list;
-  basic_block curr_block;
-  rtx curr_insn;
-  rtx *set_insn;
-  rtx which_reg;
-  int type ;
-  int has_defs;
+  struct zero_extend_info zei;
+  basic_block bb;
+  rtx insn;
 
-  zeinsn_list = VEC_alloc (rtx, heap, 8);
-  FOR_EACH_BB (curr_block)
-    {
-      FOR_BB_INSNS (curr_block, curr_insn)
-        {
-          if (!INSN_P (curr_insn))
-            continue;
+  zei.insn_list = VEC_alloc (rtx, heap, 8);
 
-          type = for_each_rtx (&PATTERN (curr_insn),
-                               is_set_with_extension_DI,
-                               (void *)&set_insn);
-
-          if (!type)
-            continue;
+  FOR_EACH_BB (bb)
+    FOR_BB_INSNS (bb, insn)
+      {
+	if (!NONDEBUG_INSN_P (insn))
+	  continue;
 
-          which_reg = XEXP (SET_SRC (*set_insn), 0);
-          has_defs = get_defs (curr_insn, which_reg, NULL);
-          if (has_defs)
-            VEC_safe_push (rtx, heap, zeinsn_list, curr_insn);
-          else if (dump_file)
-            {
-              fprintf (dump_file, "Cannot eliminate zero extension : \n");
-              print_rtl_single (dump_file, curr_insn);
-              fprintf (dump_file,
-                       "This has no defs. Could be extending parameters.\n");
-            }
-        }
-    }
-  return zeinsn_list;
+	zei.insn = insn;
+	note_stores (PATTERN (insn), add_removable_zero_extend, &zei);
+      }
+
+  return zei.insn_list;
 }
 
 /* This is the main function that checks the insn stream for redundant
@@ -906,13 +902,12 @@
 
   max_insn_uid = get_max_uid ();
 
-  is_insn_merge_attempted = XNEWVEC (enum insn_merge_code,
-                                     sizeof (enum insn_merge_code)* max_insn_uid);
+  is_insn_merge_attempted
+    = XNEWVEC (enum insn_merge_code,
+	       sizeof (enum insn_merge_code) * max_insn_uid);
 
   for (i = 0; i < max_insn_uid; i++)
-    {
-      is_insn_merge_attempted[i] = MERGE_NOT_ATTEMPTED;
-    }
+    is_insn_merge_attempted[i] = MERGE_NOT_ATTEMPTED;
 
   num_ze_opportunities = num_realized = 0;
 
@@ -920,7 +915,7 @@
 
   zeinsn_list = find_removable_zero_extends ();
 
-  for (ix = 0; VEC_iterate (rtx, zeinsn_list, ix, curr_insn); ix++)
+  FOR_EACH_VEC_ELT (rtx, zeinsn_list, ix, curr_insn)
     {
       num_ze_opportunities++;
       /* Try to combine the zero-extends with the definition here.  */
@@ -941,10 +936,8 @@
     }
 
   /* Delete all useless zero extensions here in one sweep.  */
-  for (ix = 0; VEC_iterate (rtx, zeinsn_del_list, ix, curr_insn); ix++)
-    {
-      delete_insn (curr_insn);
-    }
+  FOR_EACH_VEC_ELT (rtx, zeinsn_del_list, ix, curr_insn)
+    delete_insn (curr_insn);
 
   free (is_insn_merge_attempted);
   VEC_free (rtx, heap, zeinsn_list);