public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix X +- C1 CMP C2 match.pd folding with -fwrapv (PR tree-optimization/80788)
@ 2017-11-27 22:41 Jakub Jelinek
  2017-11-28  7:41 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2017-11-27 22:41 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

This transformation turns it into a false or true if TREE_OVERFLOW
and TYPE_OVERFLOW_UNDEFINED, but if TREE_OVERFLOW is set, but not
TYPE_OVERFLOW_UNDEFINED, we leak the overflow bit into the IL, which then
confuses the VRP pass.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2017-11-27  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/80788
	* match.pd (X +- C1 CMP C2 -> X CMP C2 -+ C1): If res
	has TREE_OVERFLOW set, call drop_tree_overflow.

	* gcc.dg/pr80788.c: New test.

--- gcc/match.pd.jj	2017-11-24 22:38:53.000000000 +0100
+++ gcc/match.pd	2017-11-27 13:02:37.385280024 +0100
@@ -4393,7 +4393,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 	  && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
       { constant_boolean_node (cmp == NE_EXPR, type); }
       (if (single_use (@3))
-       (cmp @0 { res; }))))))))
+       (cmp @0 { TREE_OVERFLOW (res)
+		 ? drop_tree_overflow (res) : res; }))))))))
 (for cmp (lt le gt ge)
  (for op (plus minus)
       rop (minus plus)
--- gcc/testsuite/gcc.dg/pr80788.c.jj	2017-11-27 13:05:08.554378216 +0100
+++ gcc/testsuite/gcc.dg/pr80788.c	2017-11-27 13:04:42.000000000 +0100
@@ -0,0 +1,13 @@
+/* PR tree-optimization/80788 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fwrapv" } */
+
+void
+foo (signed char x)
+{
+  signed char a = (x + 1) ^ 128;
+  x &= !!a;
+  if (x != 0)
+    for (;;)
+      ;
+}

	Jakub

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

* Re: [PATCH] Fix X +- C1 CMP C2 match.pd folding with -fwrapv (PR tree-optimization/80788)
  2017-11-27 22:41 [PATCH] Fix X +- C1 CMP C2 match.pd folding with -fwrapv (PR tree-optimization/80788) Jakub Jelinek
@ 2017-11-28  7:41 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-11-28  7:41 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On November 27, 2017 11:36:23 PM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>This transformation turns it into a false or true if TREE_OVERFLOW
>and TYPE_OVERFLOW_UNDEFINED, but if TREE_OVERFLOW is set, but not
>TYPE_OVERFLOW_UNDEFINED, we leak the overflow bit into the IL, which
>then
>confuses the VRP pass.
>
>Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
>for
>trunk?

OK. 

Richard. 

>2017-11-27  Jakub Jelinek  <jakub@redhat.com>
>
>	PR tree-optimization/80788
>	* match.pd (X +- C1 CMP C2 -> X CMP C2 -+ C1): If res
>	has TREE_OVERFLOW set, call drop_tree_overflow.
>
>	* gcc.dg/pr80788.c: New test.
>
>--- gcc/match.pd.jj	2017-11-24 22:38:53.000000000 +0100
>+++ gcc/match.pd	2017-11-27 13:02:37.385280024 +0100
>@@ -4393,7 +4393,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> 	  && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
>       { constant_boolean_node (cmp == NE_EXPR, type); }
>       (if (single_use (@3))
>-       (cmp @0 { res; }))))))))
>+       (cmp @0 { TREE_OVERFLOW (res)
>+		 ? drop_tree_overflow (res) : res; }))))))))
> (for cmp (lt le gt ge)
>  (for op (plus minus)
>       rop (minus plus)
>--- gcc/testsuite/gcc.dg/pr80788.c.jj	2017-11-27 13:05:08.554378216
>+0100
>+++ gcc/testsuite/gcc.dg/pr80788.c	2017-11-27 13:04:42.000000000 +0100
>@@ -0,0 +1,13 @@
>+/* PR tree-optimization/80788 */
>+/* { dg-do compile } */
>+/* { dg-options "-O2 -fwrapv" } */
>+
>+void
>+foo (signed char x)
>+{
>+  signed char a = (x + 1) ^ 128;
>+  x &= !!a;
>+  if (x != 0)
>+    for (;;)
>+      ;
>+}
>
>	Jakub

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

end of thread, other threads:[~2017-11-28  6:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-27 22:41 [PATCH] Fix X +- C1 CMP C2 match.pd folding with -fwrapv (PR tree-optimization/80788) Jakub Jelinek
2017-11-28  7:41 ` 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).