summaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorrakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4>2004-10-27 20:27:20 +0000
committerrakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4>2004-10-27 20:27:20 +0000
commitdede8dccf78be0a4041a7ca47d26f709e888f1fa (patch)
tree36323e61beca852219425c346a9efad5a6b0dfb5 /gcc/tree.c
parent5fd0f19b793f1e60a0d310d6f07ceff2e8eaa7ed (diff)
downloadgcc-dede8dccf78be0a4041a7ca47d26f709e888f1fa.tar.gz
PR tree-optimization/18048
* fold-const.c (try_move_mult_to_index): New function. (fold): Use try_move_mult_to_index. * tree-ssa-loop-ivopts.c (try_add_cand_for): Prefer common candidates. * tree-ssa-loop-niter.c (number_of_iterations_cond): Produce an all-ones unsigned constant without extra bits. * tree.c (build_low_bits_mask): New function. * tree.h (build_low_bits_mask): Declare. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@89708 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 18dec5ea730..9531e695d9a 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -609,6 +609,40 @@ build_int_cst_wide (tree type, unsigned HOST_WIDE_INT low, HOST_WIDE_INT hi)
return t;
}
+/* Builds an integer constant in TYPE such that lowest BITS bits are ones
+ and the rest are zeros. */
+
+tree
+build_low_bits_mask (tree type, unsigned bits)
+{
+ unsigned HOST_WIDE_INT low;
+ HOST_WIDE_INT high;
+ unsigned HOST_WIDE_INT all_ones = ~(unsigned HOST_WIDE_INT) 0;
+
+ gcc_assert (bits <= TYPE_PRECISION (type));
+
+ if (bits == TYPE_PRECISION (type)
+ && !TYPE_UNSIGNED (type))
+ {
+ /* Sign extended all-ones mask. */
+ low = all_ones;
+ high = -1;
+ }
+ else if (bits <= HOST_BITS_PER_WIDE_INT)
+ {
+ low = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
+ high = 0;
+ }
+ else
+ {
+ bits -= HOST_BITS_PER_WIDE_INT;
+ low = all_ones;
+ high = all_ones >> (HOST_BITS_PER_WIDE_INT - bits);
+ }
+
+ return build_int_cst_wide (type, low, high);
+}
+
/* Checks that X is integer constant that can be expressed in (unsigned)
HOST_WIDE_INT without loss of precision. */