aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKazu Hirata <kazu@cs.umass.edu>2005-03-06 14:19:45 +0000
committerKazu Hirata <kazu@gcc.gnu.org>2005-03-06 14:19:45 +0000
commitd7e5b287a07ee0615c5c8f27ac2e5f27bbb1467c (patch)
tree219caf65938492613e3650bb0a6b6835080502c1 /gcc
parentc933f71e3d23b794c70aa88f5641b1368a958167 (diff)
downloadgcc-d7e5b287a07ee0615c5c8f27ac2e5f27bbb1467c.zip
gcc-d7e5b287a07ee0615c5c8f27ac2e5f27bbb1467c.tar.gz
gcc-d7e5b287a07ee0615c5c8f27ac2e5f27bbb1467c.tar.bz2
fold-const.c (optimize_minmax_comparison): Take decomposed arguments code, type, op0, and op1 instead of t.
* fold-const.c (optimize_minmax_comparison): Take decomposed arguments code, type, op0, and op1 instead of t. (fold_binary): Update a call to optimize_minmax_comparison. From-SVN: r95971
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog4
-rw-r--r--gcc/fold-const.c40
2 files changed, 31 insertions, 13 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4e8e1e8..95005a4 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -6,6 +6,10 @@
* fold-const.c (fold_binary): Use code instead of t.
+ * fold-const.c (optimize_minmax_comparison): Take decomposed
+ arguments code, type, op0, and op1 instead of t.
+ (fold_binary): Update a call to optimize_minmax_comparison.
+
2005-03-06 Kazu Hirata <kazu@cs.umass.edu>
* fold-const.c (fold_binary): Avoid directly using the original
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index c6105dc..86b94f1 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -117,7 +117,7 @@ static tree fold_range_test (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);
-static tree optimize_minmax_comparison (tree);
+static tree optimize_minmax_comparison (enum tree_code, tree, tree, tree);
static tree extract_muldiv (tree, tree, enum tree_code, tree);
static tree extract_muldiv_1 (tree, tree, enum tree_code, tree);
static int multiple_of_p (tree, tree, tree);
@@ -4959,12 +4959,11 @@ fold_truthop (enum tree_code code, tree truth_type, tree lhs, tree rhs)
constant. */
static tree
-optimize_minmax_comparison (tree t)
+optimize_minmax_comparison (enum tree_code code, tree type, tree op0, tree op1)
{
- tree type = TREE_TYPE (t);
- tree arg0 = TREE_OPERAND (t, 0);
+ tree arg0 = op0;
enum tree_code op_code;
- tree comp_const = TREE_OPERAND (t, 1);
+ tree comp_const = op1;
tree minmax_const;
int consts_equal, consts_lt;
tree inner;
@@ -4983,24 +4982,33 @@ optimize_minmax_comparison (tree t)
|| TREE_CONSTANT_OVERFLOW (comp_const)
|| TREE_CODE (minmax_const) != INTEGER_CST
|| TREE_CONSTANT_OVERFLOW (minmax_const))
- return t;
+ return NULL_TREE;
/* Now handle all the various comparison codes. We only handle EQ_EXPR
and GT_EXPR, doing the rest with recursive calls using logical
simplifications. */
- switch (TREE_CODE (t))
+ switch (code)
{
case NE_EXPR: case LT_EXPR: case LE_EXPR:
- return
- invert_truthvalue (optimize_minmax_comparison (invert_truthvalue (t)));
+ {
+ /* FIXME: We should be able to invert code without building a
+ scratch tree node, but doing so would require us to
+ duplicate a part of invert_truthvalue here. */
+ tree tem = invert_truthvalue (build2 (code, type, op0, op1));
+ tem = optimize_minmax_comparison (TREE_CODE (tem),
+ TREE_TYPE (tem),
+ TREE_OPERAND (tem, 0),
+ TREE_OPERAND (tem, 1));
+ return invert_truthvalue (tem);
+ }
case GE_EXPR:
return
fold (build2 (TRUTH_ORIF_EXPR, type,
optimize_minmax_comparison
- (build2 (EQ_EXPR, type, arg0, comp_const)),
+ (EQ_EXPR, type, arg0, comp_const),
optimize_minmax_comparison
- (build2 (GT_EXPR, type, arg0, comp_const))));
+ (GT_EXPR, type, arg0, comp_const)));
case EQ_EXPR:
if (op_code == MAX_EXPR && consts_equal)
@@ -5047,7 +5055,7 @@ optimize_minmax_comparison (tree t)
return fold (build2 (GT_EXPR, type, inner, comp_const));
default:
- return t;
+ return NULL_TREE;
}
}
@@ -9142,7 +9150,13 @@ fold_binary (tree expr)
&& (TREE_CODE (arg0) == MIN_EXPR
|| TREE_CODE (arg0) == MAX_EXPR)
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
- return optimize_minmax_comparison (t);
+ {
+ tem = optimize_minmax_comparison (code, type, op0, op1);
+ if (tem)
+ return tem;
+
+ return t;
+ }
/* If we are comparing an ABS_EXPR with a constant, we can
convert all the cases into explicit comparisons, but they may