From: Jakub Jelinek <jakub@redhat.com>
To: Paolo Bonzini <bonzini@gnu.org>
Cc: gcc-patches@gcc.gnu.org, Richard Guenther <rguenther@suse.de>
Subject: Re: [PATCH] Robustify simplify_truth_ops_using_ranges (PR tree-optimization/37662, PR tree-optimization/37663)
Date: Tue, 30 Sep 2008 15:53:00 -0000 [thread overview]
Message-ID: <20080930143423.GB24413@tyan-ft48-01.lab.bos.redhat.com> (raw)
In-Reply-To: <48E22F41.2090806@gnu.org>
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
prev parent reply other threads:[~2008-09-30 14:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-30 13:34 Jakub Jelinek
2008-09-30 13:53 ` Richard Guenther
2008-09-30 14:40 ` Paolo Bonzini
2008-09-30 15:53 ` Jakub Jelinek [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080930143423.GB24413@tyan-ft48-01.lab.bos.redhat.com \
--to=jakub@redhat.com \
--cc=bonzini@gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=rguenther@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).