diff gcc/dse.c @ 36:855418dad1a3

gcc-4.4-20091020
author e075725
date Tue, 22 Dec 2009 21:19:31 +0900
parents 58ad6c70ea60
children 77e2b8dfacca
line wrap: on
line diff
--- a/gcc/dse.c	Thu Sep 24 13:21:57 2009 +0900
+++ b/gcc/dse.c	Tue Dec 22 21:19:31 2009 +0900
@@ -1070,6 +1070,8 @@
 {
   rtx mem_address = XEXP (mem, 0);
   rtx expanded_address, address;
+  int expanded;
+
   /* Make sure that cselib is has initialized all of the operands of
      the address before asking it to do the subst.  */
 
@@ -1114,72 +1116,88 @@
       fprintf (dump_file, "\n");
     }
 
-  /* Use cselib to replace all of the reg references with the full
-     expression.  This will take care of the case where we have 
-
-     r_x = base + offset;
-     val = *r_x;
+  /* First see if just canon_rtx (mem_address) is const or frame,
+     if not, try cselib_expand_value_rtx and call canon_rtx on that.  */
+  address = NULL_RTX;
+  for (expanded = 0; expanded < 2; expanded++)
+    {
+      if (expanded)
+	{
+	  /* Use cselib to replace all of the reg references with the full
+	     expression.  This will take care of the case where we have 
+
+	     r_x = base + offset;
+	     val = *r_x;
    
-     by making it into 
-
-     val = *(base + offset);  
-  */
-
-  expanded_address = cselib_expand_value_rtx (mem_address, scratch, 5);
-
-  /* If this fails, just go with the mem_address.  */
-  if (!expanded_address)
-    expanded_address = mem_address;
-
-  /* Split the address into canonical BASE + OFFSET terms.  */
-  address = canon_rtx (expanded_address);
-
-  *offset = 0;
-
-  if (dump_file)
-    {
-      fprintf (dump_file, "\n   after cselib_expand address: ");
-      print_inline_rtx (dump_file, expanded_address, 0);
-      fprintf (dump_file, "\n");
-
-      fprintf (dump_file, "\n   after canon_rtx address: ");
-      print_inline_rtx (dump_file, address, 0);
-      fprintf (dump_file, "\n");
-    }
-
-  if (GET_CODE (address) == CONST)
-    address = XEXP (address, 0);
-
-  if (GET_CODE (address) == PLUS && GET_CODE (XEXP (address, 1)) == CONST_INT)
-    {
-      *offset = INTVAL (XEXP (address, 1));
-      address = XEXP (address, 0);
-    }
-
-  if (const_or_frame_p (address))
-    {
-      group_info_t group = get_group_info (address);
+	     by making it into 
+
+	     val = *(base + offset);  */
+
+	  expanded_address = cselib_expand_value_rtx (mem_address,
+						      scratch, 5);
+
+	  /* If this fails, just go with the address from first
+	     iteration.  */
+	  if (!expanded_address)
+	    break;
+	}
+      else
+	expanded_address = mem_address;
+
+      /* Split the address into canonical BASE + OFFSET terms.  */
+      address = canon_rtx (expanded_address);
+
+      *offset = 0;
 
       if (dump_file)
-	fprintf (dump_file, "  gid=%d offset=%d \n", group->id, (int)*offset);
-      *base = NULL;
-      *group_id = group->id;
+	{
+	  if (expanded)
+	    {
+	      fprintf (dump_file, "\n   after cselib_expand address: ");
+	      print_inline_rtx (dump_file, expanded_address, 0);
+	      fprintf (dump_file, "\n");
+	    }
+
+	  fprintf (dump_file, "\n   after canon_rtx address: ");
+	  print_inline_rtx (dump_file, address, 0);
+	  fprintf (dump_file, "\n");
+	}
+
+      if (GET_CODE (address) == CONST)
+	address = XEXP (address, 0);
+
+      if (GET_CODE (address) == PLUS
+	  && GET_CODE (XEXP (address, 1)) == CONST_INT)
+	{
+	  *offset = INTVAL (XEXP (address, 1));
+	  address = XEXP (address, 0);
+	}
+
+      if (const_or_frame_p (address))
+	{
+	  group_info_t group = get_group_info (address);
+
+	  if (dump_file)
+	    fprintf (dump_file, "  gid=%d offset=%d \n",
+		     group->id, (int)*offset);
+	  *base = NULL;
+	  *group_id = group->id;
+	  return true;
+	}
     }
-  else
+
+  *base = cselib_lookup (address, Pmode, true);
+  *group_id = -1;
+
+  if (*base == NULL)
     {
-      *base = cselib_lookup (address, Pmode, true);
-      *group_id = -1;
-
-      if (*base == NULL)
-	{
-	  if (dump_file)
-	    fprintf (dump_file, " no cselib val - should be a wild read.\n");
-	  return false;
-	}
       if (dump_file)
-	fprintf (dump_file, "  varying cselib base=%d offset = %d\n", 
-		 (*base)->value, (int)*offset);
+	fprintf (dump_file, " no cselib val - should be a wild read.\n");
+      return false;
     }
+  if (dump_file)
+    fprintf (dump_file, "  varying cselib base=%d offset = %d\n", 
+	     (*base)->value, (int)*offset);
   return true;
 }