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] Remove BIT_FIELD_REF_UNSIGNED, tighten BIT_FIELD_REF type constraints


As discussed in

http://gcc.gnu.org/ml/gcc/2008-03/msg00252.html

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

Richard.


2008-03-05  Richard Guenther  <rguenther@suse.de>

	* tree.def (BIT_FIELD_REF): Constrain result type and its precision.
	* tree-cfg.c (verify_expr): Verify BIT_FIELD_REF constraints on
	result type and precision.
	* expr.c (get_inner_reference): Set unsignedp based on the result
	type of BIT_FIELD_REF.
	* tree.h (BIT_FIELD_REF_UNSIGNED): Remove.
	* tree-sra.c (instantiate_element): Do not set BIT_FIELD_REF_UNSIGNED.
	(try_instantiate_multiple_fields): Likewise.  Use the correct type
	for BIT_FIELD_REF.
	(sra_build_assignment): Likewise.
	(sra_build_elt_assignment): Likewise.
	(sra_explode_bitfield_assignment): Likewise.
	* print-tree.c (print_node): Do not check BIT_FIELD_REF_UNSIGNED.
	* tree-vect-transform.c (vect_create_epilog_for_reduction): Do not
	set BIT_FIELD_REF_UNSIGNED.
	(vectorizable_load): Likewise.

Index: gcc/tree.def
===================================================================
*** gcc/tree.def.orig	2008-03-05 13:45:46.000000000 +0100
--- gcc/tree.def	2008-03-06 11:36:23.000000000 +0100
*************** DEFTREECODE (COMPONENT_REF, "component_r
*** 391,398 ****
     Operand 0 is the structure or union expression;
     operand 1 is a tree giving the constant number of bits being referenced;
     operand 2 is a tree giving the constant position of the first referenced bit.
!    The field can be either a signed or unsigned field;
!    BIT_FIELD_REF_UNSIGNED says which.  */
  DEFTREECODE (BIT_FIELD_REF, "bit_field_ref", tcc_reference, 3)
  
  /* The ordering of the following codes is optimized for the checking
--- 391,399 ----
     Operand 0 is the structure or union expression;
     operand 1 is a tree giving the constant number of bits being referenced;
     operand 2 is a tree giving the constant position of the first referenced bit.
!    The result type width has to match the number of bits referenced.
!    If the result type is integral, its signedness specifies how it is extended
!    to its mode width.  */
  DEFTREECODE (BIT_FIELD_REF, "bit_field_ref", tcc_reference, 3)
  
  /* The ordering of the following codes is optimized for the checking
Index: gcc/tree-cfg.c
===================================================================
*** gcc/tree-cfg.c.orig	2008-03-06 10:09:56.000000000 +0100
--- gcc/tree-cfg.c	2008-03-06 11:36:23.000000000 +0100
*************** verify_expr (tree *tp, int *walk_subtree
*** 3277,3282 ****
--- 3277,3298 ----
  		  error ("invalid position or size operand to BIT_FIELD_REF");
  		  return t;
  		}
+ 	      else if (INTEGRAL_TYPE_P (TREE_TYPE (t))
+ 		       && (TYPE_PRECISION (TREE_TYPE (t))
+ 			   != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
+ 		{
+ 		  error ("integral result type precision does not match "
+ 			 "field size of BIT_FIELD_REF");
+ 		  return t;
+ 		}
+ 	      if (!INTEGRAL_TYPE_P (TREE_TYPE (t))
+ 		  && (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (t)))
+ 		      != TREE_INT_CST_LOW (TREE_OPERAND (t, 1))))
+ 		{
+ 		  error ("mode precision of non-integral result does not "
+ 			 "match field size of BIT_FIELD_REF");
+ 		  return t;
+ 		}
  	    }
  
  	  t = TREE_OPERAND (t, 0);
Index: gcc/expr.c
===================================================================
*** gcc/expr.c.orig	2008-03-05 13:45:46.000000000 +0100
--- gcc/expr.c	2008-03-06 11:36:23.000000000 +0100
*************** get_inner_reference (tree exp, HOST_WIDE
*** 5893,5899 ****
    else if (TREE_CODE (exp) == BIT_FIELD_REF)
      {
        size_tree = TREE_OPERAND (exp, 1);
!       *punsignedp = BIT_FIELD_REF_UNSIGNED (exp);
  
        /* For vector types, with the correct size of access, use the mode of
  	 inner type.  */
--- 5893,5900 ----
    else if (TREE_CODE (exp) == BIT_FIELD_REF)
      {
        size_tree = TREE_OPERAND (exp, 1);
!       *punsignedp = (! INTEGRAL_TYPE_P (TREE_TYPE (exp))
! 		     || TYPE_UNSIGNED (TREE_TYPE (exp)));
  
        /* For vector types, with the correct size of access, use the mode of
  	 inner type.  */
Index: gcc/tree-sra.c
===================================================================
*** gcc/tree-sra.c.orig	2008-03-05 13:45:46.000000000 +0100
--- gcc/tree-sra.c	2008-03-06 11:38:48.000000000 +0100
*************** instantiate_element (struct sra_elt *elt
*** 1280,1288 ****
  					       TYPE_SIZE (elt->type),
  					       DECL_SIZE (var))
  				 : bitsize_int (0));
-       if (!INTEGRAL_TYPE_P (elt->type)
- 	  || TYPE_UNSIGNED (elt->type))
- 	BIT_FIELD_REF_UNSIGNED (elt->replacement) = 1;
      }
  
    /* For vectors, if used on the left hand side with BIT_FIELD_REF,
--- 1280,1285 ----
*************** try_instantiate_multiple_fields (struct 
*** 1677,1688 ****
  
    /* Create the field group as a single variable.  */
  
!   type = lang_hooks.types.type_for_mode (mode, 1);
    gcc_assert (type);
    var = build3 (BIT_FIELD_REF, type, NULL_TREE,
  		bitsize_int (size),
  		bitsize_int (bit));
-   BIT_FIELD_REF_UNSIGNED (var) = 1;
  
    block = instantiate_missing_elements_1 (elt, var, type);
    gcc_assert (block && block->is_scalar);
--- 1674,1690 ----
  
    /* Create the field group as a single variable.  */
  
!   /* We used to create a type for the mode above, but size turns
!      to be out not of mode-size.  As we need a matching type
!      to build a BIT_FIELD_REF, use a nonstandard integer type as
!      fallback.  */
!   type = lang_hooks.types.type_for_size (size, 1);
!   if (!type || TYPE_PRECISION (type) != size)
!     type = build_nonstandard_integer_type (size, 1);
    gcc_assert (type);
    var = build3 (BIT_FIELD_REF, type, NULL_TREE,
  		bitsize_int (size),
  		bitsize_int (bit));
  
    block = instantiate_missing_elements_1 (elt, var, type);
    gcc_assert (block && block->is_scalar);
*************** try_instantiate_multiple_fields (struct 
*** 1696,1702 ****
  				   TREE_TYPE (block->element), var,
  				   bitsize_int (size),
  				   bitsize_int (bit & ~alchk));
-       BIT_FIELD_REF_UNSIGNED (block->replacement) = 1;
      }
  
    block->in_bitfld_block = 2;
--- 1698,1703 ----
*************** try_instantiate_multiple_fields (struct 
*** 1719,1725 ****
  				   + (TREE_INT_CST_LOW
  				      (DECL_FIELD_BIT_OFFSET (f))))
  				  & ~alchk));
-       BIT_FIELD_REF_UNSIGNED (fld->replacement) = TYPE_UNSIGNED (field_type);
        fld->in_bitfld_block = 1;
      }
  
--- 1720,1725 ----
*************** sra_build_assignment (tree dst, tree src
*** 2141,2147 ****
        tree var, shift, width;
        tree utype, stype, stmp, utmp, dtmp;
        tree list, stmt;
!       bool unsignedp = BIT_FIELD_REF_UNSIGNED (src);
  
        var = TREE_OPERAND (src, 0);
        width = TREE_OPERAND (src, 1);
--- 2141,2148 ----
        tree var, shift, width;
        tree utype, stype, stmp, utmp, dtmp;
        tree list, stmt;
!       bool unsignedp = (INTEGRAL_TYPE_P (TREE_TYPE (src))
! 		        ? TYPE_UNSIGNED (TREE_TYPE (src)) : true);
  
        var = TREE_OPERAND (src, 0);
        width = TREE_OPERAND (src, 1);
*************** sra_build_elt_assignment (struct sra_elt
*** 2491,2496 ****
--- 2492,2498 ----
    if (elt->in_bitfld_block == 2
        && TREE_CODE (src) == BIT_FIELD_REF)
      {
+       tmp = src;
        cst = TYPE_SIZE (TREE_TYPE (var));
        cst2 = size_binop (MINUS_EXPR, TREE_OPERAND (src, 2),
  			 TREE_OPERAND (dst, 2));
*************** sra_build_elt_assignment (struct sra_elt
*** 2536,2543 ****
  	}
        else
  	{
! 	  src = fold_build3 (BIT_FIELD_REF, TREE_TYPE (var), src, cst, cst2);
! 	  BIT_FIELD_REF_UNSIGNED (src) = 1;
  	}
  
        return sra_build_assignment (var, src);
--- 2538,2544 ----
  	}
        else
  	{
! 	  src = fold_convert (TREE_TYPE (var), tmp);
  	}
  
        return sra_build_assignment (var, src);
*************** sra_explode_bitfield_assignment (tree va
*** 3014,3019 ****
--- 3015,3022 ----
  	  type = TREE_TYPE (infld);
  	  if (TYPE_PRECISION (type) != TREE_INT_CST_LOW (flen))
  	    type = lang_hooks.types.type_for_size (TREE_INT_CST_LOW (flen), 1);
+ 	  else
+ 	    type = unsigned_type_for (type);
  
  	  if (TREE_CODE (infld) == BIT_FIELD_REF)
  	    {
*************** sra_explode_bitfield_assignment (tree va
*** 3031,3037 ****
  	    }
  
  	  infld = fold_build3 (BIT_FIELD_REF, type, infld, flen, fpos);
- 	  BIT_FIELD_REF_UNSIGNED (infld) = 1;
  
  	  invar = size_binop (MINUS_EXPR, flp.field_pos, bpos);
  	  if (flp.overlap_pos)
--- 3034,3039 ----
*************** sra_explode_bitfield_assignment (tree va
*** 3039,3045 ****
  	  invar = size_binop (PLUS_EXPR, invar, vpos);
  
  	  invar = fold_build3 (BIT_FIELD_REF, type, var, flen, invar);
- 	  BIT_FIELD_REF_UNSIGNED (invar) = 1;
  
  	  if (to_var)
  	    st = sra_build_bf_assignment (invar, infld);
--- 3041,3046 ----
Index: gcc/tree.h
===================================================================
*** gcc/tree.h.orig	2008-03-06 10:09:56.000000000 +0100
--- gcc/tree.h	2008-03-06 11:36:23.000000000 +0100
*************** struct gimple_stmt GTY(())
*** 542,549 ****
             all types
         DECL_UNSIGNED in
             all decls
-        BIT_FIELD_REF_UNSIGNED in
-            BIT_FIELD_REF
  
     asm_written_flag:
  
--- 542,547 ----
*************** extern void omp_clause_range_check_faile
*** 1301,1310 ****
  #define DECL_UNSIGNED(NODE) \
    (DECL_COMMON_CHECK (NODE)->base.unsigned_flag)
  
- /* In a BIT_FIELD_REF, means the bitfield is to be interpreted as unsigned.  */
- #define BIT_FIELD_REF_UNSIGNED(NODE) \
-   (BIT_FIELD_REF_CHECK (NODE)->base.unsigned_flag)
- 
  /* In integral and pointer types, means an unsigned type.  */
  #define TYPE_UNSIGNED(NODE) (TYPE_CHECK (NODE)->base.unsigned_flag)
  
--- 1299,1304 ----
Index: gcc/print-tree.c
===================================================================
*** gcc/print-tree.c.orig	2008-02-27 10:36:29.000000000 +0100
--- gcc/print-tree.c	2008-03-06 11:36:23.000000000 +0100
*************** print_node (FILE *file, const char *pref
*** 676,683 ****
      case tcc_reference:
      case tcc_statement:
      case tcc_vl_exp:
-       if (TREE_CODE (node) == BIT_FIELD_REF && BIT_FIELD_REF_UNSIGNED (node))
- 	fputs (" unsigned", file);
        if (TREE_CODE (node) == BIND_EXPR)
  	{
  	  print_node (file, "vars", TREE_OPERAND (node, 0), indent + 4);
--- 676,681 ----
Index: gcc/tree-vect-transform.c
===================================================================
*** gcc/tree-vect-transform.c.orig	2008-02-27 10:36:29.000000000 +0100
--- gcc/tree-vect-transform.c	2008-03-06 11:36:23.000000000 +0100
*************** vect_create_epilog_for_reduction (tree v
*** 2517,2523 ****
  	  vec_size_in_bits = tree_low_cst (TYPE_SIZE (vectype), 1);
  	  rhs = build3 (BIT_FIELD_REF, scalar_type, vec_temp, bitsize,
  			 bitsize_zero_node);
- 	  BIT_FIELD_REF_UNSIGNED (rhs) = TYPE_UNSIGNED (scalar_type);
  	  epilog_stmt = build_gimple_modify_stmt (new_scalar_dest, rhs);
  	  new_temp = make_ssa_name (new_scalar_dest, epilog_stmt);
  	  GIMPLE_STMT_OPERAND (epilog_stmt, 0) = new_temp;
--- 2517,2522 ----
*************** vect_create_epilog_for_reduction (tree v
*** 2532,2538 ****
  	      tree rhs = build3 (BIT_FIELD_REF, scalar_type, vec_temp, bitsize,
  				 bitpos);
  		
- 	      BIT_FIELD_REF_UNSIGNED (rhs) = TYPE_UNSIGNED (scalar_type);
  	      epilog_stmt = build_gimple_modify_stmt (new_scalar_dest, rhs);
  	      new_name = make_ssa_name (new_scalar_dest, epilog_stmt);
  	      GIMPLE_STMT_OPERAND (epilog_stmt, 0) = new_name;
--- 2531,2536 ----
*************** vect_create_epilog_for_reduction (tree v
*** 2568,2574 ****
  	bitpos = bitsize_zero_node;
  
        rhs = build3 (BIT_FIELD_REF, scalar_type, new_temp, bitsize, bitpos);
-       BIT_FIELD_REF_UNSIGNED (rhs) = TYPE_UNSIGNED (scalar_type);
        epilog_stmt = build_gimple_modify_stmt (new_scalar_dest, rhs);
        new_temp = make_ssa_name (new_scalar_dest, epilog_stmt);
        GIMPLE_STMT_OPERAND (epilog_stmt, 0) = new_temp; 
--- 2566,2571 ----
*************** vectorizable_load (tree stmt, block_stmt
*** 5877,5884 ****
  		  bitpos = bitsize_zero_node;
  		  vec_inv = build3 (BIT_FIELD_REF, scalar_type, new_temp, 
  							    bitsize, bitpos);
- 		  BIT_FIELD_REF_UNSIGNED (vec_inv) = 
- 						 TYPE_UNSIGNED (scalar_type);
  		  vec_dest = 
  			vect_create_destination_var (scalar_dest, NULL_TREE);
  		  new_stmt = build_gimple_modify_stmt (vec_dest, vec_inv);
--- 5874,5879 ----


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