public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] FMA_EXPR can cause -fnon-call-exceptions with floating point args (PR middle-end/79396)
@ 2017-02-24 21:41 Jakub Jelinek
  2017-02-25  8:23 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2017-02-24 21:41 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

On the following testcase we replace a PLUS_EXPR (which is considered
throwing with -fnon-call-exceptions when it has floating point arguments
and FP exceptions or sNaNs are enabled) with a FMA_EXPR; I believe it
can throw the same, but stmt_could_throw_1_p doesn't think so (as it is
not unary/binary/comparison).  While we could tweak the widen_mul patch
to deal with dropping EH from gsi_replace and cleaning up cfg etc., I
believe the right fix is to fix stmt_could_throw_1_p.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2017-02-24  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/79396
	* tree-eh.c (stmt_could_throw_1_p): Handle FMA_EXPR like tcc_binary
	or tcc_unary.

	* g++.dg/opt/pr79396.C: New test.

--- gcc/tree-eh.c.jj	2017-02-06 13:32:13.000000000 +0100
+++ gcc/tree-eh.c	2017-02-24 19:14:04.964854279 +0100
@@ -2738,7 +2738,8 @@ stmt_could_throw_1_p (gimple *stmt)
 
   if (TREE_CODE_CLASS (code) == tcc_comparison
       || TREE_CODE_CLASS (code) == tcc_unary
-      || TREE_CODE_CLASS (code) == tcc_binary)
+      || TREE_CODE_CLASS (code) == tcc_binary
+      || code == FMA_EXPR)
     {
       if (is_gimple_assign (stmt)
 	  && TREE_CODE_CLASS (code) == tcc_comparison)
--- gcc/testsuite/g++.dg/opt/pr79396.C.jj	2017-02-24 19:22:18.499312974 +0100
+++ gcc/testsuite/g++.dg/opt/pr79396.C	2017-02-24 19:21:38.000000000 +0100
@@ -0,0 +1,13 @@
+// PR middle-end/79396
+// { dg-do compile }
+// { dg-options "-fnon-call-exceptions -O2" }
+// { dg-additional-options "-mfma" { target i?86-*-* x86_64-*-* } }
+
+struct A { A (); ~A (); };
+
+float
+foo (float x)
+{
+  A a;
+  return __builtin_pow (x, 2) + 2;
+}

	Jakub

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

* Re: [PATCH] FMA_EXPR can cause -fnon-call-exceptions with floating point args (PR middle-end/79396)
  2017-02-24 21:41 [PATCH] FMA_EXPR can cause -fnon-call-exceptions with floating point args (PR middle-end/79396) Jakub Jelinek
@ 2017-02-25  8:23 ` Richard Biener
  2017-02-25  8:33   ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2017-02-25  8:23 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On February 24, 2017 9:56:25 PM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>On the following testcase we replace a PLUS_EXPR (which is considered
>throwing with -fnon-call-exceptions when it has floating point
>arguments
>and FP exceptions or sNaNs are enabled) with a FMA_EXPR; I believe it
>can throw the same, but stmt_could_throw_1_p doesn't think so (as it is
>not unary/binary/comparison).  While we could tweak the widen_mul patch
>to deal with dropping EH from gsi_replace and cleaning up cfg etc., I
>believe the right fix is to fix stmt_could_throw_1_p.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.  Can you make sure this is then consistent with the other throw predicates?.

Richard

>2017-02-24  Jakub Jelinek  <jakub@redhat.com>
>
>	PR middle-end/79396
>	* tree-eh.c (stmt_could_throw_1_p): Handle FMA_EXPR like tcc_binary
>	or tcc_unary.
>
>	* g++.dg/opt/pr79396.C: New test.
>
>--- gcc/tree-eh.c.jj	2017-02-06 13:32:13.000000000 +0100
>+++ gcc/tree-eh.c	2017-02-24 19:14:04.964854279 +0100
>@@ -2738,7 +2738,8 @@ stmt_could_throw_1_p (gimple *stmt)
> 
>   if (TREE_CODE_CLASS (code) == tcc_comparison
>       || TREE_CODE_CLASS (code) == tcc_unary
>-      || TREE_CODE_CLASS (code) == tcc_binary)
>+      || TREE_CODE_CLASS (code) == tcc_binary
>+      || code == FMA_EXPR)
>     {
>       if (is_gimple_assign (stmt)
> 	  && TREE_CODE_CLASS (code) == tcc_comparison)
>--- gcc/testsuite/g++.dg/opt/pr79396.C.jj	2017-02-24 19:22:18.499312974
>+0100
>+++ gcc/testsuite/g++.dg/opt/pr79396.C	2017-02-24 19:21:38.000000000
>+0100
>@@ -0,0 +1,13 @@
>+// PR middle-end/79396
>+// { dg-do compile }
>+// { dg-options "-fnon-call-exceptions -O2" }
>+// { dg-additional-options "-mfma" { target i?86-*-* x86_64-*-* } }
>+
>+struct A { A (); ~A (); };
>+
>+float
>+foo (float x)
>+{
>+  A a;
>+  return __builtin_pow (x, 2) + 2;
>+}
>
>	Jakub

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

* Re: [PATCH] FMA_EXPR can cause -fnon-call-exceptions with floating point args (PR middle-end/79396)
  2017-02-25  8:23 ` Richard Biener
@ 2017-02-25  8:33   ` Jakub Jelinek
  2017-02-27  8:19     ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2017-02-25  8:33 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On Sat, Feb 25, 2017 at 08:42:33AM +0100, Richard Biener wrote:
> On February 24, 2017 9:56:25 PM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
> >Hi!
> >
> >On the following testcase we replace a PLUS_EXPR (which is considered
> >throwing with -fnon-call-exceptions when it has floating point
> >arguments
> >and FP exceptions or sNaNs are enabled) with a FMA_EXPR; I believe it
> >can throw the same, but stmt_could_throw_1_p doesn't think so (as it is
> >not unary/binary/comparison).  While we could tweak the widen_mul patch
> >to deal with dropping EH from gsi_replace and cleaning up cfg etc., I
> >believe the right fix is to fix stmt_could_throw_1_p.
> >
> >Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> OK.  Can you make sure this is then consistent with the other throw predicates?.

may_trap_p_1 handles FMA right, no idea what other predicates could cover
that on RTL.  But you're right, operation_could_trap_p used by
tree_could_trap_p needs the same treatment:

2017-02-25  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/79396
	* tree-eh.c (operation_could_trap_p, stmt_could_throw_1_p): Handle
	FMA_EXPR like tcc_binary or tcc_unary.

	* g++.dg/opt/pr79396.C: New test.

--- gcc/tree-eh.c.jj	2017-02-24 21:39:01.240088691 +0100
+++ gcc/tree-eh.c	2017-02-25 09:21:06.017859379 +0100
@@ -2513,7 +2513,8 @@ operation_could_trap_p (enum tree_code o
 
   if (TREE_CODE_CLASS (op) != tcc_comparison
       && TREE_CODE_CLASS (op) != tcc_unary
-      && TREE_CODE_CLASS (op) != tcc_binary)
+      && TREE_CODE_CLASS (op) != tcc_binary
+      && op != FMA_EXPR)
     return false;
 
   return operation_could_trap_helper_p (op, fp_operation, honor_trapv,
@@ -2738,7 +2739,8 @@ stmt_could_throw_1_p (gimple *stmt)
 
   if (TREE_CODE_CLASS (code) == tcc_comparison
       || TREE_CODE_CLASS (code) == tcc_unary
-      || TREE_CODE_CLASS (code) == tcc_binary)
+      || TREE_CODE_CLASS (code) == tcc_binary
+      || code == FMA_EXPR)
     {
       if (is_gimple_assign (stmt)
 	  && TREE_CODE_CLASS (code) == tcc_comparison)
--- gcc/testsuite/g++.dg/opt/pr79396.C.jj	2017-02-25 09:20:03.608706718 +0100
+++ gcc/testsuite/g++.dg/opt/pr79396.C	2017-02-25 09:20:03.607706732 +0100
@@ -0,0 +1,13 @@
+// PR middle-end/79396
+// { dg-do compile }
+// { dg-options "-fnon-call-exceptions -O2" }
+// { dg-additional-options "-mfma" { target i?86-*-* x86_64-*-* } }
+
+struct A { A (); ~A (); };
+
+float
+foo (float x)
+{
+  A a;
+  return __builtin_pow (x, 2) + 2;
+}


	Jakub

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

* Re: [PATCH] FMA_EXPR can cause -fnon-call-exceptions with floating point args (PR middle-end/79396)
  2017-02-25  8:33   ` Jakub Jelinek
@ 2017-02-27  8:19     ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2017-02-27  8:19 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Sat, 25 Feb 2017, Jakub Jelinek wrote:

> On Sat, Feb 25, 2017 at 08:42:33AM +0100, Richard Biener wrote:
> > On February 24, 2017 9:56:25 PM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
> > >Hi!
> > >
> > >On the following testcase we replace a PLUS_EXPR (which is considered
> > >throwing with -fnon-call-exceptions when it has floating point
> > >arguments
> > >and FP exceptions or sNaNs are enabled) with a FMA_EXPR; I believe it
> > >can throw the same, but stmt_could_throw_1_p doesn't think so (as it is
> > >not unary/binary/comparison).  While we could tweak the widen_mul patch
> > >to deal with dropping EH from gsi_replace and cleaning up cfg etc., I
> > >believe the right fix is to fix stmt_could_throw_1_p.
> > >
> > >Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> > 
> > OK.  Can you make sure this is then consistent with the other throw predicates?.
> 
> may_trap_p_1 handles FMA right, no idea what other predicates could cover
> that on RTL.  But you're right, operation_could_trap_p used by
> tree_could_trap_p needs the same treatment:

Yes, that was what I remembered (used for example by vn_nary_may_trap).

Ok.

Thanks,
Richard.

> 2017-02-25  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR middle-end/79396
> 	* tree-eh.c (operation_could_trap_p, stmt_could_throw_1_p): Handle
> 	FMA_EXPR like tcc_binary or tcc_unary.
> 
> 	* g++.dg/opt/pr79396.C: New test.
> 
> --- gcc/tree-eh.c.jj	2017-02-24 21:39:01.240088691 +0100
> +++ gcc/tree-eh.c	2017-02-25 09:21:06.017859379 +0100
> @@ -2513,7 +2513,8 @@ operation_could_trap_p (enum tree_code o
>  
>    if (TREE_CODE_CLASS (op) != tcc_comparison
>        && TREE_CODE_CLASS (op) != tcc_unary
> -      && TREE_CODE_CLASS (op) != tcc_binary)
> +      && TREE_CODE_CLASS (op) != tcc_binary
> +      && op != FMA_EXPR)
>      return false;
>  
>    return operation_could_trap_helper_p (op, fp_operation, honor_trapv,
> @@ -2738,7 +2739,8 @@ stmt_could_throw_1_p (gimple *stmt)
>  
>    if (TREE_CODE_CLASS (code) == tcc_comparison
>        || TREE_CODE_CLASS (code) == tcc_unary
> -      || TREE_CODE_CLASS (code) == tcc_binary)
> +      || TREE_CODE_CLASS (code) == tcc_binary
> +      || code == FMA_EXPR)
>      {
>        if (is_gimple_assign (stmt)
>  	  && TREE_CODE_CLASS (code) == tcc_comparison)
> --- gcc/testsuite/g++.dg/opt/pr79396.C.jj	2017-02-25 09:20:03.608706718 +0100
> +++ gcc/testsuite/g++.dg/opt/pr79396.C	2017-02-25 09:20:03.607706732 +0100
> @@ -0,0 +1,13 @@
> +// PR middle-end/79396
> +// { dg-do compile }
> +// { dg-options "-fnon-call-exceptions -O2" }
> +// { dg-additional-options "-mfma" { target i?86-*-* x86_64-*-* } }
> +
> +struct A { A (); ~A (); };
> +
> +float
> +foo (float x)
> +{
> +  A a;
> +  return __builtin_pow (x, 2) + 2;
> +}
> 
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)

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

end of thread, other threads:[~2017-02-27  8:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-24 21:41 [PATCH] FMA_EXPR can cause -fnon-call-exceptions with floating point args (PR middle-end/79396) Jakub Jelinek
2017-02-25  8:23 ` Richard Biener
2017-02-25  8:33   ` Jakub Jelinek
2017-02-27  8:19     ` 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).