public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix neg overflow expansion (PR middle-end/77594)
@ 2016-09-15 23:10 Jakub Jelinek
  2016-09-16  5:59 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-09-15 23:10 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

As mentioned in the PR, during expand_arith_overflow expansion
expand_neg_overflow falls through into expand_addsub_overflow, so expands
roughly the same code twice and keeps perhaps the less efficient version
around.

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

2016-09-16  Jakub Jelinek  <jakub@redhat.com>
	    Eric Botcazou  <ebotcazou@adacore.com>

	PR middle-end/77594
	* internal-fn.c (expand_arith_overflow) <case MINUS_EXPR>: Don't fall
	through into expand_addsub_overflow after expand_neg_overflow.

	* gcc.target/i386/pr77594.c: New test.

--- gcc/internal-fn.c.jj	2016-08-29 12:17:14.000000000 +0200
+++ gcc/internal-fn.c	2016-09-15 09:42:09.693980531 +0200
@@ -1833,7 +1833,10 @@ expand_arith_overflow (enum tree_code co
 	    {
 	    case MINUS_EXPR:
 	      if (integer_zerop (arg0) && !unsr_p)
-		expand_neg_overflow (loc, lhs, arg1, false);
+		{
+		  expand_neg_overflow (loc, lhs, arg1, false);
+		  return;
+		}
 	      /* FALLTHRU */
 	    case PLUS_EXPR:
 	      expand_addsub_overflow (loc, code, lhs, arg0, arg1,
--- gcc/testsuite/gcc.target/i386/pr77594.c.jj	2016-09-15 09:44:51.879910346 +0200
+++ gcc/testsuite/gcc.target/i386/pr77594.c	2016-09-15 09:44:43.000000000 +0200
@@ -0,0 +1,11 @@
+/* PR middle-end/77594 */
+/* { dg-do compile } */
+/* { dg-options "-O0" } */
+
+int
+foo (int a, int *b)
+{
+  return __builtin_sub_overflow (0, a, b);
+}
+
+/* { dg-final { scan-assembler-times "\tjn?o\t" 1 } } */

	Jakub

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

* Re: [PATCH] Fix neg overflow expansion (PR middle-end/77594)
  2016-09-15 23:10 [PATCH] Fix neg overflow expansion (PR middle-end/77594) Jakub Jelinek
@ 2016-09-16  5:59 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2016-09-16  5:59 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On September 16, 2016 12:48:04 AM GMT+02:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>As mentioned in the PR, during expand_arith_overflow expansion
>expand_neg_overflow falls through into expand_addsub_overflow, so
>expands
>roughly the same code twice and keeps perhaps the less efficient
>version
>around.
>
>Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
>for
>trunk?

OK (really obvious).

Thanks,
Richard.

>2016-09-16  Jakub Jelinek  <jakub@redhat.com>
>	    Eric Botcazou  <ebotcazou@adacore.com>
>
>	PR middle-end/77594
>	* internal-fn.c (expand_arith_overflow) <case MINUS_EXPR>: Don't fall
>	through into expand_addsub_overflow after expand_neg_overflow.
>
>	* gcc.target/i386/pr77594.c: New test.
>
>--- gcc/internal-fn.c.jj	2016-08-29 12:17:14.000000000 +0200
>+++ gcc/internal-fn.c	2016-09-15 09:42:09.693980531 +0200
>@@ -1833,7 +1833,10 @@ expand_arith_overflow (enum tree_code co
> 	    {
> 	    case MINUS_EXPR:
> 	      if (integer_zerop (arg0) && !unsr_p)
>-		expand_neg_overflow (loc, lhs, arg1, false);
>+		{
>+		  expand_neg_overflow (loc, lhs, arg1, false);
>+		  return;
>+		}
> 	      /* FALLTHRU */
> 	    case PLUS_EXPR:
> 	      expand_addsub_overflow (loc, code, lhs, arg0, arg1,
>--- gcc/testsuite/gcc.target/i386/pr77594.c.jj	2016-09-15
>09:44:51.879910346 +0200
>+++ gcc/testsuite/gcc.target/i386/pr77594.c	2016-09-15
>09:44:43.000000000 +0200
>@@ -0,0 +1,11 @@
>+/* PR middle-end/77594 */
>+/* { dg-do compile } */
>+/* { dg-options "-O0" } */
>+
>+int
>+foo (int a, int *b)
>+{
>+  return __builtin_sub_overflow (0, a, b);
>+}
>+
>+/* { dg-final { scan-assembler-times "\tjn?o\t" 1 } } */
>
>	Jakub


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

end of thread, other threads:[~2016-09-16  5:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-15 23:10 [PATCH] Fix neg overflow expansion (PR middle-end/77594) Jakub Jelinek
2016-09-16  5:59 ` 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).