[PATCH] Robustify simplify_truth_ops_using_ranges (PR tree-optimization/37662, PR tree-optimization/37663)
Jakub Jelinek
jakub@redhat.com
Tue Sep 30 15:53:00 GMT 2008
On Tue, Sep 30, 2008 at 03:53:05PM +0200, Paolo Bonzini wrote:
> Jakub Jelinek wrote:
> > The newly added simplify_truth_ops_using_ranges seems to be too fragile,
> > assumes the first argument must be always a SSA_NAME and only very few
> > possibilities for the second argument. The first assumption isn't true
> > e.g. when ccp or other passes substituted one of the truth op operands
> > but fab hasn't happened yet to swap the commutative operands to the
> > preferred order.
>
> First of all, thanks for this patch -- my comments aren't meant to bash
> your work.
As we talked on IRC, your fold_gimple_assign change looks good, and in
that case it doesn't make much sense to play with tree_swap_operands_p
in the tree-vrp.c case.
So here is an updated patch which I'll bootstrap/regtest together with
your fold_gimple_assign change.
2008-09-30 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/37662
PR tree-optimization/37663
* tree-vrp.c (simplify_truth_ops_using_ranges): Don't call
get_value_range with non-SSA_NAME. Don't assert operands have been
folded, instead just bail out.
* gcc.c-torture/compile/pr37662.c: New test.
* gcc.dg/pr37663.c: New test.
--- gcc/tree-vrp.c.jj 2008-09-16 16:50:49.000000000 +0200
+++ gcc/tree-vrp.c 2008-09-30 16:22:40.000000000 +0200
@@ -6304,9 +6304,12 @@ simplify_truth_ops_using_ranges (gimple_
bool need_conversion;
op0 = gimple_assign_rhs1 (stmt);
- vr = get_value_range (op0);
if (TYPE_PRECISION (TREE_TYPE (op0)) != 1)
{
+ if (TREE_CODE (op0) != SSA_NAME)
+ return false;
+ vr = get_value_range (op0);
+
val = compare_range_with_value (GE_EXPR, vr, integer_zero_node, &sop);
if (!val || !integer_onep (val))
return false;
@@ -6329,10 +6332,15 @@ simplify_truth_ops_using_ranges (gimple_
if (is_gimple_min_invariant (op1))
{
/* Exclude anything that should have been already folded. */
- gcc_assert (rhs_code == EQ_EXPR || rhs_code == NE_EXPR
- || rhs_code == TRUTH_XOR_EXPR);
- gcc_assert (integer_zerop (op1) || integer_onep (op1)
- || integer_all_onesp (op1));
+ if (rhs_code != EQ_EXPR
+ && rhs_code != NE_EXPR
+ && rhs_code != TRUTH_XOR_EXPR)
+ return false;
+
+ if (!integer_zerop (op1)
+ && !integer_onep (op1)
+ && !integer_all_onesp (op1))
+ return false;
/* Limit the number of cases we have to consider. */
if (rhs_code == EQ_EXPR)
@@ -6349,7 +6357,10 @@ simplify_truth_ops_using_ranges (gimple_
if (TYPE_PRECISION (TREE_TYPE (op1)) != 1)
{
+ if (TREE_CODE (op1) != SSA_NAME)
+ return false;
vr = get_value_range (op1);
+
val = compare_range_with_value (GE_EXPR, vr, integer_zero_node, &sop);
if (!val || !integer_onep (val))
return false;
--- gcc/testsuite/gcc.c-torture/compile/pr37662.c.jj 2008-09-30 13:57:08.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/compile/pr37662.c 2008-09-30 13:56:08.000000000 +0200
@@ -0,0 +1,15 @@
+/* PR tree-optimization/37662 */
+
+extern int baz (void);
+
+static int
+foo (void)
+{
+ return 1;
+}
+
+int
+bar (void)
+{
+ return foo () >= 1 ^ (baz () || 0) || 0;
+}
--- gcc/testsuite/gcc.dg/pr37663.c.jj 2008-09-30 13:56:43.000000000 +0200
+++ gcc/testsuite/gcc.dg/pr37663.c 2008-09-30 13:55:33.000000000 +0200
@@ -0,0 +1,15 @@
+/* PR tree-optimization/37663 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fwrapv" } */
+
+extern void bar (void);
+
+void
+foo (int x)
+{
+ x = 1 >= x;
+ int y = -1885403717;
+ x = x + (x != y * y);
+ if (x)
+ bar ();
+}
Jakub
More information about the Gcc-patches
mailing list