public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Don't fold PTR - (UN)SIGNED comparison (PR middle-end/54945)
@ 2012-10-18 16:46 Marek Polacek
  2012-10-19  8:22 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2012-10-18 16:46 UTC (permalink / raw)
  To: GCC Patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Don't fold PTR - (UN)SIGNED comparison (PR middle-end/54945)
  2012-10-18 16:46 [PATCH] Don't fold PTR - (UN)SIGNED comparison (PR middle-end/54945) Marek Polacek
@ 2012-10-19  8:22 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2012-10-19  8:22 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

On Thu, Oct 18, 2012 at 6:21 PM, Marek Polacek <polacek@redhat.com> wrote:
> 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?

Ok for all active branches.

Thanks,
Richard.

> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-10-19  8:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-18 16:46 [PATCH] Don't fold PTR - (UN)SIGNED comparison (PR middle-end/54945) Marek Polacek
2012-10-19  8:22 ` Richard Biener

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).