This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] More type fixes, fix PR39698


This fixes some last OpenMP lowering issues as well as one vectorizer
issue where we create mismatched types for the adjusted start value
of the induction variable and one vectorizer issue where we create
wrong typed initial values for reductions (thanks Ira).

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to
trunk.

Richard.

2009-04-16  Richard Guenther  <rguenther@suse.de>
	Ira Rosen  <irar@il.ibm.com>

	PR tree-optimization/39698
	* tree-vect-loop.c (get_initial_def_for_reduction): Use the
	type of the reduction variable.  Only generate the def if
	it is needed.

	* omp-low.c (expand_omp_for_generic): When converting to a pointer
	make sure to first convert to an integer of the same precision.
	* tree-vect-loop-manip.c (vect_update_ivs_after_vectorizer): Retain
	the type of the evolution correctly in computing the new
	induction variable base.

Index: gcc/omp-low.c
===================================================================
*** gcc/omp-low.c.orig	2009-04-16 12:17:20.000000000 +0200
--- gcc/omp-low.c	2009-04-16 12:46:07.000000000 +0200
*************** expand_omp_for_generic (struct omp_regio
*** 3812,3832 ****
  
    /* Iteration setup for sequential loop goes in L0_BB.  */
    gsi = gsi_start_bb (l0_bb);
    if (bias)
!     t = fold_convert (type, fold_build2 (MINUS_EXPR, fd->iter_type,
! 					 istart0, bias));
!   else
!     t = fold_convert (type, istart0);
    t = force_gimple_operand_gsi (&gsi, t, false, NULL_TREE,
  				false, GSI_CONTINUE_LINKING);
    stmt = gimple_build_assign (fd->loop.v, t);
    gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
  
    if (bias)
!     t = fold_convert (type, fold_build2 (MINUS_EXPR, fd->iter_type,
! 					 iend0, bias));
!   else
!     t = fold_convert (type, iend0);
    iend = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
  				   false, GSI_CONTINUE_LINKING);
    if (fd->collapse > 1)
--- 3812,3836 ----
  
    /* Iteration setup for sequential loop goes in L0_BB.  */
    gsi = gsi_start_bb (l0_bb);
+   t = istart0;
    if (bias)
!     t = fold_build2 (MINUS_EXPR, fd->iter_type, t, bias);
!   if (POINTER_TYPE_P (type))
!     t = fold_convert (lang_hooks.types.type_for_size (TYPE_PRECISION (type),
! 						      0), t);
!   t = fold_convert (type, t);
    t = force_gimple_operand_gsi (&gsi, t, false, NULL_TREE,
  				false, GSI_CONTINUE_LINKING);
    stmt = gimple_build_assign (fd->loop.v, t);
    gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING);
  
+   t = iend0;
    if (bias)
!     t = fold_build2 (MINUS_EXPR, fd->iter_type, t, bias);
!   if (POINTER_TYPE_P (type))
!     t = fold_convert (lang_hooks.types.type_for_size (TYPE_PRECISION (type),
! 						      0), t);
!   t = fold_convert (type, t);
    iend = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
  				   false, GSI_CONTINUE_LINKING);
    if (fd->collapse > 1)
Index: gcc/tree-vect-loop-manip.c
===================================================================
*** gcc/tree-vect-loop-manip.c.orig	2009-04-16 12:17:20.000000000 +0200
--- gcc/tree-vect-loop-manip.c	2009-04-16 12:46:07.000000000 +0200
*************** vect_update_ivs_after_vectorizer (loop_v
*** 1593,1599 ****
        tree access_fn = NULL;
        tree evolution_part;
        tree init_expr;
!       tree step_expr;
        tree var, ni, ni_name;
        gimple_stmt_iterator last_gsi;
  
--- 1593,1600 ----
        tree access_fn = NULL;
        tree evolution_part;
        tree init_expr;
!       tree step_expr, off;
!       tree type;
        tree var, ni, ni_name;
        gimple_stmt_iterator last_gsi;
  
*************** vect_update_ivs_after_vectorizer (loop_v
*** 1623,1628 ****
--- 1624,1634 ----
  
        access_fn = analyze_scalar_evolution (loop, PHI_RESULT (phi)); 
        gcc_assert (access_fn);
+       /* We can end up with an access_fn like
+            (short int) {(short unsigned int) i_49, +, 1}_1
+ 	 for further analysis we need to strip the outer cast but we
+ 	 need to preserve the original type.  */
+       type = TREE_TYPE (access_fn);
        STRIP_NOPS (access_fn);
        evolution_part =
  	 unshare_expr (evolution_part_in_loop_num (access_fn, loop->num));
*************** vect_update_ivs_after_vectorizer (loop_v
*** 1635,1656 ****
        step_expr = evolution_part;
        init_expr = unshare_expr (initial_condition_in_loop_num (access_fn, 
  							       loop->num));
  
        if (POINTER_TYPE_P (TREE_TYPE (init_expr)))
  	ni = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (init_expr), 
! 			  init_expr, 
! 			  fold_build2 (MULT_EXPR, sizetype,
! 				       fold_convert (sizetype, niters),
! 				       step_expr));
        else
  	ni = fold_build2 (PLUS_EXPR, TREE_TYPE (init_expr),
! 			  fold_build2 (MULT_EXPR, TREE_TYPE (init_expr),
! 				       fold_convert (TREE_TYPE (init_expr),
! 						     niters),
! 				       step_expr),
! 			  init_expr);
! 
! 
  
        var = create_tmp_var (TREE_TYPE (init_expr), "tmp");
        add_referenced_var (var);
--- 1641,1659 ----
        step_expr = evolution_part;
        init_expr = unshare_expr (initial_condition_in_loop_num (access_fn, 
  							       loop->num));
+       init_expr = fold_convert (type, init_expr);
  
+       off = fold_build2 (MULT_EXPR, TREE_TYPE (step_expr),
+ 			 fold_convert (TREE_TYPE (step_expr), niters),
+ 			 step_expr);
        if (POINTER_TYPE_P (TREE_TYPE (init_expr)))
  	ni = fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (init_expr), 
! 			  init_expr,
! 			  fold_convert (sizetype, off));
        else
  	ni = fold_build2 (PLUS_EXPR, TREE_TYPE (init_expr),
! 			  init_expr,
! 			  fold_convert (TREE_TYPE (init_expr), off));
  
        var = create_tmp_var (TREE_TYPE (init_expr), "tmp");
        add_referenced_var (var);
Index: gcc/tree-vect-loop.c
===================================================================
*** gcc/tree-vect-loop.c.orig	2009-04-04 22:52:06.000000000 +0200
--- gcc/tree-vect-loop.c	2009-04-16 12:47:57.000000000 +0200
*************** get_initial_def_for_reduction (gimple st
*** 2267,2299 ****
    stmt_vec_info stmt_vinfo = vinfo_for_stmt (stmt);
    loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_vinfo);
    struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
!   tree vectype = STMT_VINFO_VECTYPE (stmt_vinfo);
!   int nunits =  TYPE_VECTOR_SUBPARTS (vectype);
!   tree scalar_type = TREE_TYPE (vectype);
    enum tree_code code = gimple_assign_rhs_code (stmt);
-   tree type = TREE_TYPE (init_val);
-   tree vecdef;
    tree def_for_init;
    tree init_def;
    tree t = NULL_TREE;
    int i;
    bool nested_in_vect_loop = false; 
  
!   gcc_assert (POINTER_TYPE_P (type) || INTEGRAL_TYPE_P (type) || SCALAR_FLOAT_TYPE_P (type));
    if (nested_in_vect_loop_p (loop, stmt))
      nested_in_vect_loop = true;
    else
      gcc_assert (loop == (gimple_bb (stmt))->loop_father);
  
-   vecdef = vect_get_vec_def_for_operand (init_val, stmt, NULL);
- 
    switch (code)
    {
    case WIDEN_SUM_EXPR:
    case DOT_PROD_EXPR:
    case PLUS_EXPR:
      if (nested_in_vect_loop)
!       *adjustment_def = vecdef;
      else
        *adjustment_def = init_val;
      /* Create a vector of zeros for init_def.  */
--- 2267,2299 ----
    stmt_vec_info stmt_vinfo = vinfo_for_stmt (stmt);
    loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_vinfo);
    struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
!   tree scalar_type = TREE_TYPE (init_val);
!   tree vectype = get_vectype_for_scalar_type (scalar_type);
!   int nunits;
    enum tree_code code = gimple_assign_rhs_code (stmt);
    tree def_for_init;
    tree init_def;
    tree t = NULL_TREE;
    int i;
    bool nested_in_vect_loop = false; 
  
!   gcc_assert (vectype);
!   nunits = TYPE_VECTOR_SUBPARTS (vectype);
! 
!   gcc_assert (POINTER_TYPE_P (scalar_type) || INTEGRAL_TYPE_P (scalar_type)
! 	      || SCALAR_FLOAT_TYPE_P (scalar_type));
    if (nested_in_vect_loop_p (loop, stmt))
      nested_in_vect_loop = true;
    else
      gcc_assert (loop == (gimple_bb (stmt))->loop_father);
  
    switch (code)
    {
    case WIDEN_SUM_EXPR:
    case DOT_PROD_EXPR:
    case PLUS_EXPR:
      if (nested_in_vect_loop)
!       *adjustment_def = vect_get_vec_def_for_operand (init_val, stmt, NULL);
      else
        *adjustment_def = init_val;
      /* Create a vector of zeros for init_def.  */
*************** get_initial_def_for_reduction (gimple st
*** 2310,2316 ****
    case MIN_EXPR:
    case MAX_EXPR:
      *adjustment_def = NULL_TREE;
!     init_def = vecdef;
      break;
  
    default:
--- 2310,2316 ----
    case MIN_EXPR:
    case MAX_EXPR:
      *adjustment_def = NULL_TREE;
!     init_def = vect_get_vec_def_for_operand (init_val, stmt, NULL);
      break;
  
    default:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]