This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Add bult_int_cst_wide_type, use build_int_cst_type more
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Gcc Patch List" <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 8 Jan 2007 21:31:38 +0100
- Subject: [PATCH] Add bult_int_cst_wide_type, use build_int_cst_type more
This patch removes all of the
mask = build_int_cst (unsigned_type, -1);
mask = force_fit_type (mask, 0, false, false);
idiom uses by either using the existing build_int_cst_type or the new
build_int_cst_wide_type. This saves a tree node and a line of source.
Bootstrapped and tested on i686-pc-linux-gnu, another one including
all languages still running.
Richard.
2007-01-08 Richard Guenther <rguenther@suse.de>
* tree.h (build_int_cst_wide_type): Export.
* tree.c (build_int_cst_wide_type): New function.
(build_int_cst_wide): Fix comment.
* builtins.c (fold_builtin_object_size): Use build_int_cst
to build -1 or 0 of the correct type. Use fit_double_type
to check for overflow.
* fold-const.c (optimize_bit_field_compare): Use build_int_cst_type
to build the mask.
(decode_field_reference): Likewise.
(all_ones_mask_p): Likewise.
(native_interpret_int): Use build_int_cst_wide_type.
(fold_binary): Use build_int_cst_type to build an all-ones
value.
* stor-layout.c (set_sizetype): Use build_int_cst_wide_type.
java/
* lex.c (do_java_lex): Use build_int_cst_wide_type.
* jcf-parse.c (get_constant): Likewise.
cp/
* cvt.c (cp_convert_to_pointer): Use build_int_cst_type.
ada/
* cuintp.c (build_cst_from_int): Use built_int_cst_type.
2007-01-08 Richard Guenther <rguenther@suse.de>
* tree.h (build_int_cst_wide_type): Export.
* tree.c (build_int_cst_wide_type): New function.
(build_int_cst_wide): Fix comment.
* builtins.c (fold_builtin_object_size): Use build_int_cst
to build -1 or 0 of the correct type. Use fit_double_type
to check for overflow.
* fold-const.c (optimize_bit_field_compare): Use build_int_cst_type
to build the mask.
(decode_field_reference): Likewise.
(all_ones_mask_p): Likewise.
(native_interpret_int): Use build_int_cst_wide_type.
(fold_binary): Use build_int_cst_type to build an all-ones
value.
* stor-layout.c (set_sizetype): Use build_int_cst_wide_type.
java/
* lex.c (do_java_lex): Use build_int_cst_wide_type.
* jcf-parse.c (get_constant): Likewise.
cp/
* cvt.c (cp_convert_to_pointer): Use build_int_cst_type.
ada/
* cuintp.c (build_cst_from_int): Use built_int_cst_type.
Index: gcc/builtins.c
===================================================================
*** gcc.orig/builtins.c 2007-01-08 19:54:50.000000000 +0100
--- gcc/builtins.c 2007-01-08 21:12:58.000000000 +0100
*************** fold_builtin_object_size (tree arglist)
*** 10808,10820 ****
if there are any side-effects, it returns (size_t) -1 for types 0 and 1
and (size_t) 0 for types 2 and 3. */
if (TREE_SIDE_EFFECTS (ptr))
! return fold_convert (size_type_node,
! object_size_type < 2
! ? integer_minus_one_node : integer_zero_node);
if (TREE_CODE (ptr) == ADDR_EXPR)
ret = build_int_cstu (size_type_node,
! compute_builtin_object_size (ptr, object_size_type));
else if (TREE_CODE (ptr) == SSA_NAME)
{
--- 10808,10818 ----
if there are any side-effects, it returns (size_t) -1 for types 0 and 1
and (size_t) 0 for types 2 and 3. */
if (TREE_SIDE_EFFECTS (ptr))
! return build_int_cst_type (size_type_node, object_size_type < 2 ? -1 : 0);
if (TREE_CODE (ptr) == ADDR_EXPR)
ret = build_int_cstu (size_type_node,
! compute_builtin_object_size (ptr, object_size_type));
else if (TREE_CODE (ptr) == SSA_NAME)
{
*************** fold_builtin_object_size (tree arglist)
*** 10831,10839 ****
if (ret)
{
! ret = force_fit_type (ret, -1, false, false);
! if (TREE_CONSTANT_OVERFLOW (ret))
! ret = 0;
}
return ret;
--- 10829,10838 ----
if (ret)
{
! unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (ret);
! HOST_WIDE_INT high = TREE_INT_CST_HIGH (ret);
! if (fit_double_type (low, high, &low, &high, TREE_TYPE (ret)))
! ret = NULL_TREE;
}
return ret;
Index: gcc/fold-const.c
===================================================================
*** gcc.orig/fold-const.c 2007-01-08 19:49:14.000000000 +0100
--- gcc/fold-const.c 2007-01-08 21:11:53.000000000 +0100
*************** optimize_bit_field_compare (enum tree_co
*** 3478,3486 ****
lbitpos = nbitsize - lbitsize - lbitpos;
/* Make the mask to be used against the extracted field. */
! mask = build_int_cst (unsigned_type, -1);
! mask = force_fit_type (mask, 0, false, false);
! mask = fold_convert (unsigned_type, mask);
mask = const_binop (LSHIFT_EXPR, mask, size_int (nbitsize - lbitsize), 0);
mask = const_binop (RSHIFT_EXPR, mask,
size_int (nbitsize - lbitsize - lbitpos), 0);
--- 3478,3484 ----
lbitpos = nbitsize - lbitsize - lbitpos;
/* Make the mask to be used against the extracted field. */
! mask = build_int_cst_type (unsigned_type, -1);
mask = const_binop (LSHIFT_EXPR, mask, size_int (nbitsize - lbitsize), 0);
mask = const_binop (RSHIFT_EXPR, mask,
size_int (nbitsize - lbitsize - lbitpos), 0);
*************** decode_field_reference (tree exp, HOST_W
*** 3638,3645 ****
unsigned_type = lang_hooks.types.type_for_size (*pbitsize, 1);
precision = TYPE_PRECISION (unsigned_type);
! mask = build_int_cst (unsigned_type, -1);
! mask = force_fit_type (mask, 0, false, false);
mask = const_binop (LSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
mask = const_binop (RSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
--- 3636,3642 ----
unsigned_type = lang_hooks.types.type_for_size (*pbitsize, 1);
precision = TYPE_PRECISION (unsigned_type);
! mask = build_int_cst_type (unsigned_type, -1);
mask = const_binop (LSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
mask = const_binop (RSHIFT_EXPR, mask, size_int (precision - *pbitsize), 0);
*************** all_ones_mask_p (tree mask, int size)
*** 3664,3671 ****
unsigned int precision = TYPE_PRECISION (type);
tree tmask;
! tmask = build_int_cst (lang_hooks.types.signed_type (type), -1);
! tmask = force_fit_type (tmask, 0, false, false);
return
tree_int_cst_equal (mask,
--- 3661,3667 ----
unsigned int precision = TYPE_PRECISION (type);
tree tmask;
! tmask = build_int_cst_type (lang_hooks.types.signed_type (type), -1);
return
tree_int_cst_equal (mask,
*************** native_interpret_int (tree type, unsigne
*** 7113,7120 ****
<< (bitpos - HOST_BITS_PER_WIDE_INT);
}
! return force_fit_type (build_int_cst_wide (type, lo, hi),
! 0, false, false);
}
--- 7109,7115 ----
<< (bitpos - HOST_BITS_PER_WIDE_INT);
}
! return build_int_cst_wide_type (type, lo, hi);
}
*************** fold_binary (enum tree_code code, tree t
*** 8802,8809 ****
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
&& !TYPE_TRAP_SIGNED (type))
{
! t1 = build_int_cst (type, -1);
! t1 = force_fit_type (t1, 0, false, false);
return omit_one_operand (type, t1, arg1);
}
--- 8797,8803 ----
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0)
&& !TYPE_TRAP_SIGNED (type))
{
! t1 = build_int_cst_type (type, -1);
return omit_one_operand (type, t1, arg1);
}
*************** fold_binary (enum tree_code code, tree t
*** 8812,8819 ****
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)
&& !TYPE_TRAP_SIGNED (type))
{
! t1 = build_int_cst (type, -1);
! t1 = force_fit_type (t1, 0, false, false);
return omit_one_operand (type, t1, arg0);
}
--- 8806,8812 ----
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0)
&& !TYPE_TRAP_SIGNED (type))
{
! t1 = build_int_cst_type (type, -1);
return omit_one_operand (type, t1, arg0);
}
*************** fold_binary (enum tree_code code, tree t
*** 9601,9608 ****
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
{
! t1 = build_int_cst (type, -1);
! t1 = force_fit_type (t1, 0, false, false);
return omit_one_operand (type, t1, arg1);
}
--- 9594,9600 ----
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
{
! t1 = build_int_cst_type (type, -1);
return omit_one_operand (type, t1, arg1);
}
*************** fold_binary (enum tree_code code, tree t
*** 9610,9617 ****
if (TREE_CODE (arg1) == BIT_NOT_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
{
! t1 = build_int_cst (type, -1);
! t1 = force_fit_type (t1, 0, false, false);
return omit_one_operand (type, t1, arg0);
}
--- 9602,9608 ----
if (TREE_CODE (arg1) == BIT_NOT_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
{
! t1 = build_int_cst_type (type, -1);
return omit_one_operand (type, t1, arg0);
}
*************** fold_binary (enum tree_code code, tree t
*** 9717,9724 ****
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
{
! t1 = build_int_cst (type, -1);
! t1 = force_fit_type (t1, 0, false, false);
return omit_one_operand (type, t1, arg1);
}
--- 9708,9714 ----
if (TREE_CODE (arg0) == BIT_NOT_EXPR
&& operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
{
! t1 = build_int_cst_type (type, -1);
return omit_one_operand (type, t1, arg1);
}
*************** fold_binary (enum tree_code code, tree t
*** 9726,9733 ****
if (TREE_CODE (arg1) == BIT_NOT_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
{
! t1 = build_int_cst (type, -1);
! t1 = force_fit_type (t1, 0, false, false);
return omit_one_operand (type, t1, arg0);
}
--- 9716,9722 ----
if (TREE_CODE (arg1) == BIT_NOT_EXPR
&& operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
{
! t1 = build_int_cst_type (type, -1);
return omit_one_operand (type, t1, arg0);
}
Index: gcc/stor-layout.c
===================================================================
*** gcc.orig/stor-layout.c 2007-01-08 19:52:53.000000000 +0100
--- gcc/stor-layout.c 2007-01-08 19:53:48.000000000 +0100
*************** set_sizetype (tree type)
*** 2003,2016 ****
orig_max = TYPE_MAX_VALUE (sizetype);
! /* Build a new node with the same values, but a different type. */
! new_max = build_int_cst_wide (sizetype,
! TREE_INT_CST_LOW (orig_max),
! TREE_INT_CST_HIGH (orig_max));
!
! /* Now sign extend it using force_fit_type to ensure
! consistency. */
! new_max = force_fit_type (new_max, 0, 0, 0);
TYPE_MAX_VALUE (sizetype) = new_max;
}
}
--- 2003,2013 ----
orig_max = TYPE_MAX_VALUE (sizetype);
! /* Build a new node with the same values, but a different type.
! Sign extend it to ensure consistency. */
! new_max = build_int_cst_wide_type (sizetype,
! TREE_INT_CST_LOW (orig_max),
! TREE_INT_CST_HIGH (orig_max));
TYPE_MAX_VALUE (sizetype) = new_max;
}
}
Index: gcc/tree.c
===================================================================
*** gcc.orig/tree.c 2007-01-08 19:45:31.000000000 +0100
--- gcc/tree.c 2007-01-08 19:49:06.000000000 +0100
*************** build_int_cst_type (tree type, HOST_WIDE
*** 789,794 ****
--- 789,805 ----
return build_int_cst_wide (type, low1, hi);
}
+ /* Create an INT_CST node of TYPE and value HI:LOW. The value is truncated
+ and sign extended according to the value range of TYPE. */
+
+ tree
+ build_int_cst_wide_type (tree type,
+ unsigned HOST_WIDE_INT low, HOST_WIDE_INT high)
+ {
+ fit_double_type (low, high, &low, &high, type);
+ return build_int_cst_wide (type, low, high);
+ }
+
/* These are the hash table functions for the hash table of INTEGER_CST
nodes of a sizetype. */
*************** int_cst_hash_eq (const void *x, const vo
*** 817,826 ****
&& TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
}
! /* Create an INT_CST node of TYPE and value HI:LOW. If TYPE is NULL,
! integer_type_node is used. The returned node is always shared.
! For small integers we use a per-type vector cache, for larger ones
! we use a single hash table. */
tree
build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
--- 828,836 ----
&& TREE_INT_CST_LOW (xt) == TREE_INT_CST_LOW (yt));
}
! /* Create an INT_CST node of TYPE and value HI:LOW.
! The returned node is always shared. For small integers we use a
! per-type vector cache, for larger ones we use a single hash table. */
tree
build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
Index: gcc/tree.h
===================================================================
*** gcc.orig/tree.h 2007-01-08 19:49:13.000000000 +0100
--- gcc/tree.h 2007-01-08 21:11:53.000000000 +0100
*************** extern tree build_int_cst (tree, HOST_WI
*** 3654,3659 ****
--- 3654,3661 ----
extern tree build_int_cst_type (tree, HOST_WIDE_INT);
extern tree build_int_cstu (tree, unsigned HOST_WIDE_INT);
extern tree build_int_cst_wide (tree, unsigned HOST_WIDE_INT, HOST_WIDE_INT);
+ extern tree build_int_cst_wide_type (tree,
+ unsigned HOST_WIDE_INT, HOST_WIDE_INT);
extern tree build_vector (tree, tree);
extern tree build_vector_from_ctor (tree, VEC(constructor_elt,gc) *);
extern tree build_constructor (tree, VEC(constructor_elt,gc) *);
Index: gcc/cp/cvt.c
===================================================================
*** gcc.orig/cp/cvt.c 2007-01-08 20:45:38.000000000 +0100
--- gcc/cp/cvt.c 2007-01-08 20:46:05.000000000 +0100
*************** cp_convert_to_pointer (tree type, tree e
*** 251,259 ****
{
/* A NULL pointer-to-member is represented by -1, not by
zero. */
! expr = build_int_cst (type, -1);
! /* Fix up the representation of -1 if appropriate. */
! expr = force_fit_type (expr, 0, false, false);
}
else
expr = build_int_cst (type, 0);
--- 251,257 ----
{
/* A NULL pointer-to-member is represented by -1, not by
zero. */
! expr = build_int_cst_type (type, -1);
}
else
expr = build_int_cst (type, 0);
Index: gcc/java/jcf-parse.c
===================================================================
*** gcc.orig/java/jcf-parse.c 2007-01-08 20:44:08.000000000 +0100
--- gcc/java/jcf-parse.c 2007-01-08 20:44:31.000000000 +0100
*************** get_constant (JCF *jcf, int index)
*** 320,327 ****
lshift_double (num, 0, 32, 64, &lo, &hi, 0);
num = JPOOL_UINT (jcf, index+1);
add_double (lo, hi, num, 0, &lo, &hi);
! value = build_int_cst_wide (long_type_node, lo, hi);
! value = force_fit_type (value, 0, false, false);
break;
}
--- 320,326 ----
lshift_double (num, 0, 32, 64, &lo, &hi, 0);
num = JPOOL_UINT (jcf, index+1);
add_double (lo, hi, num, 0, &lo, &hi);
! value = build_int_cst_wide_type (long_type_node, lo, hi);
break;
}
Index: gcc/java/lex.c
===================================================================
*** gcc.orig/java/lex.c 2007-01-08 20:44:11.000000000 +0100
--- gcc/java/lex.c 2007-01-08 20:45:08.000000000 +0100
*************** do_java_lex (YYSTYPE *java_lval)
*** 1234,1242 ****
}
/* Sign extend the value. */
! value = build_int_cst_wide (long_suffix ? long_type_node : int_type_node,
! low, high);
! value = force_fit_type (value, 0, false, false);
if (radix != 10)
{
--- 1234,1241 ----
}
/* Sign extend the value. */
! value = build_int_cst_wide_type (long_suffix ? long_type_node
! : int_type_node, low, high);
if (radix != 10)
{
Index: gcc/ada/cuintp.c
===================================================================
*** gcc.orig/ada/cuintp.c 2007-01-08 20:47:58.000000000 +0100
--- gcc/ada/cuintp.c 2007-01-08 20:48:19.000000000 +0100
*************** build_cst_from_int (tree type, HOST_WIDE
*** 62,68 ****
if (TREE_CODE (type) == REAL_TYPE)
return convert (type, build_int_cst (NULL_TREE, low));
else
! return force_fit_type (build_int_cst (type, low), false, false, false);
}
/* Similar to UI_To_Int, but return a GCC INTEGER_CST or REAL_CST node,
--- 62,68 ----
if (TREE_CODE (type) == REAL_TYPE)
return convert (type, build_int_cst (NULL_TREE, low));
else
! return build_int_cst_type (type, low);
}
/* Similar to UI_To_Int, but return a GCC INTEGER_CST or REAL_CST node,