Index: gcc/tree-cfg.c
===================================================================
--- gcc/tree-cfg.c      (revision 178354)
+++ gcc/tree-cfg.c      (working copy)
@@ -3713,6 +3713,7 @@ verify_gimple_assign_ternary (gimple stm

     case DOT_PROD_EXPR:
     case REALIGN_LOAD_EXPR:
+    case VEC_SHUFFLE_EXPR:
       /* FIXME.  */
       return false;

can you do some basic verification here?  At least what you document
in tree.def should be verified here.

Index: gcc/tree-vect-generic.c
===================================================================
--- gcc/tree-vect-generic.c     (revision 178354)
+++ gcc/tree-vect-generic.c     (working copy)
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3.
 #include "tree-pass.h"
 #include "flags.h"
 #include "ggc.h"
+#include "diagnostic.h"

I don't see where you need this, nor a Makefile.in change.

+/* Build a reference to the element of the vector VECT. Function

two spaces after a '.'

+      if (TREE_CODE (vect) == VECTOR_CST)
+        {
+            unsigned i;
+            tree vals = TREE_VECTOR_CST_ELTS (vect);
+            for (i = 0; vals; vals = TREE_CHAIN (vals), ++i)
+              if (i == index)

operand_equal_p

+      else if (TREE_CODE (vect) == SSA_NAME)
+        {
+          tree el;
+          gimple vectdef = SSA_NAME_DEF_STMT (vect);
+          if (gimple_assign_single_p (vectdef)
+              && (el = vector_element (gsi, gimple_assign_rhs1 (vectdef),
+                                       idx, ptmpvec))
+                 != error_mark_node)
+            return el;

I think it's a premature optimization to look up the defining statement here.

+  if (need_asgn)
+    {
+      TREE_ADDRESSABLE (tmpvec) = 1;

this should be at the point we call create_tmp_var.

+      asgn = gimple_build_assign (tmpvec, vect);

and I think this needs gimplification for the case of a non-constant
non-SSA name vect.  But maybe that never happens
(consider (v4si){a, b, c, d}[i]).

+  indextype = build_index_type (size_int (maxval));
+  arraytype = build_array_type (TREE_TYPE (type), indextype);

there is now build_array_type_nelts conveniently available.

+                 idx, NULL_TREE, NULL_TREE);
+
+
+}

excess vertical space.

+static void
+lower_vec_shuffle (gimple_stmt_iterator *gsi, location_t loc)
+{
+#define TRAP_RETURN(new_stmt, stmt, gsi, vec0) \
+do { \
+  new_stmt = gimple_build_call (built_in_decls[BUILT_IN_TRAP], 0); \
+  gsi_insert_before (gsi, new_stmt,  GSI_SAME_STMT); \
+  split_block (gimple_bb (new_stmt), new_stmt); \
+  new_stmt = gimple_build_assign (gimple_call_lhs (stmt), vec0); \
+  gsi_replace (gsi, new_stmt, false); \
+  return; \
+} while (0)

I don't like such defines - this instead asks for factoring the lowering
to a function that returns a failure state and the caller doing the
TRAP_RETURN in case of failure.

+    }
+
+

excess vertical space (please double-check your patches for these simple
stylistic issues).

+  if (vec0 == vec1)
+    {

operand_equal_p

+          if (idxval == error_mark_node)
+            {
+              warning_at (loc, 0, "Invalid shuffling mask index %i", i);
+              TRAP_RETURN (new_stmt, stmt, gsi, vec0);

ah, here is the diagnostic.  I think you should change that to

  if (warning_at (loc, 0, ...))
    inform (loc, "if this code is reached, the program will abort");

as we say elsewhere when inserting traps.

+  if (code == VEC_SHUFFLE_EXPR)
+    {
+      lower_vec_shuffle (gsi, gimple_location (stmt));
+      gimple_set_modified (gsi_stmt (*gsi), true);
+      update_stmt (gsi_stmt (*gsi));

I don't think you need the gimple_set_modified call.

 /* Use this to lower vector operations introduced by the vectorizer,
    if it may need the bit-twiddling tricks implemented in this file.  */

+

spurious white-space change.

 static bool
-gate_expand_vector_operations (void)
+gate_expand_vector_operations_noop (void)
 {
-  return flag_tree_vectorize != 0;
+  return optimize == 0;
 }

but I think we already have this change in-tree.  Your patch needs updating
(we have _ssa, not _noop).

Index: gcc/passes.c
===================================================================
--- gcc/passes.c        (revision 178354)
+++ gcc/passes.c        (working copy)
@@ -1354,7 +1354,6 @@ init_optimization_passes (void)
          NEXT_PASS (pass_vectorize);
            {
              struct opt_pass **p = &pass_vectorize.pass.sub;
-             NEXT_PASS (pass_lower_vector_ssa);
              NEXT_PASS (pass_dce_loop);
            }
           NEXT_PASS (pass_predcom);
@@ -1366,6 +1365,7 @@ init_optimization_passes (void)
          NEXT_PASS (pass_lim);
          NEXT_PASS (pass_tree_loop_done);
        }
+      NEXT_PASS (pass_lower_vector_ssa);

This change should not be neccesary.

