[patch] Fold constants in vectorizer

Zdenek Dvorak rakdver@atrey.karlin.mff.cuni.cz
Fri Nov 10 16:47:00 GMT 2006


Hello,

vectorizer produces statements with unfolded constants (like
ratio = 151 >> 4) in case number of iterations of the loop is
a constant.  These statements are not folded anywhere else,
and remain in the program till rtl expansion.  They also tend to
confuse further analyses.

This patch makes vectorizer fold the expressions before emitting them
to program.  Bootstrapped & regtested on i686 (with -march=athlon -msse2
-ftree-vectorize).

Zdenek

	* tree-vect-transform.c (vect_generate_tmps_on_preheader): Fold the
	emited expressions.

Index: tree-vect-transform.c
===================================================================
*** tree-vect-transform.c	(revision 118545)
--- tree-vect-transform.c	(working copy)
*************** vect_generate_tmps_on_preheader (loop_ve
*** 2343,2371 ****
  
    /* Create: ratio = ni >> log2(vf) */
  
!   var = create_tmp_var (TREE_TYPE (ni), "bnd");
!   add_referenced_var (var);
!   ratio_name = make_ssa_name (var, NULL_TREE);
!   stmt = build2 (MODIFY_EXPR, void_type_node, ratio_name,
! 	   build2 (RSHIFT_EXPR, TREE_TYPE (ni_name), ni_name, log_vf));
!   SSA_NAME_DEF_STMT (ratio_name) = stmt;
! 
!   pe = loop_preheader_edge (loop);
!   new_bb = bsi_insert_on_edge_immediate (pe, stmt);
!   gcc_assert (!new_bb);
         
    /* Create: ratio_mult_vf = ratio << log2 (vf).  */
  
!   var = create_tmp_var (TREE_TYPE (ni), "ratio_mult_vf");
!   add_referenced_var (var);
!   ratio_mult_vf_name = make_ssa_name (var, NULL_TREE);
!   stmt = build2 (MODIFY_EXPR, void_type_node, ratio_mult_vf_name,
! 	   build2 (LSHIFT_EXPR, TREE_TYPE (ratio_name), ratio_name, log_vf));
!   SSA_NAME_DEF_STMT (ratio_mult_vf_name) = stmt;
! 
!   pe = loop_preheader_edge (loop);
!   new_bb = bsi_insert_on_edge_immediate (pe, stmt);
!   gcc_assert (!new_bb);
  
    *ni_name_ptr = ni_name;
    *ratio_mult_vf_name_ptr = ratio_mult_vf_name;
--- 2343,2375 ----
  
    /* Create: ratio = ni >> log2(vf) */
  
!   ratio_name = fold_build2 (RSHIFT_EXPR, TREE_TYPE (ni_name), ni_name, log_vf);
!   if (!is_gimple_val (ratio_name))
!     {
!       var = create_tmp_var (TREE_TYPE (ni), "bnd");
!       add_referenced_var (var);
! 
!       ratio_name = force_gimple_operand (ratio_name, &stmt, true, var);
!       pe = loop_preheader_edge (loop);
!       new_bb = bsi_insert_on_edge_immediate (pe, stmt);
!       gcc_assert (!new_bb);
!     }
         
    /* Create: ratio_mult_vf = ratio << log2 (vf).  */
  
!   ratio_mult_vf_name = fold_build2 (LSHIFT_EXPR, TREE_TYPE (ratio_name),
! 				    ratio_name, log_vf);
!   if (!is_gimple_val (ratio_mult_vf_name))
!     {
!       var = create_tmp_var (TREE_TYPE (ni), "ratio_mult_vf");
!       add_referenced_var (var);
! 
!       ratio_mult_vf_name = force_gimple_operand (ratio_mult_vf_name, &stmt,
! 						 true, var);
!       pe = loop_preheader_edge (loop);
!       new_bb = bsi_insert_on_edge_immediate (pe, stmt);
!       gcc_assert (!new_bb);
!     }
  
    *ni_name_ptr = ni_name;
    *ratio_mult_vf_name_ptr = ratio_mult_vf_name;



More information about the Gcc-patches mailing list