[backport from gcc-4.8/trunk r188979 <mikpe@it.uu.se>]

gcc/

2012-06-26  Ulrich Weigand  <ulrich.weigand@linaro.org>

	PR tree-optimization/53729
	PR tree-optimization/53636
	* tree-vect-slp.c (vect_slp_analyze_bb_1): Delay call to
	vect_verify_datarefs_alignment until after statements have
	been marked as relevant/irrelevant.
	* tree-vect-data-refs.c (vect_verify_datarefs_alignment):
	Skip irrelevant statements.
	(vect_enhance_data_refs_alignment): Use STMT_VINFO_RELEVANT_P
	instead of STMT_VINFO_RELEVANT.
	(vect_get_data_access_cost): Do not check for supportable
	alignment before calling vect_get_load_cost/vect_get_store_cost.
	* tree-vect-stmts.c (vect_get_store_cost): Do not abort when
	handling unsupported alignment.
	(vect_get_load_cost): Likewise.

--- gcc-4.7.1/gcc/tree-vect-data-refs.c.~1~	2012-09-09 14:33:06.000000000 +0200
+++ gcc-4.7.1/gcc/tree-vect-data-refs.c	2012-09-09 14:33:23.000000000 +0200
@@ -1075,6 +1075,9 @@ vect_verify_datarefs_alignment (loop_vec
       gimple stmt = DR_STMT (dr);
       stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
 
+      if (!STMT_VINFO_RELEVANT_P (stmt_info))
+	continue;
+
       /* For interleaving, only the alignment of the first access matters. 
          Skip statements marked as not vectorizable.  */
       if ((STMT_VINFO_STRIDED_ACCESS (stmt_info)
@@ -1189,17 +1192,11 @@ vect_get_data_access_cost (struct data_r
   loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_info);
   int vf = LOOP_VINFO_VECT_FACTOR (loop_vinfo);
   int ncopies = vf / nunits;
-  bool supportable_dr_alignment = vect_supportable_dr_alignment (dr, true);
 
-  if (!supportable_dr_alignment)
-    *inside_cost = VECT_MAX_COST;
+  if (DR_IS_READ (dr))
+    vect_get_load_cost (dr, ncopies, true, inside_cost, outside_cost);
   else
-    {
-      if (DR_IS_READ (dr))
-        vect_get_load_cost (dr, ncopies, true, inside_cost, outside_cost);
-      else
-        vect_get_store_cost (dr, ncopies, inside_cost);
-    }
+    vect_get_store_cost (dr, ncopies, inside_cost);
 
   if (vect_print_dump_info (REPORT_COST))
     fprintf (vect_dump, "vect_get_data_access_cost: inside_cost = %d, "
@@ -1513,7 +1510,7 @@ vect_enhance_data_refs_alignment (loop_v
       stmt = DR_STMT (dr);
       stmt_info = vinfo_for_stmt (stmt);
 
-      if (!STMT_VINFO_RELEVANT (stmt_info))
+      if (!STMT_VINFO_RELEVANT_P (stmt_info))
 	continue;
 
       /* For interleaving, only the alignment of the first access
--- gcc-4.7.1/gcc/tree-vect-slp.c.~1~	2012-05-21 23:03:42.000000000 +0200
+++ gcc-4.7.1/gcc/tree-vect-slp.c	2012-09-09 14:33:23.000000000 +0200
@@ -2047,16 +2047,6 @@ vect_slp_analyze_bb_1 (basic_block bb)
       return NULL;
     }
 
-   if (!vect_verify_datarefs_alignment (NULL, bb_vinfo))
-    {
-      if (vect_print_dump_info (REPORT_UNVECTORIZED_LOCATIONS))
-        fprintf (vect_dump, "not vectorized: unsupported alignment in basic "
-                            "block.\n");
-
-      destroy_bb_vec_info (bb_vinfo);
-      return NULL;
-    }
-
   /* Check the SLP opportunities in the basic block, analyze and build SLP
      trees.  */
   if (!vect_analyze_slp (NULL, bb_vinfo))
@@ -2079,6 +2069,16 @@ vect_slp_analyze_bb_1 (basic_block bb)
       vect_mark_slp_stmts_relevant (SLP_INSTANCE_TREE (instance));
     }
 
+   if (!vect_verify_datarefs_alignment (NULL, bb_vinfo))
+    {
+      if (vect_print_dump_info (REPORT_UNVECTORIZED_LOCATIONS))
+        fprintf (vect_dump, "not vectorized: unsupported alignment in basic "
+                            "block.\n");
+
+      destroy_bb_vec_info (bb_vinfo);
+      return NULL;
+    }
+
   if (!vect_slp_analyze_operations (bb_vinfo))
     {
       if (vect_print_dump_info (REPORT_UNVECTORIZED_LOCATIONS))
--- gcc-4.7.1/gcc/tree-vect-stmts.c.~1~	2012-02-29 00:40:32.000000000 +0100
+++ gcc-4.7.1/gcc/tree-vect-stmts.c	2012-09-09 14:33:23.000000000 +0200
@@ -979,6 +979,16 @@ vect_get_store_cost (struct data_referen
         break;
       }
 
+    case dr_unaligned_unsupported:
+      {
+        *inside_cost = VECT_MAX_COST;
+
+        if (vect_print_dump_info (REPORT_COST))
+          fprintf (vect_dump, "vect_model_store_cost: unsupported access.");
+
+        break;
+      }
+
     default:
       gcc_unreachable ();
     }
@@ -1131,6 +1141,16 @@ vect_get_load_cost (struct data_referenc
         break;
       }
 
+    case dr_unaligned_unsupported:
+      {
+        *inside_cost = VECT_MAX_COST;
+
+        if (vect_print_dump_info (REPORT_COST))
+          fprintf (vect_dump, "vect_model_load_cost: unsupported access.");
+
+        break;
+      }
+
     default:
       gcc_unreachable ();
     }
