summaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-math-opts.c
diff options
context:
space:
mode:
authorbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2011-06-30 19:13:32 +0000
committerbstarynk <bstarynk@138bc75d-0d04-0410-961f-82ee72b054a4>2011-06-30 19:13:32 +0000
commit879e6664462821e8f43500b22229bb2ac1e09cea (patch)
treeff6fbe2138242f2438e6bb48988cae82c4cf1a68 /gcc/tree-ssa-math-opts.c
parenta36ec8263c25ecfe4e83aa19eaf33244394baa9c (diff)
downloadgcc-879e6664462821e8f43500b22229bb2ac1e09cea.tar.gz
2011-06-30 Basile Starynkevitch <basile@starynkevitch.net>
MELT branch merged with trunk rev 175718 using svnmerge. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/melt-branch@175720 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-math-opts.c')
-rw-r--r--gcc/tree-ssa-math-opts.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/gcc/tree-ssa-math-opts.c b/gcc/tree-ssa-math-opts.c
index bc7919a39ad..49ec360f9ce 100644
--- a/gcc/tree-ssa-math-opts.c
+++ b/gcc/tree-ssa-math-opts.c
@@ -1543,6 +1543,9 @@ do_shift_rotate (enum tree_code code,
default:
return false;
}
+ /* Zero unused bits for size. */
+ if (n->size < (int)sizeof (HOST_WIDEST_INT))
+ n->n &= ((unsigned HOST_WIDEST_INT)1 << (n->size * BITS_PER_UNIT)) - 1;
return true;
}
@@ -1740,15 +1743,16 @@ find_bswap (gimple stmt)
struct symbolic_number n;
tree source_expr;
+ int limit;
/* The last parameter determines the depth search limit. It usually
correlates directly to the number of bytes to be touched. We
- increase that number by one here in order to also cover signed ->
- unsigned conversions of the src operand as can be seen in
- libgcc. */
- source_expr = find_bswap_1 (stmt, &n,
- TREE_INT_CST_LOW (
- TYPE_SIZE_UNIT (gimple_expr_type (stmt))) + 1);
+ increase that number by three here in order to also
+ cover signed -> unsigned converions of the src operand as can be seen
+ in libgcc, and for initial shift/and operation of the src operand. */
+ limit = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (gimple_expr_type (stmt)));
+ limit += 1 + (int) ceil_log2 ((unsigned HOST_WIDE_INT) limit);
+ source_expr = find_bswap_1 (stmt, &n, limit);
if (!source_expr)
return NULL_TREE;
@@ -1817,7 +1821,11 @@ execute_optimize_bswap (void)
{
gimple_stmt_iterator gsi;
- for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+ /* We do a reverse scan for bswap patterns to make sure we get the
+ widest match. As bswap pattern matching doesn't handle
+ previously inserted smaller bswap replacements as sub-
+ patterns, the wider variant wouldn't be detected. */
+ for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi))
{
gimple stmt = gsi_stmt (gsi);
tree bswap_src, bswap_type;