aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-operands.c
diff options
context:
space:
mode:
authorJeff Law <law@redhat.com>2004-06-15 23:09:41 -0600
committerJeff Law <law@gcc.gnu.org>2004-06-15 23:09:41 -0600
commitfd660b1bee7af09cd69d1125cf35e6aa5826234c (patch)
tree2d5c137139fce6357a14c09e7a739e3529131431 /gcc/tree-ssa-operands.c
parent3e97fe67e31070b78a333dba397ab4ddde2e7311 (diff)
downloadgcc-fd660b1bee7af09cd69d1125cf35e6aa5826234c.zip
gcc-fd660b1bee7af09cd69d1125cf35e6aa5826234c.tar.gz
gcc-fd660b1bee7af09cd69d1125cf35e6aa5826234c.tar.bz2
fold-const.c (swap_tree_comparison): No longer static.
* fold-const.c (swap_tree_comparison): No longer static. (tree_swap_operands_p): Similarly. Return true if both operands are SSA_NAMEs and the first operand has a higher version number than the second operand. * tree.h (swap_tree_comparison): Prototype. (tree_swap_operands_p): Prototype. * tree-ssa-operands.c (get_expr_operands): For commutative operators and relational comparisons, canonicalize the order of the operands. * gcc.dg/tree-ssa/20040615-1.c: New test. * gcc.dg/tree-ssa/20030824-1.c: Update expected output to be less sensitive to operand ordering. * gcc.dg/tree-ssa/20030824-2.c: Likewise. From-SVN: r83224
Diffstat (limited to 'gcc/tree-ssa-operands.c')
-rw-r--r--gcc/tree-ssa-operands.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/tree-ssa-operands.c b/gcc/tree-ssa-operands.c
index 02380b6..f1edfa18 100644
--- a/gcc/tree-ssa-operands.c
+++ b/gcc/tree-ssa-operands.c
@@ -1235,6 +1235,37 @@ get_expr_operands (tree stmt, tree *expr_p, int flags, voperands_t prev_vops)
|| code == TRUTH_XOR_EXPR
|| code == COMPOUND_EXPR)
{
+ tree op0 = TREE_OPERAND (expr, 0);
+ tree op1 = TREE_OPERAND (expr, 1);
+
+ /* If it would be profitable to swap the operands, then do so to
+ canonicalize the statement, enabling better optimization.
+
+ By placing canonicalization of such expressions here we
+ transparently keep statements in canonical form, even
+ when the statement is modified. */
+ if (tree_swap_operands_p (op0, op1, false))
+ {
+ /* For relationals we need to swap the operands and change
+ the code. */
+ if (code == LT_EXPR
+ || code == GT_EXPR
+ || code == LE_EXPR
+ || code == GE_EXPR)
+ {
+ TREE_SET_CODE (expr, swap_tree_comparison (code));
+ TREE_OPERAND (expr, 0) = op1;
+ TREE_OPERAND (expr, 1) = op0;
+ }
+
+ /* For a commutative operator we can just swap the operands. */
+ if (commutative_tree_code (code))
+ {
+ TREE_OPERAND (expr, 0) = op1;
+ TREE_OPERAND (expr, 1) = op0;
+ }
+ }
+
get_expr_operands (stmt, &TREE_OPERAND (expr, 0), flags, prev_vops);
get_expr_operands (stmt, &TREE_OPERAND (expr, 1), flags, prev_vops);
return;