[patch] fold-const.c: Reorganize fold - Part 11/n
Kazu Hirata
kazu@cs.umass.edu
Sun Mar 6 16:23:00 GMT 2005
Hi,
Attached is part 11 of my patch to reorganize fold.
Eventually, we want fold_binary to look like
fold_binary (code, type, op0, op1)
instead of
fold_binary (binary_expr)
So we should use code, type, op0, and op1 instead of t.
Currently, fold_binary calls fold_range_test, which takes t. The
patch changes its arguments so that it will take code, type, op0, and
op1.
Tested on i686-pc-linux-gnu. OK to apply?
p.s.
After I tested Part 11, I mistakenly posted Part 12 as tested. Part
12 has survived bootstrapped so far and is now going through
regression testing.
Kazu Hirata
2005-03-06 Kazu Hirata <kazu@cs.umass.edu>
* fold-const.c (fold_range_test): Take decomposed arguments
code, type, op0, and op1 instead of t.
(fold_binary): Update a call to fold_range_test.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.527
diff -u -d -p -r1.527 fold-const.c
--- fold-const.c 6 Mar 2005 02:25:03 -0000 1.527
+++ fold-const.c 6 Mar 2005 02:33:54 -0000
@@ -113,7 +113,7 @@ static tree make_range (tree, int *, tre
static tree build_range_check (tree, tree, int, tree, tree);
static int merge_ranges (int *, tree *, tree *, int, tree, tree, int, tree,
tree);
-static tree fold_range_test (tree);
+static tree fold_range_test (enum tree_code, tree, tree, tree);
static tree fold_cond_expr_with_comparison (tree, tree, tree, tree);
static tree unextend (tree, int, int, tree);
static tree fold_truthop (enum tree_code, tree, tree, tree);
@@ -4414,14 +4414,14 @@ fold_cond_expr_with_comparison (tree typ
merge it into some range test. Return the new tree if so. */
static tree
-fold_range_test (tree exp)
+fold_range_test (enum tree_code code, tree type, tree op0, tree op1)
{
- int or_op = (TREE_CODE (exp) == TRUTH_ORIF_EXPR
- || TREE_CODE (exp) == TRUTH_OR_EXPR);
+ int or_op = (code == TRUTH_ORIF_EXPR
+ || code == TRUTH_OR_EXPR);
int in0_p, in1_p, in_p;
tree low0, low1, low, high0, high1, high;
- tree lhs = make_range (TREE_OPERAND (exp, 0), &in0_p, &low0, &high0);
- tree rhs = make_range (TREE_OPERAND (exp, 1), &in1_p, &low1, &high1);
+ tree lhs = make_range (op0, &in0_p, &low0, &high0);
+ tree rhs = make_range (op1, &in1_p, &low1, &high1);
tree tem;
/* If this is an OR operation, invert both sides; we will invert
@@ -4436,7 +4436,7 @@ fold_range_test (tree exp)
if ((lhs == 0 || rhs == 0 || operand_equal_p (lhs, rhs, 0))
&& merge_ranges (&in_p, &low, &high, in0_p, low0, high0,
in1_p, low1, high1)
- && 0 != (tem = (build_range_check (TREE_TYPE (exp),
+ && 0 != (tem = (build_range_check (type,
lhs != 0 ? lhs
: rhs != 0 ? rhs : integer_zero_node,
in_p, low, high))))
@@ -4447,33 +4447,32 @@ fold_range_test (tree exp)
is the same, make a non-short-circuit operation. */
else if (LOGICAL_OP_NON_SHORT_CIRCUIT
&& lhs != 0 && rhs != 0
- && (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
- || TREE_CODE (exp) == TRUTH_ORIF_EXPR)
+ && (code == TRUTH_ANDIF_EXPR
+ || code == TRUTH_ORIF_EXPR)
&& operand_equal_p (lhs, rhs, 0))
{
/* If simple enough, just rewrite. Otherwise, make a SAVE_EXPR
unless we are at top level or LHS contains a PLACEHOLDER_EXPR, in
which cases we can't do this. */
if (simple_operand_p (lhs))
- return build2 (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
+ return build2 (code == TRUTH_ANDIF_EXPR
? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
- TREE_TYPE (exp), TREE_OPERAND (exp, 0),
- TREE_OPERAND (exp, 1));
+ type, op0, op1);
else if (lang_hooks.decls.global_bindings_p () == 0
&& ! CONTAINS_PLACEHOLDER_P (lhs))
{
tree common = save_expr (lhs);
- if (0 != (lhs = build_range_check (TREE_TYPE (exp), common,
+ if (0 != (lhs = build_range_check (type, common,
or_op ? ! in0_p : in0_p,
low0, high0))
- && (0 != (rhs = build_range_check (TREE_TYPE (exp), common,
+ && (0 != (rhs = build_range_check (type, common,
or_op ? ! in1_p : in1_p,
low1, high1))))
- return build2 (TREE_CODE (exp) == TRUTH_ANDIF_EXPR
+ return build2 (code == TRUTH_ANDIF_EXPR
? TRUTH_AND_EXPR : TRUTH_OR_EXPR,
- TREE_TYPE (exp), lhs, rhs);
+ type, lhs, rhs);
}
}
@@ -8611,7 +8610,7 @@ fold_binary (tree expr)
}
/* See if we can build a range comparison. */
- if (0 != (tem = fold_range_test (t)))
+ if (0 != (tem = fold_range_test (code, type, op0, op1)))
return tem;
/* Check for the possibility of merging component references. If our
More information about the Gcc-patches
mailing list