aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorRichard Sandiford <rdsandiford@googlemail.com>2013-11-18 14:50:47 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2013-11-18 14:50:47 +0000
commitb04268a57f6e67376cf804e6e5866cf8cbfef968 (patch)
tree131a6aaf79560e8a3a9a65edd5dc63fa0d893de7 /gcc/tree.c
parenta2ca7c8cb966f02300a3775ba5575412aa6b1f94 (diff)
downloadgcc-b04268a57f6e67376cf804e6e5866cf8cbfef968.zip
gcc-b04268a57f6e67376cf804e6e5866cf8cbfef968.tar.gz
gcc-b04268a57f6e67376cf804e6e5866cf8cbfef968.tar.bz2
tree.h (tree_fits_shwi_p, [...]): Declare.
gcc/ * tree.h (tree_fits_shwi_p, tree_fits_uhwi_p): Declare. * tree.c (tree_fits_shwi_p, tree_fits_uhwi_p): Define. From-SVN: r204954
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 34bc8ac..374f560 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -6990,6 +6990,32 @@ host_integerp (const_tree t, int pos)
|| (pos && TREE_INT_CST_HIGH (t) == 0)));
}
+/* Return true if T is an INTEGER_CST whose numerical value (extended
+ according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
+
+bool
+tree_fits_shwi_p (const_tree t)
+{
+ return (t != NULL_TREE
+ && TREE_CODE (t) == INTEGER_CST
+ && ((TREE_INT_CST_HIGH (t) == 0
+ && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
+ || (TREE_INT_CST_HIGH (t) == -1
+ && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
+ && !TYPE_UNSIGNED (TREE_TYPE (t)))));
+}
+
+/* Return true if T is an INTEGER_CST whose numerical value (extended
+ according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
+
+bool
+tree_fits_uhwi_p (const_tree t)
+{
+ return (t != NULL_TREE
+ && TREE_CODE (t) == INTEGER_CST
+ && TREE_INT_CST_HIGH (t) == 0);
+}
+
/* Return the HOST_WIDE_INT least significant bits of T if it is an
INTEGER_CST and there is no overflow. POS is nonzero if the result must
be non-negative. We must be able to satisfy the above conditions. */