aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2016-05-02 09:40:09 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2016-05-02 09:40:09 +0000
commit697e0b28cca9e5f3e1ee59131c048ef93014fb2f (patch)
tree8813b12d24cde53b2b940740605d9108aa099d28 /gcc
parent8de73453a42758af02bb23ed58f4b1e78ad11bc7 (diff)
downloadgcc-697e0b28cca9e5f3e1ee59131c048ef93014fb2f.zip
gcc-697e0b28cca9e5f3e1ee59131c048ef93014fb2f.tar.gz
gcc-697e0b28cca9e5f3e1ee59131c048ef93014fb2f.tar.bz2
Add a wi::to_wide helper function
As Richard says, we ought to have a convenient way of converting an INTEGER_CST to a wide_int of a particular precision without having to extract the sign of the INTEGER_CST's type each time. This patch adds a wi::to_wide helper for that, alongside the existing wi::to_offset and wi::to_widest. Tested on x86_64-linux-gnu and aarch64-linux-gnu. gcc/ * tree.h (wi::to_wide): New function. * expr.c (expand_expr_real_1): Use wi::to_wide. * fold-const.c (int_const_binop_1): Likewise. (extract_muldiv_1): Likewise. gcc/c-family/ * c-common.c (shorten_compare): Use wi::to_wide. From-SVN: r235721
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/c-family/ChangeLog4
-rw-r--r--gcc/c-family/c-common.c7
-rw-r--r--gcc/expr.c5
-rw-r--r--gcc/fold-const.c9
-rw-r--r--gcc/tree.h12
6 files changed, 31 insertions, 13 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d83a16a..7b1c838 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
2016-05-02 Richard Sandiford <richard.sandiford@arm.com>
+ * tree.h (wi::to_wide): New function.
+ * expr.c (expand_expr_real_1): Use wi::to_wide.
+ * fold-const.c (int_const_binop_1): Likewise.
+ (extract_muldiv_1): Likewise.
+
+2016-05-02 Richard Sandiford <richard.sandiford@arm.com>
+
* wide-int.h: Update offset_int and widest_int documentation.
(WI_SIGNED_SHIFT_RESULT): New macro.
(wi::binary_shift): Define signed_shift_result_type for
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 834950e..49012e1 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,7 @@
+2016-05-02 Richard Sandiford <richard.sandiford@arm.com>
+
+ * c-common.c (shorten_compare): Use wi::to_wide.
+
2016-04-29 Cesar Philippidis <cesar@codesourcery.com>
PR middle-end/70626
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 3c35a6b..d45bf1b 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -4012,10 +4012,9 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
/* Convert primop1 to target type, but do not introduce
additional overflow. We know primop1 is an int_cst. */
primop1 = force_fit_type (*restype_ptr,
- wide_int::from
- (primop1,
- TYPE_PRECISION (*restype_ptr),
- TYPE_SIGN (TREE_TYPE (primop1))),
+ wi::to_wide
+ (primop1,
+ TYPE_PRECISION (*restype_ptr)),
0, TREE_OVERFLOW (primop1));
}
if (type != *restype_ptr)
diff --git a/gcc/expr.c b/gcc/expr.c
index 8870a0c..812c544 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -9729,10 +9729,9 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
GET_MODE_PRECISION (TYPE_MODE (type)), we need to extend from
the former to the latter according to the signedness of the
type. */
- temp = immed_wide_int_const (wide_int::from
+ temp = immed_wide_int_const (wi::to_wide
(exp,
- GET_MODE_PRECISION (TYPE_MODE (type)),
- TYPE_SIGN (type)),
+ GET_MODE_PRECISION (TYPE_MODE (type))),
TYPE_MODE (type));
return temp;
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 8ece0f8..3c389ee 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -963,8 +963,7 @@ int_const_binop_1 (enum tree_code code, const_tree arg1, const_tree parg2,
signop sign = TYPE_SIGN (type);
bool overflow = false;
- wide_int arg2 = wide_int::from (parg2, TYPE_PRECISION (type),
- TYPE_SIGN (TREE_TYPE (parg2)));
+ wide_int arg2 = wi::to_wide (parg2, TYPE_PRECISION (type));
switch (code)
{
@@ -6397,10 +6396,8 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type,
bool overflow_mul_p;
signop sign = TYPE_SIGN (ctype);
unsigned prec = TYPE_PRECISION (ctype);
- wide_int mul = wi::mul (wide_int::from (op1, prec,
- TYPE_SIGN (TREE_TYPE (op1))),
- wide_int::from (c, prec,
- TYPE_SIGN (TREE_TYPE (c))),
+ wide_int mul = wi::mul (wi::to_wide (op1, prec),
+ wi::to_wide (c, prec),
sign, &overflow_mul_p);
overflow_p = TREE_OVERFLOW (c) | TREE_OVERFLOW (op1);
if (overflow_mul_p
diff --git a/gcc/tree.h b/gcc/tree.h
index 024cf3d..6e52e3d 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -5211,6 +5211,8 @@ namespace wi
to_widest (const_tree);
generic_wide_int <extended_tree <ADDR_MAX_PRECISION> > to_offset (const_tree);
+
+ wide_int to_wide (const_tree, unsigned int);
}
inline unsigned int
@@ -5240,6 +5242,16 @@ wi::to_offset (const_tree t)
return t;
}
+/* Convert INTEGER_CST T to a wide_int of precision PREC, extending or
+ truncating as necessary. When extending, use sign extension if T's
+ type is signed and zero extension if T's type is unsigned. */
+
+inline wide_int
+wi::to_wide (const_tree t, unsigned int prec)
+{
+ return wide_int::from (t, prec, TYPE_SIGN (TREE_TYPE (t)));
+}
+
template <int N>
inline wi::extended_tree <N>::extended_tree (const_tree t)
: m_t (t)