From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Don't fold PTR - (UN)SIGNED comparison (PR middle-end/54945)
Date: Thu, 18 Oct 2012 16:46:00 -0000 [thread overview]
Message-ID: <20121018162110.GA29645@redhat.com> (raw)
This patch changes folding in fold_sign_changed_comparison in a way
that when we have pointer/non-pointer comparison, we give up folding
here. The issue is e.g. when we have (intptr_t) &MEM[(void *)&x + 4B]
== (intptr_t) &y and forwprop wants to fold this one via
fold_binary_loc--we then end up folding non-sign-changing comparison.
I don't know about the testcase though. I had something, but I think
it is too unrealiable. Regtested/bootstrapped on
x86_64-unknown-linux-gnu. Ok for trunk?
2012-10-18 Marek Polacek <polacek@redhat.com>
* fold-const.c (fold_sign_changed_comparison): Punt if folding
pointer/non-pointer comparison.
--- gcc/fold-const.c.mp 2012-10-17 15:01:34.882926243 +0200
+++ gcc/fold-const.c 2012-10-18 18:02:55.482642941 +0200
@@ -6731,12 +6731,14 @@ fold_sign_changed_comparison (location_t
&& TREE_TYPE (TREE_OPERAND (arg1, 0)) == inner_type))
return NULL_TREE;
- if ((TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
- || POINTER_TYPE_P (inner_type) != POINTER_TYPE_P (outer_type))
+ if (TYPE_UNSIGNED (inner_type) != TYPE_UNSIGNED (outer_type)
&& code != NE_EXPR
&& code != EQ_EXPR)
return NULL_TREE;
+ if (POINTER_TYPE_P (inner_type) != POINTER_TYPE_P (outer_type))
+ return NULL_TREE;
+
if (TREE_CODE (arg1) == INTEGER_CST)
arg1 = force_fit_type_double (inner_type, tree_to_double_int (arg1),
0, TREE_OVERFLOW (arg1));
Marek
next reply other threads:[~2012-10-18 16:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-18 16:46 Marek Polacek [this message]
2012-10-19 8:22 ` Richard Biener
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=20121018162110.GA29645@redhat.com \
--to=polacek@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/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).