Commit d579f20b by Jeff Law Committed by Jeff Law

tree-vrp.c (test_for_singularity): Extracted from ...

        * tree-vrp.c (test_for_singularity): Extracted from  ...
        (simplify_cond_using_ranges): Attempt to simplify a relational
        test to NE_EXPR.  Dump information when a COND_EXPR is simplified.

        * gcc.dg/tree-ssa/vrp17.c: Update expected output.
        * gcc.dg/tree-ssa/vrp18.c: New test.

From-SVN: r102489
parent 3353ebf0
2005-07-28 Jeff Law <law@redhat.com>
* tree-vrp.c (test_for_singularity): Extracted from ...
(simplify_cond_using_ranges): Attempt to simplify a relational
test to NE_EXPR. Dump information when a COND_EXPR is simplified.
2005-07-28 Dorit Nuzman <dorit@il.ibm.com> 2005-07-28 Dorit Nuzman <dorit@il.ibm.com>
PR tree-optimization/22506 PR tree-optimization/22506
......
2005-07-28 Jeff Law <law@redhat.com>
* gcc.dg/tree-ssa/vrp17.c: Update expected output.
* gcc.dg/tree-ssa/vrp18.c: New test.
2005-07-28 Dorit Nuzman <dorit@il.ibm.com> 2005-07-28 Dorit Nuzman <dorit@il.ibm.com>
* gcc.dg/vect/vect-reduc-1char.c: Fix data to fit in char. * gcc.dg/vect/vect-reduc-1char.c: Fix data to fit in char.
......
...@@ -27,6 +27,6 @@ gimplify_for_stmt (tree stmt) ...@@ -27,6 +27,6 @@ gimplify_for_stmt (tree stmt)
abort (); abort ();
} }
/* { dg-final { scan-tree-dump-times "== 3" 1 "vrp" } } */ /* { dg-final { scan-tree-dump-times "Simplified relational" 1 "vrp" } } */
/* { dg-final { cleanup-tree-dump "vrp" } } */ /* { dg-final { cleanup-tree-dump "vrp" } } */
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-vrp" } */
static int blocksize = 4096;
int bar (int);
void foo (void)
{
int toread;
int bytes;
static char eof_reached = 0;
toread = blocksize;
bytes = 1;
while (toread != 0)
{
bytes = bar (toread);
if (bytes <= 0)
{
if (bytes < 0)
continue;
break;
}
toread -= bytes;
}
if (bytes == 0)
eof_reached = 1;
}
/* { dg-final { scan-tree-dump-times "Simplified relational" 1 "vrp" } } */
/* { dg-final { cleanup-tree-dump "vrp" } } */
...@@ -3616,30 +3616,16 @@ simplify_abs_using_ranges (tree stmt, tree rhs) ...@@ -3616,30 +3616,16 @@ simplify_abs_using_ranges (tree stmt, tree rhs)
} }
} }
/* Simplify a conditional using a relational operator to an equality /* We are comparing trees OP0 and OP1 using COND_CODE. OP0 has
test if the range information indicates only one value can satisfy a known value range VR.
the original conditional. */
static void If there is one and only one value which will satisfy the
simplify_cond_using_ranges (tree stmt) conditional, then return that value. Else return NULL. */
{
tree cond = COND_EXPR_COND (stmt);
tree op0 = TREE_OPERAND (cond, 0);
tree op1 = TREE_OPERAND (cond, 1);
enum tree_code cond_code = TREE_CODE (cond);
if (cond_code != NE_EXPR static tree
&& cond_code != EQ_EXPR test_for_singularity (enum tree_code cond_code, tree op0,
&& TREE_CODE (op0) == SSA_NAME tree op1, value_range_t *vr)
&& INTEGRAL_TYPE_P (TREE_TYPE (op0)) {
&& is_gimple_min_invariant (op1))
{
value_range_t *vr = get_value_range (op0);
/* If we have range information for OP0, then we might be
able to simplify this conditional. */
if (vr->type == VR_RANGE)
{
tree min = NULL; tree min = NULL;
tree max = NULL; tree max = NULL;
...@@ -3683,15 +3669,87 @@ simplify_cond_using_ranges (tree stmt) ...@@ -3683,15 +3669,87 @@ simplify_cond_using_ranges (tree stmt)
/* If the new min/max values have converged to a /* If the new min/max values have converged to a
single value, then there is only one value which single value, then there is only one value which
can satisfy the condition. Rewrite the condition can satisfy the condition, return that value. */
to test for equality. */ if (min == max && is_gimple_min_invariant (min))
if (min == max return min;
&& is_gimple_min_invariant (min)) }
return NULL;
}
/* Simplify a conditional using a relational operator to an equality
test if the range information indicates only one value can satisfy
the original conditional. */
static void
simplify_cond_using_ranges (tree stmt)
{
tree cond = COND_EXPR_COND (stmt);
tree op0 = TREE_OPERAND (cond, 0);
tree op1 = TREE_OPERAND (cond, 1);
enum tree_code cond_code = TREE_CODE (cond);
if (cond_code != NE_EXPR
&& cond_code != EQ_EXPR
&& TREE_CODE (op0) == SSA_NAME
&& INTEGRAL_TYPE_P (TREE_TYPE (op0))
&& is_gimple_min_invariant (op1))
{
value_range_t *vr = get_value_range (op0);
/* If we have range information for OP0, then we might be
able to simplify this conditional. */
if (vr->type == VR_RANGE)
{
tree new = test_for_singularity (cond_code, op0, op1, vr);
if (new)
{
if (dump_file)
{
fprintf (dump_file, "Simplified relational ");
print_generic_expr (dump_file, cond, 0);
fprintf (dump_file, " into ");
}
COND_EXPR_COND (stmt)
= build (EQ_EXPR, boolean_type_node, op0, new);
update_stmt (stmt);
if (dump_file)
{
print_generic_expr (dump_file, COND_EXPR_COND (stmt), 0);
fprintf (dump_file, "\n");
}
return;
}
/* Try again after inverting the condition. We only deal
with integral types here, so no need to worry about
issues with inverting FP comparisons. */
cond_code = invert_tree_comparison (cond_code, false);
new = test_for_singularity (cond_code, op0, op1, vr);
if (new)
{
if (dump_file)
{ {
fprintf (dump_file, "Simplified relational ");
print_generic_expr (dump_file, cond, 0);
fprintf (dump_file, " into ");
}
COND_EXPR_COND (stmt) COND_EXPR_COND (stmt)
= build (EQ_EXPR, boolean_type_node, op0, min); = build (NE_EXPR, boolean_type_node, op0, new);
update_stmt (stmt); update_stmt (stmt);
if (dump_file)
{
print_generic_expr (dump_file, COND_EXPR_COND (stmt), 0);
fprintf (dump_file, "\n");
} }
return;
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment