The type_for_size langhook should go (it does not handle non-mode
precision well, at least it handles it unexpectedly to most callers).
Instead callers that want to call a langhook should use type_for_mode.

The following patch makes some direct uses of the langhook from the
middle-end use something more suitable, for example [un]signed_type_for
for getting an integer type for a pointer type.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Jakub, are the OMP bits ok?

Thanks,
Richard.

2012-03-07  Richard Guenther  <rguent...@suse.de>

        * omp-low.c (extract_omp_for_data): Use signed_type_for.
        (expand_omp_for_generic): Likewise.
        (expand_omp_for_static_nochunk): Likewise.
        (expand_omp_for_static_chunk): Likewise.
        * tree-vect-stmts.c (vect_gen_perm_mask): Use type_for_mode.
        * tree-vect-slp.c (vect_transform_slp_perm_load): Likewise.
        * tree-vect-loop-manip.c (vect_gen_niters_for_prolog_loop):
        Use unsigned_type_for.
        (vect_create_cond_for_align_checks): Use signed_type_for.

Index: gcc/omp-low.c
===================================================================
*** gcc/omp-low.c       (revision 185029)
--- gcc/omp-low.c       (working copy)
*************** extract_omp_for_data (gimple for_stmt, s
*** 407,414 ****
              tree itype = TREE_TYPE (loop->v);
  
              if (POINTER_TYPE_P (itype))
!               itype
!                 = lang_hooks.types.type_for_size (TYPE_PRECISION (itype), 0);
              t = build_int_cst (itype, (loop->cond_code == LT_EXPR ? -1 : 1));
              t = fold_build2_loc (loc,
                               PLUS_EXPR, itype,
--- 407,413 ----
              tree itype = TREE_TYPE (loop->v);
  
              if (POINTER_TYPE_P (itype))
!               itype = signed_type_for (itype);
              t = build_int_cst (itype, (loop->cond_code == LT_EXPR ? -1 : 1));
              t = fold_build2_loc (loc,
                               PLUS_EXPR, itype,
*************** expand_omp_for_generic (struct omp_regio
*** 3772,3778 ****
          tree itype = TREE_TYPE (fd->loops[i].v);
  
          if (POINTER_TYPE_P (itype))
!           itype = lang_hooks.types.type_for_size (TYPE_PRECISION (itype), 0);
          t = build_int_cst (itype, (fd->loops[i].cond_code == LT_EXPR
                                     ? -1 : 1));
          t = fold_build2 (PLUS_EXPR, itype,
--- 3771,3777 ----
          tree itype = TREE_TYPE (fd->loops[i].v);
  
          if (POINTER_TYPE_P (itype))
!           itype = signed_type_for (itype);
          t = build_int_cst (itype, (fd->loops[i].cond_code == LT_EXPR
                                     ? -1 : 1));
          t = fold_build2 (PLUS_EXPR, itype,
*************** expand_omp_for_generic (struct omp_regio
*** 3836,3843 ****
          && TYPE_PRECISION (type) != TYPE_PRECISION (fd->iter_type))
        {
          /* Avoid casting pointers to integer of a different size.  */
!         tree itype
!           = lang_hooks.types.type_for_size (TYPE_PRECISION (type), 0);
          t1 = fold_convert (fd->iter_type, fold_convert (itype, fd->loop.n2));
          t0 = fold_convert (fd->iter_type, fold_convert (itype, fd->loop.n1));
        }
--- 3835,3841 ----
          && TYPE_PRECISION (type) != TYPE_PRECISION (fd->iter_type))
        {
          /* Avoid casting pointers to integer of a different size.  */
!         tree itype = signed_type_for (type);
          t1 = fold_convert (fd->iter_type, fold_convert (itype, fd->loop.n2));
          t0 = fold_convert (fd->iter_type, fold_convert (itype, fd->loop.n1));
        }
*************** expand_omp_for_generic (struct omp_regio
*** 3904,3911 ****
    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);
--- 3902,3908 ----
    if (bias)
      t = fold_build2 (MINUS_EXPR, fd->iter_type, t, bias);
    if (POINTER_TYPE_P (type))
!     t = fold_convert (signed_type_for (type), t);
    t = fold_convert (type, t);
    t = force_gimple_operand_gsi (&gsi, t, false, NULL_TREE,
                                false, GSI_CONTINUE_LINKING);
*************** expand_omp_for_generic (struct omp_regio
*** 3916,3923 ****
    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);
--- 3913,3919 ----
    if (bias)
      t = fold_build2 (MINUS_EXPR, fd->iter_type, t, bias);
    if (POINTER_TYPE_P (type))
!     t = fold_convert (signed_type_for (type), t);
    t = fold_convert (type, t);
    iend = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
                                   false, GSI_CONTINUE_LINKING);
*************** expand_omp_for_generic (struct omp_regio
*** 3932,3938 ****
          tree vtype = TREE_TYPE (fd->loops[i].v), itype;
          itype = vtype;
          if (POINTER_TYPE_P (vtype))
!           itype = lang_hooks.types.type_for_size (TYPE_PRECISION (vtype), 0);
          t = fold_build2 (TRUNC_MOD_EXPR, type, tem, counts[i]);
          t = fold_convert (itype, t);
          t = fold_build2 (MULT_EXPR, itype, t,
--- 3928,3934 ----
          tree vtype = TREE_TYPE (fd->loops[i].v), itype;
          itype = vtype;
          if (POINTER_TYPE_P (vtype))
!           itype = signed_type_for (vtype);
          t = fold_build2 (TRUNC_MOD_EXPR, type, tem, counts[i]);
          t = fold_convert (itype, t);
          t = fold_build2 (MULT_EXPR, itype, t,
*************** expand_omp_for_static_nochunk (struct om
*** 4162,4168 ****
  
    itype = type = TREE_TYPE (fd->loop.v);
    if (POINTER_TYPE_P (type))
!     itype = lang_hooks.types.type_for_size (TYPE_PRECISION (type), 0);
  
    entry_bb = region->entry;
    cont_bb = region->cont;
--- 4158,4164 ----
  
    itype = type = TREE_TYPE (fd->loop.v);
    if (POINTER_TYPE_P (type))
!     itype = signed_type_for (type);
  
    entry_bb = region->entry;
    cont_bb = region->cont;
*************** expand_omp_for_static_chunk (struct omp_
*** 4379,4385 ****
  
    itype = type = TREE_TYPE (fd->loop.v);
    if (POINTER_TYPE_P (type))
!     itype = lang_hooks.types.type_for_size (TYPE_PRECISION (type), 0);
  
    entry_bb = region->entry;
    se = split_block (entry_bb, last_stmt (entry_bb));
--- 4375,4381 ----
  
    itype = type = TREE_TYPE (fd->loop.v);
    if (POINTER_TYPE_P (type))
!     itype = signed_type_for (type);
  
    entry_bb = region->entry;
    se = split_block (entry_bb, last_stmt (entry_bb));
Index: gcc/tree-vect-stmts.c
===================================================================
*** gcc/tree-vect-stmts.c       (revision 185029)
--- gcc/tree-vect-stmts.c       (working copy)
*************** vect_gen_perm_mask (tree vectype, unsign
*** 4099,4107 ****
    if (!can_vec_perm_p (TYPE_MODE (vectype), false, sel))
      return NULL;
  
!   mask_elt_type
!     = lang_hooks.types.type_for_size
!     (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (vectype))), 1);
    mask_type = get_vectype_for_scalar_type (mask_elt_type);
  
    mask_vec = NULL;
--- 4099,4106 ----
    if (!can_vec_perm_p (TYPE_MODE (vectype), false, sel))
      return NULL;
  
!   mask_elt_type = lang_hooks.types.type_for_mode
!                   (int_mode_for_mode (TYPE_MODE (TREE_TYPE (vectype))), 1);
    mask_type = get_vectype_for_scalar_type (mask_elt_type);
  
    mask_vec = NULL;
Index: gcc/tree-vect-slp.c
===================================================================
*** gcc/tree-vect-slp.c (revision 185029)
--- gcc/tree-vect-slp.c (working copy)
*************** vect_transform_slp_perm_load (gimple stm
*** 2709,2717 ****
  
    /* The generic VEC_PERM_EXPR code always uses an integral type of the
       same size as the vector element being permuted.  */
!   mask_element_type
!     = lang_hooks.types.type_for_size
!     (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (vectype))), 1);
    mask_type = get_vectype_for_scalar_type (mask_element_type);
    nunits = TYPE_VECTOR_SUBPARTS (vectype);
    mask = XALLOCAVEC (unsigned char, nunits);
--- 2709,2716 ----
  
    /* The generic VEC_PERM_EXPR code always uses an integral type of the
       same size as the vector element being permuted.  */
!   mask_element_type = lang_hooks.types.type_for_mode
!               (int_mode_for_mode (TYPE_MODE (TREE_TYPE (vectype))), 1);
    mask_type = get_vectype_for_scalar_type (mask_element_type);
    nunits = TYPE_VECTOR_SUBPARTS (vectype);
    mask = XALLOCAVEC (unsigned char, nunits);
Index: gcc/tree-vect-loop-manip.c
===================================================================
*** gcc/tree-vect-loop-manip.c  (revision 185029)
--- gcc/tree-vect-loop-manip.c  (working copy)
*************** vect_gen_niters_for_prolog_loop (loop_ve
*** 2058,2066 ****
          ? size_int (-TYPE_VECTOR_SUBPARTS (vectype) + 1) : NULL_TREE;
        tree start_addr = vect_create_addr_base_for_vector_ref (dr_stmt,
                                                &new_stmts, offset, loop);
!       tree ptr_type = TREE_TYPE (start_addr);
!       tree size = TYPE_SIZE (ptr_type);
!       tree type = lang_hooks.types.type_for_size (tree_low_cst (size, 1), 1);
        tree vectype_size_minus_1 = build_int_cst (type, vectype_align - 1);
        tree elem_size_log =
          build_int_cst (type, exact_log2 (vectype_align/nelements));
--- 2058,2064 ----
          ? size_int (-TYPE_VECTOR_SUBPARTS (vectype) + 1) : NULL_TREE;
        tree start_addr = vect_create_addr_base_for_vector_ref (dr_stmt,
                                                &new_stmts, offset, loop);
!       tree type = unsigned_type_for (TREE_TYPE (start_addr));
        tree vectype_size_minus_1 = build_int_cst (type, vectype_align - 1);
        tree elem_size_log =
          build_int_cst (type, exact_log2 (vectype_align/nelements));
*************** vect_create_cond_for_align_checks (loop_
*** 2278,2284 ****
    int mask = LOOP_VINFO_PTR_MASK (loop_vinfo);
    tree mask_cst;
    unsigned int i;
-   tree psize;
    tree int_ptrsize_type;
    char tmp_name[20];
    tree or_tmp_name = NULL_TREE;
--- 2276,2281 ----
*************** vect_create_cond_for_align_checks (loop_
*** 2291,2301 ****
       all zeros followed by all ones.  */
    gcc_assert ((mask != 0) && ((mask & (mask+1)) == 0));
  
!   /* CHECKME: what is the best integer or unsigned type to use to hold a
!      cast from a pointer value?  */
!   psize = TYPE_SIZE (ptr_type_node);
!   int_ptrsize_type
!     = lang_hooks.types.type_for_size (tree_low_cst (psize, 1), 0);
  
    /* Create expression (mask & (dr_1 || ... || dr_n)) where dr_i is the 
address
       of the first vector of the i'th data reference. */
--- 2288,2294 ----
       all zeros followed by all ones.  */
    gcc_assert ((mask != 0) && ((mask & (mask+1)) == 0));
  
!   int_ptrsize_type = signed_type_for (ptr_type_node);
  
    /* Create expression (mask & (dr_1 || ... || dr_n)) where dr_i is the 
address
       of the first vector of the i'th data reference. */

Reply via email to