aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorAndreas Krebbel <Andreas.Krebbel@de.ibm.com>2009-06-14 14:45:32 +0000
committerAndreas Krebbel <krebbel@gcc.gnu.org>2009-06-14 14:45:32 +0000
commit03bd2f1af7c1f2343940f6ca5409048ba16a2e4c (patch)
treeb8f6f449a98ff4e7527b14909b70123620025068 /gcc/tree.c
parenta810f82f7bd1fb1c3f4fa1f332e736cb1ada36c4 (diff)
downloadgcc-03bd2f1af7c1f2343940f6ca5409048ba16a2e4c.zip
gcc-03bd2f1af7c1f2343940f6ca5409048ba16a2e4c.tar.gz
gcc-03bd2f1af7c1f2343940f6ca5409048ba16a2e4c.tar.bz2
passes.c: Add bswap pass.
2009-06-14 Andreas Krebbel <Andreas.Krebbel@de.ibm.com> * passes.c: Add bswap pass. * tree-pass.h: Add pass_optimize_bswap declaration. * tree-ssa-math-opts.c: Include diagnostics.h for print_gimple_stmt. Include rtl.h, expr.h and optabs.h for optab_handler check. (struct symbolic_number, pass_optimize_bswap): New definition. (do_shift_rotate, verify_symbolic_number_p): New functions. (find_bswap_1, find_bswap, execute_optimize_bswap): New functions. (gate_optimize_bswap): New function. * tree.c (widest_int_cst_value): New function. * tree.h (widest_int_cst_value): Prototype added. 2009-06-14 Andreas Krebbel <Andreas.Krebbel@de.ibm.com> * gcc.dg/optimize-bswap-1.c: New testcase. From-SVN: r148471
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index eb1ad15..6ed29ca 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -8489,6 +8489,35 @@ int_cst_value (const_tree x)
return val;
}
+/* Return value of a constant X and sign-extend it. */
+
+HOST_WIDEST_INT
+widest_int_cst_value (const_tree x)
+{
+ unsigned bits = TYPE_PRECISION (TREE_TYPE (x));
+ unsigned HOST_WIDEST_INT val = TREE_INT_CST_LOW (x);
+
+#if HOST_BITS_PER_WIDEST_INT > HOST_BITS_PER_WIDE_INT
+ gcc_assert (HOST_BITS_PER_WIDEST_INT >= 2 * HOST_BITS_PER_WIDE_INT);
+ val |= TREE_INT_CST_HIGH (x) << HOST_BITS_PER_WIDE_INT;
+#else
+ /* Make sure the sign-extended value will fit in a HOST_WIDE_INT. */
+ gcc_assert (TREE_INT_CST_HIGH (x) == 0
+ || TREE_INT_CST_HIGH (x) == -1);
+#endif
+
+ if (bits < HOST_BITS_PER_WIDEST_INT)
+ {
+ bool negative = ((val >> (bits - 1)) & 1) != 0;
+ if (negative)
+ val |= (~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1;
+ else
+ val &= ~((~(unsigned HOST_WIDEST_INT) 0) << (bits - 1) << 1);
+ }
+
+ return val;
+}
+
/* If TYPE is an integral type, return an equivalent type which is
unsigned iff UNSIGNEDP is true. If TYPE is not an integral type,
return TYPE itself. */