Patchwork Property for vector lowering

login
register
mail settings
Submitter Marc Glisse
Date Dec. 6, 2012, 5:19 p.m.
Message ID <alpine.DEB.2.02.1212061700330.10023@stedding.saclay.inria.fr>
Download mbox | patch
Permalink /patch/204290/
State New
Headers show

Comments

Marc Glisse - Dec. 6, 2012, 5:19 p.m.
Hello,

this patch (for 4.9) introduces a property so we can check if vector 
operations have been lowered yet. It mimics the complex lowering property, 
and this required moving the -O0 vector lowering pass (otherwise it breaks 
many testcases with "covariant" in their name).

The tree-ssa-forwprop.c part was mostly to test if this was working, it 
may need some changes and I am fine with leaving it out for now. One day, 
lower_vec_perm might be able to do something cleverer than a constructor 
of element bitfields, for instance in the case where the vector is only 
twice the size of supported vector operations and both arguments are the 
same, then we could lower: vec_perm_expr(v,v,m) into 
{vec_perm_expr(v0,v1,m0), vec_perm_expr(v0,v1,m1)} where v0 is the first 
half of v, etc.

Passes bootstrap+testsuite on x86_64-linux (same number of PASS 
afterwards, it is hard to compare lines exactly with the pass numbering 
changes).

2012-12-06  Marc Glisse  <marc.glisse@inria.fr>

 	* tree-pass.h (PROP_gimple_lvec): New.
 	* passes.c (dump_properties): Handle PROP_gimple_lvec.
 	(init_optimization_passes): Move pass_lower_vector.
 	* tree-vect-generic.c (gate_expand_vector_operations_ssa): Test
 	PROP_gimple_lvec.
 	(pass_lower_vector): Provide PROP_gimple_lvec.
 	(pass_lower_vector_ssa): Likewise.
 	* cfgexpand.c (pass_expand): Require PROP_gimple_lvec.
 	* tree-ssa-forwprop.c (simplify_vector_constructor): Test
 	PROP_gimple_lvec.
Richard Guenther - March 19, 2013, 3:19 p.m.
On Thu, Dec 6, 2012 at 6:19 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> Hello,
>
> this patch (for 4.9) introduces a property so we can check if vector
> operations have been lowered yet. It mimics the complex lowering property,
> and this required moving the -O0 vector lowering pass (otherwise it breaks
> many testcases with "covariant" in their name).
>
> The tree-ssa-forwprop.c part was mostly to test if this was working, it may
> need some changes and I am fine with leaving it out for now. One day,
> lower_vec_perm might be able to do something cleverer than a constructor of
> element bitfields, for instance in the case where the vector is only twice
> the size of supported vector operations and both arguments are the same,
> then we could lower: vec_perm_expr(v,v,m) into {vec_perm_expr(v0,v1,m0),
> vec_perm_expr(v0,v1,m1)} where v0 is the first half of v, etc.
>
> Passes bootstrap+testsuite on x86_64-linux (same number of PASS afterwards,
> it is hard to compare lines exactly with the pass numbering changes).

Ok with leaving out the tree-ssa-forwprop.c changes for now.

Thanks,
Richard.

> 2012-12-06  Marc Glisse  <marc.glisse@inria.fr>
>
>         * tree-pass.h (PROP_gimple_lvec): New.
>         * passes.c (dump_properties): Handle PROP_gimple_lvec.
>         (init_optimization_passes): Move pass_lower_vector.
>         * tree-vect-generic.c (gate_expand_vector_operations_ssa): Test
>         PROP_gimple_lvec.
>         (pass_lower_vector): Provide PROP_gimple_lvec.
>         (pass_lower_vector_ssa): Likewise.
>         * cfgexpand.c (pass_expand): Require PROP_gimple_lvec.
>         * tree-ssa-forwprop.c (simplify_vector_constructor): Test
>         PROP_gimple_lvec.
>
> --
> Marc Glisse
> Index: passes.c
> ===================================================================
> --- passes.c    (revision 194247)
> +++ passes.c    (working copy)
> @@ -1305,21 +1305,20 @@ init_optimization_passes (void)
>    NEXT_PASS (pass_ipa_free_lang_data);
>    NEXT_PASS (pass_ipa_function_and_variable_visibility);
>    NEXT_PASS (pass_early_local_passes);
>      {
>        struct opt_pass **p = &pass_early_local_passes.pass.sub;
>        NEXT_PASS (pass_fixup_cfg);
>        NEXT_PASS (pass_init_datastructures);
>        NEXT_PASS (pass_expand_omp);
>
>        NEXT_PASS (pass_build_ssa);
> -      NEXT_PASS (pass_lower_vector);
>        NEXT_PASS (pass_early_warn_uninitialized);
>        NEXT_PASS (pass_rebuild_cgraph_edges);
>        NEXT_PASS (pass_inline_parameters);
>        NEXT_PASS (pass_early_inline);
>        NEXT_PASS (pass_all_early_optimizations);
>         {
>           struct opt_pass **p = &pass_all_early_optimizations.pass.sub;
>           NEXT_PASS (pass_remove_cgraph_callee_edges);
>           NEXT_PASS (pass_rename_ssa_copies);
>           NEXT_PASS (pass_ccp);
> @@ -1549,20 +1548,21 @@ init_optimization_passes (void)
>        NEXT_PASS (pass_uncprop);
>        NEXT_PASS (pass_local_pure_const);
>      }
>    NEXT_PASS (pass_tm_init);
>      {
>        struct opt_pass **p = &pass_tm_init.pass.sub;
>        NEXT_PASS (pass_tm_mark);
>        NEXT_PASS (pass_tm_memopt);
>        NEXT_PASS (pass_tm_edges);
>      }
> +  NEXT_PASS (pass_lower_vector);
>    NEXT_PASS (pass_lower_complex_O0);
>    NEXT_PASS (pass_asan_O0);
>    NEXT_PASS (pass_tsan_O0);
>    NEXT_PASS (pass_cleanup_eh);
>    NEXT_PASS (pass_lower_resx);
>    NEXT_PASS (pass_nrv);
>    NEXT_PASS (pass_mudflap_2);
>    NEXT_PASS (pass_cleanup_cfg_post_optimizing);
>    NEXT_PASS (pass_warn_function_noreturn);
>
> @@ -2769,20 +2769,22 @@ dump_properties (FILE *dump, unsigned in
>    if (props & PROP_ssa)
>      fprintf (dump, "PROP_ssa\n");
>    if (props & PROP_no_crit_edges)
>      fprintf (dump, "PROP_no_crit_edges\n");
>    if (props & PROP_rtl)
>      fprintf (dump, "PROP_rtl\n");
>    if (props & PROP_gimple_lomp)
>      fprintf (dump, "PROP_gimple_lomp\n");
>    if (props & PROP_gimple_lcx)
>      fprintf (dump, "PROP_gimple_lcx\n");
> +  if (props & PROP_gimple_lvec)
> +    fprintf (dump, "PROP_gimple_lvec\n");
>    if (props & PROP_cfglayout)
>      fprintf (dump, "PROP_cfglayout\n");
>  }
>
>  DEBUG_FUNCTION void
>  debug_properties (unsigned int props)
>  {
>    dump_properties (stderr, props);
>  }
>
> Index: tree-pass.h
> ===================================================================
> --- tree-pass.h (revision 194247)
> +++ tree-pass.h (working copy)
> @@ -142,20 +142,21 @@ struct simple_ipa_opt_pass
>  #define PROP_gimple_lcf                (1 << 1)        /* lowered control
> flow */
>  #define PROP_gimple_leh                (1 << 2)        /* lowered eh */
>  #define PROP_cfg               (1 << 3)
>  #define PROP_ssa               (1 << 5)
>  #define PROP_no_crit_edges      (1 << 6)
>  #define PROP_rtl               (1 << 7)
>  #define PROP_gimple_lomp       (1 << 8)        /* lowered OpenMP directives
> */
>  #define PROP_cfglayout         (1 << 9)        /* cfglayout mode on RTL */
>  #define PROP_gimple_lcx                (1 << 10)       /* lowered complex
> */
>  #define PROP_loops             (1 << 11)       /* preserve loop structures
> */
> +#define PROP_gimple_lvec       (1 << 12)       /* lowered vector */
>
>  #define PROP_trees \
>    (PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp)
>
>  /* To-do flags.  */
>  #define TODO_ggc_collect               (1 << 1)
>  #define TODO_verify_ssa                        (1 << 2)
>  #define TODO_verify_flow               (1 << 3)
>  #define TODO_verify_stmts              (1 << 4)
>  #define TODO_cleanup_cfg               (1 << 5)
> Index: tree-ssa-forwprop.c
> ===================================================================
> --- tree-ssa-forwprop.c (revision 194247)
> +++ tree-ssa-forwprop.c (working copy)
> @@ -2855,28 +2855,30 @@ simplify_vector_constructor (gimple_stmt
>      }
>    if (i < nelts)
>      return false;
>
>    if (maybe_ident)
>      gimple_assign_set_rhs_from_tree (gsi, orig);
>    else
>      {
>        tree mask_type, *mask_elts;
>
> -      if (!can_vec_perm_p (TYPE_MODE (type), false, sel))
> +      if (cfun->curr_properties & PROP_gimple_lvec
> +         && !can_vec_perm_p (TYPE_MODE (type), false, sel))
>         return false;
>        mask_type
>         = build_vector_type (build_nonstandard_integer_type (elem_size, 1),
>                              nelts);
> -      if (GET_MODE_CLASS (TYPE_MODE (mask_type)) != MODE_VECTOR_INT
> -         || GET_MODE_SIZE (TYPE_MODE (mask_type))
> -            != GET_MODE_SIZE (TYPE_MODE (type)))
> +      if (cfun->curr_properties & PROP_gimple_lvec
> +         && (GET_MODE_CLASS (TYPE_MODE (mask_type)) != MODE_VECTOR_INT
> +             || GET_MODE_SIZE (TYPE_MODE (mask_type))
> +                != GET_MODE_SIZE (TYPE_MODE (type))))
>         return false;
>        mask_elts = XALLOCAVEC (tree, nelts);
>        for (i = 0; i < nelts; i++)
>         mask_elts[i] = build_int_cst (TREE_TYPE (mask_type), sel[i]);
>        op2 = build_vector (mask_type, mask_elts);
>        gimple_assign_set_rhs_with_ops_1 (gsi, VEC_PERM_EXPR, orig, orig,
> op2);
>      }
>    update_stmt (gsi_stmt (*gsi));
>    return true;
>  }
> Index: tree-vect-generic.c
> ===================================================================
> --- tree-vect-generic.c (revision 194247)
> +++ tree-vect-generic.c (working copy)
> @@ -1466,21 +1466,21 @@ expand_vector_operations_1 (gimple_stmt_
>    gimple_assign_set_rhs_from_tree (gsi, new_rhs);
>    update_stmt (gsi_stmt (*gsi));
>  }
>
>  /* Use this to lower vector operations introduced by the vectorizer,
>     if it may need the bit-twiddling tricks implemented in this file.  */
>
>  static bool
>  gate_expand_vector_operations_ssa (void)
>  {
> -  return optimize == 0;
> +  return !(cfun->curr_properties & PROP_gimple_lvec);
>  }
>
>  static unsigned int
>  expand_vector_operations (void)
>  {
>    gimple_stmt_iterator gsi;
>    basic_block bb;
>    bool cfg_changed = false;
>
>    FOR_EACH_BB (bb)
> @@ -1507,21 +1507,21 @@ struct gimple_opt_pass pass_lower_vector
>    GIMPLE_PASS,
>    "veclower",                          /* name */
>    OPTGROUP_VEC,                         /* optinfo_flags */
>    gate_expand_vector_operations_ssa,    /* gate */
>    expand_vector_operations,            /* execute */
>    NULL,                                        /* sub */
>    NULL,                                        /* next */
>    0,                                   /* static_pass_number */
>    TV_NONE,                             /* tv_id */
>    PROP_cfg,                            /* properties_required */
> -  0,                                   /* properties_provided */
> +  PROP_gimple_lvec,                    /* properties_provided */
>    0,                                   /* properties_destroyed */
>    0,                                   /* todo_flags_start */
>    TODO_update_ssa                      /* todo_flags_finish */
>      | TODO_verify_ssa
>      | TODO_verify_stmts | TODO_verify_flow
>      | TODO_cleanup_cfg
>   }
>  };
>
>  struct gimple_opt_pass pass_lower_vector_ssa =
> @@ -1530,21 +1530,21 @@ struct gimple_opt_pass pass_lower_vector
>    GIMPLE_PASS,
>    "veclower2",                         /* name */
>    OPTGROUP_VEC,                         /* optinfo_flags */
>    0,                                   /* gate */
>    expand_vector_operations,            /* execute */
>    NULL,                                        /* sub */
>    NULL,                                        /* next */
>    0,                                   /* static_pass_number */
>    TV_NONE,                             /* tv_id */
>    PROP_cfg,                            /* properties_required */
> -  0,                                   /* properties_provided */
> +  PROP_gimple_lvec,                    /* properties_provided */
>    0,                                   /* properties_destroyed */
>    0,                                   /* todo_flags_start */
>    TODO_update_ssa                      /* todo_flags_finish */
>      | TODO_verify_ssa
>      | TODO_verify_stmts | TODO_verify_flow
>      | TODO_cleanup_cfg
>   }
>  };
>
>  #include "gt-tree-vect-generic.h"
> Index: cfgexpand.c
> ===================================================================
> --- cfgexpand.c (revision 194247)
> +++ cfgexpand.c (working copy)
> @@ -4792,18 +4792,19 @@ struct rtl_opt_pass pass_expand =
>    RTL_PASS,
>    "expand",                            /* name */
>    OPTGROUP_NONE,                        /* optinfo_flags */
>    NULL,                                 /* gate */
>    gimple_expand_cfg,                   /* execute */
>    NULL,                                 /* sub */
>    NULL,                                 /* next */
>    0,                                    /* static_pass_number */
>    TV_EXPAND,                           /* tv_id */
>    PROP_ssa | PROP_gimple_leh | PROP_cfg
> -    | PROP_gimple_lcx,                 /* properties_required */
> +    | PROP_gimple_lcx
> +    | PROP_gimple_lvec,                        /* properties_required */
>    PROP_rtl,                             /* properties_provided */
>    PROP_ssa | PROP_trees,               /* properties_destroyed */
>    TODO_verify_ssa | TODO_verify_flow
>      | TODO_verify_stmts,               /* todo_flags_start */
>    TODO_ggc_collect                     /* todo_flags_finish */
>   }
>  };
>

Patch

Index: passes.c

===================================================================
--- passes.c	(revision 194247)

+++ passes.c	(working copy)

@@ -1305,21 +1305,20 @@  init_optimization_passes (void)

   NEXT_PASS (pass_ipa_free_lang_data);
   NEXT_PASS (pass_ipa_function_and_variable_visibility);
   NEXT_PASS (pass_early_local_passes);
     {
       struct opt_pass **p = &pass_early_local_passes.pass.sub;
       NEXT_PASS (pass_fixup_cfg);
       NEXT_PASS (pass_init_datastructures);
       NEXT_PASS (pass_expand_omp);
 
       NEXT_PASS (pass_build_ssa);
-      NEXT_PASS (pass_lower_vector);

       NEXT_PASS (pass_early_warn_uninitialized);
       NEXT_PASS (pass_rebuild_cgraph_edges);
       NEXT_PASS (pass_inline_parameters);
       NEXT_PASS (pass_early_inline);
       NEXT_PASS (pass_all_early_optimizations);
 	{
 	  struct opt_pass **p = &pass_all_early_optimizations.pass.sub;
 	  NEXT_PASS (pass_remove_cgraph_callee_edges);
 	  NEXT_PASS (pass_rename_ssa_copies);
 	  NEXT_PASS (pass_ccp);
@@ -1549,20 +1548,21 @@  init_optimization_passes (void)

       NEXT_PASS (pass_uncprop);
       NEXT_PASS (pass_local_pure_const);
     }
   NEXT_PASS (pass_tm_init);
     {
       struct opt_pass **p = &pass_tm_init.pass.sub;
       NEXT_PASS (pass_tm_mark);
       NEXT_PASS (pass_tm_memopt);
       NEXT_PASS (pass_tm_edges);
     }
+  NEXT_PASS (pass_lower_vector);

   NEXT_PASS (pass_lower_complex_O0);
   NEXT_PASS (pass_asan_O0);
   NEXT_PASS (pass_tsan_O0);
   NEXT_PASS (pass_cleanup_eh);
   NEXT_PASS (pass_lower_resx);
   NEXT_PASS (pass_nrv);
   NEXT_PASS (pass_mudflap_2);
   NEXT_PASS (pass_cleanup_cfg_post_optimizing);
   NEXT_PASS (pass_warn_function_noreturn);
 
@@ -2769,20 +2769,22 @@  dump_properties (FILE *dump, unsigned in

   if (props & PROP_ssa)
     fprintf (dump, "PROP_ssa\n");
   if (props & PROP_no_crit_edges)
     fprintf (dump, "PROP_no_crit_edges\n");
   if (props & PROP_rtl)
     fprintf (dump, "PROP_rtl\n");
   if (props & PROP_gimple_lomp)
     fprintf (dump, "PROP_gimple_lomp\n");
   if (props & PROP_gimple_lcx)
     fprintf (dump, "PROP_gimple_lcx\n");
+  if (props & PROP_gimple_lvec)

+    fprintf (dump, "PROP_gimple_lvec\n");

   if (props & PROP_cfglayout)
     fprintf (dump, "PROP_cfglayout\n");
 }
 
 DEBUG_FUNCTION void
 debug_properties (unsigned int props)
 {
   dump_properties (stderr, props);
 }
 
Index: tree-pass.h

===================================================================
--- tree-pass.h	(revision 194247)

+++ tree-pass.h	(working copy)

@@ -142,20 +142,21 @@  struct simple_ipa_opt_pass

 #define PROP_gimple_lcf		(1 << 1)	/* lowered control flow */
 #define PROP_gimple_leh		(1 << 2)	/* lowered eh */
 #define PROP_cfg		(1 << 3)
 #define PROP_ssa		(1 << 5)
 #define PROP_no_crit_edges      (1 << 6)
 #define PROP_rtl		(1 << 7)
 #define PROP_gimple_lomp	(1 << 8)	/* lowered OpenMP directives */
 #define PROP_cfglayout	 	(1 << 9)	/* cfglayout mode on RTL */
 #define PROP_gimple_lcx		(1 << 10)       /* lowered complex */
 #define PROP_loops		(1 << 11)	/* preserve loop structures */
+#define PROP_gimple_lvec	(1 << 12)       /* lowered vector */

 
 #define PROP_trees \
   (PROP_gimple_any | PROP_gimple_lcf | PROP_gimple_leh | PROP_gimple_lomp)
 
 /* To-do flags.  */
 #define TODO_ggc_collect		(1 << 1)
 #define TODO_verify_ssa			(1 << 2)
 #define TODO_verify_flow		(1 << 3)
 #define TODO_verify_stmts		(1 << 4)
 #define TODO_cleanup_cfg        	(1 << 5)
Index: tree-ssa-forwprop.c

===================================================================
--- tree-ssa-forwprop.c	(revision 194247)

+++ tree-ssa-forwprop.c	(working copy)

@@ -2855,28 +2855,30 @@  simplify_vector_constructor (gimple_stmt

     }
   if (i < nelts)
     return false;
 
   if (maybe_ident)
     gimple_assign_set_rhs_from_tree (gsi, orig);
   else
     {
       tree mask_type, *mask_elts;
 
-      if (!can_vec_perm_p (TYPE_MODE (type), false, sel))

+      if (cfun->curr_properties & PROP_gimple_lvec

+	  && !can_vec_perm_p (TYPE_MODE (type), false, sel))

 	return false;
       mask_type
 	= build_vector_type (build_nonstandard_integer_type (elem_size, 1),
 			     nelts);
-      if (GET_MODE_CLASS (TYPE_MODE (mask_type)) != MODE_VECTOR_INT

-	  || GET_MODE_SIZE (TYPE_MODE (mask_type))

-	     != GET_MODE_SIZE (TYPE_MODE (type)))

+      if (cfun->curr_properties & PROP_gimple_lvec

+	  && (GET_MODE_CLASS (TYPE_MODE (mask_type)) != MODE_VECTOR_INT

+	      || GET_MODE_SIZE (TYPE_MODE (mask_type))

+		 != GET_MODE_SIZE (TYPE_MODE (type))))

 	return false;
       mask_elts = XALLOCAVEC (tree, nelts);
       for (i = 0; i < nelts; i++)
 	mask_elts[i] = build_int_cst (TREE_TYPE (mask_type), sel[i]);
       op2 = build_vector (mask_type, mask_elts);
       gimple_assign_set_rhs_with_ops_1 (gsi, VEC_PERM_EXPR, orig, orig, op2);
     }
   update_stmt (gsi_stmt (*gsi));
   return true;
 }
Index: tree-vect-generic.c

===================================================================
--- tree-vect-generic.c	(revision 194247)

+++ tree-vect-generic.c	(working copy)

@@ -1466,21 +1466,21 @@  expand_vector_operations_1 (gimple_stmt_

   gimple_assign_set_rhs_from_tree (gsi, new_rhs);
   update_stmt (gsi_stmt (*gsi));
 }
 
 /* Use this to lower vector operations introduced by the vectorizer,
    if it may need the bit-twiddling tricks implemented in this file.  */
 
 static bool
 gate_expand_vector_operations_ssa (void)
 {
-  return optimize == 0;

+  return !(cfun->curr_properties & PROP_gimple_lvec);

 }
 
 static unsigned int
 expand_vector_operations (void)
 {
   gimple_stmt_iterator gsi;
   basic_block bb;
   bool cfg_changed = false;
 
   FOR_EACH_BB (bb)
@@ -1507,21 +1507,21 @@  struct gimple_opt_pass pass_lower_vector

   GIMPLE_PASS,
   "veclower",				/* name */
   OPTGROUP_VEC,                         /* optinfo_flags */
   gate_expand_vector_operations_ssa,    /* gate */
   expand_vector_operations,		/* execute */
   NULL,					/* sub */
   NULL,					/* next */
   0,					/* static_pass_number */
   TV_NONE,				/* tv_id */
   PROP_cfg,				/* properties_required */
-  0,					/* properties_provided */

+  PROP_gimple_lvec,			/* properties_provided */

   0,					/* properties_destroyed */
   0,					/* todo_flags_start */
   TODO_update_ssa	                /* todo_flags_finish */
     | TODO_verify_ssa
     | TODO_verify_stmts | TODO_verify_flow
     | TODO_cleanup_cfg
  }
 };
 
 struct gimple_opt_pass pass_lower_vector_ssa =
@@ -1530,21 +1530,21 @@  struct gimple_opt_pass pass_lower_vector

   GIMPLE_PASS,
   "veclower2",				/* name */
   OPTGROUP_VEC,                         /* optinfo_flags */
   0,	                                /* gate */
   expand_vector_operations,		/* execute */
   NULL,					/* sub */
   NULL,					/* next */
   0,					/* static_pass_number */
   TV_NONE,				/* tv_id */
   PROP_cfg,				/* properties_required */
-  0,					/* properties_provided */

+  PROP_gimple_lvec,			/* properties_provided */

   0,					/* properties_destroyed */
   0,					/* todo_flags_start */
   TODO_update_ssa	                /* todo_flags_finish */
     | TODO_verify_ssa
     | TODO_verify_stmts | TODO_verify_flow
     | TODO_cleanup_cfg
  }
 };
 
 #include "gt-tree-vect-generic.h"
Index: cfgexpand.c

===================================================================
--- cfgexpand.c	(revision 194247)

+++ cfgexpand.c	(working copy)

@@ -4792,18 +4792,19 @@  struct rtl_opt_pass pass_expand =

   RTL_PASS,
   "expand",				/* name */
   OPTGROUP_NONE,                        /* optinfo_flags */
   NULL,                                 /* gate */
   gimple_expand_cfg,			/* execute */
   NULL,                                 /* sub */
   NULL,                                 /* next */
   0,                                    /* static_pass_number */
   TV_EXPAND,				/* tv_id */
   PROP_ssa | PROP_gimple_leh | PROP_cfg
-    | PROP_gimple_lcx,			/* properties_required */

+    | PROP_gimple_lcx

+    | PROP_gimple_lvec,			/* properties_required */

   PROP_rtl,                             /* properties_provided */
   PROP_ssa | PROP_trees,		/* properties_destroyed */
   TODO_verify_ssa | TODO_verify_flow
     | TODO_verify_stmts,		/* todo_flags_start */
   TODO_ggc_collect			/* todo_flags_finish */
  }
 };