diff options
author | Jeff Law <law@redhat.com> | 2017-09-04 08:00:29 -0600 |
---|---|---|
committer | Jeff Law <law@gcc.gnu.org> | 2017-09-04 08:00:29 -0600 |
commit | 8713d0f1c46f81107ea61781e2f4dc918d0fb67d (patch) | |
tree | 48e17398703864eb4a21643c5d2da00328515093 /gcc/tree-ssa-reassoc.c | |
parent | 8d2b48ae9f3e1e70dfe2aaf32abb9e74594b8875 (diff) | |
download | gcc-8713d0f1c46f81107ea61781e2f4dc918d0fb67d.zip gcc-8713d0f1c46f81107ea61781e2f4dc918d0fb67d.tar.gz gcc-8713d0f1c46f81107ea61781e2f4dc918d0fb67d.tar.bz2 |
re PR tree-optimization/64910 (tree reassociation results in poor code)
2017-09-03 Jeff Law <law@redhat.com>
PR tree-optimization/64910
* tree-ssa-reassoc.c (reassociate_bb): For bitwise binary ops,
swap the first and last operand if the last is a constant.
PR tree-optimization/64910
* gcc.dg/tree-ssa/pr64910-2.c: New test.
From-SVN: r251659
Diffstat (limited to 'gcc/tree-ssa-reassoc.c')
-rw-r--r-- | gcc/tree-ssa-reassoc.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 561acea..7604819 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -5762,6 +5762,18 @@ reassociate_bb (basic_block bb) fprintf (dump_file, "Width = %d was chosen for reassociation\n", width); + + /* For binary bit operations, if the last operand in + OPS is a constant, move it to the front. This + helps ensure that we generate (X & Y) & C rather + than (X & C) & Y. The former will often match + a canonical bit test when we get to RTL. */ + if ((rhs_code == BIT_AND_EXPR + || rhs_code == BIT_IOR_EXPR + || rhs_code == BIT_XOR_EXPR) + && TREE_CODE (ops.last ()->op) == INTEGER_CST) + std::swap (*ops[0], *ops[ops_num - 1]); + if (width > 1 && ops.length () > 3) rewrite_expr_tree_parallel (as_a <gassign *> (stmt), |