public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix recip opt ICEs with -fnon-call-exceptions (PR tree-optimization/90090)
@ 2019-04-16  7:43 Jakub Jelinek
  2019-04-16  7:52 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2019-04-16  7:43 UTC (permalink / raw)
  To: Richard Biener, Jeff Law; +Cc: gcc-patches

Hi!

While we in theory could move over the EH stuff from the division
instructions to the multiplication ones (right now we do not do even that),
we would need to add EH even to the divisions added by insert_reciprocals.

The following patch just punts on divisions that can throw internally,
bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

If it affects some important -fnon-call-exceptions codebase and anyone is
interested in handling it differently, it can be always reverted and handled
properly.

2019-04-16  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/90090
	* tree-ssa-math-opts.c (is_division_by): Ignore divisions that can
	throw internally.
	(is_division_by_square): Likewise.  Formatting fix.

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

--- gcc/tree-ssa-math-opts.c.jj	2019-04-08 10:11:28.620219138 +0200
+++ gcc/tree-ssa-math-opts.c	2019-04-15 09:42:22.173868303 +0200
@@ -334,7 +334,8 @@ is_division_by (gimple *use_stmt, tree d
 	 /* Do not recognize x / x as valid division, as we are getting
 	    confused later by replacing all immediate uses x in such
 	    a stmt.  */
-	 && gimple_assign_rhs1 (use_stmt) != def;
+	 && gimple_assign_rhs1 (use_stmt) != def
+	 && !stmt_can_throw_internal (cfun, use_stmt);
 }
 
 /* Return TRUE if USE_STMT is a multiplication of DEF by A.  */
@@ -367,13 +368,12 @@ is_division_by_square (gimple *use_stmt,
 {
   if (gimple_code (use_stmt) == GIMPLE_ASSIGN
       && gimple_assign_rhs_code (use_stmt) == RDIV_EXPR
-      && gimple_assign_rhs1 (use_stmt) != gimple_assign_rhs2 (use_stmt))
+      && gimple_assign_rhs1 (use_stmt) != gimple_assign_rhs2 (use_stmt)
+      && !stmt_can_throw_internal (cfun, use_stmt))
     {
       tree denominator = gimple_assign_rhs2 (use_stmt);
       if (TREE_CODE (denominator) == SSA_NAME)
-	{
-	  return is_square_of (SSA_NAME_DEF_STMT (denominator), def);
-	}
+	return is_square_of (SSA_NAME_DEF_STMT (denominator), def);
     }
   return 0;
 }
--- gcc/testsuite/g++.dg/opt/pr90090.C.jj	2019-04-15 10:34:58.151821097 +0200
+++ gcc/testsuite/g++.dg/opt/pr90090.C	2019-04-15 10:36:12.856620867 +0200
@@ -0,0 +1,19 @@
+// PR tree-optimization/90090
+// { dg-do compile }
+// { dg-options "-Ofast -fno-associative-math -fsignaling-nans -fno-tree-dce -fnon-call-exceptions" }
+
+double bar (double, double, double, double, double);
+double baz ();
+
+double
+foo (double a)
+{
+  try
+    {
+      return bar (1.0/a, 2.0/a, 4.0/a, 8.0/a, 16.0/a);
+    }
+  catch (...)
+    {
+      return baz ();
+    }
+}

	Jakub

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

* Re: [PATCH] Fix recip opt ICEs with -fnon-call-exceptions (PR tree-optimization/90090)
  2019-04-16  7:43 [PATCH] Fix recip opt ICEs with -fnon-call-exceptions (PR tree-optimization/90090) Jakub Jelinek
@ 2019-04-16  7:52 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2019-04-16  7:52 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jeff Law, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 2914 bytes --]

On Tue, 16 Apr 2019, Jakub Jelinek wrote:

> Hi!
> 
> While we in theory could move over the EH stuff from the division
> instructions to the multiplication ones (right now we do not do even that),
> we would need to add EH even to the divisions added by insert_reciprocals.
> 
> The following patch just punts on divisions that can throw internally,
> bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Richard.

> If it affects some important -fnon-call-exceptions codebase and anyone is
> interested in handling it differently, it can be always reverted and handled
> properly.
> 
> 2019-04-16  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/90090
> 	* tree-ssa-math-opts.c (is_division_by): Ignore divisions that can
> 	throw internally.
> 	(is_division_by_square): Likewise.  Formatting fix.
> 
> 	* g++.dg/opt/pr90090.C: New test.
> 
> --- gcc/tree-ssa-math-opts.c.jj	2019-04-08 10:11:28.620219138 +0200
> +++ gcc/tree-ssa-math-opts.c	2019-04-15 09:42:22.173868303 +0200
> @@ -334,7 +334,8 @@ is_division_by (gimple *use_stmt, tree d
>  	 /* Do not recognize x / x as valid division, as we are getting
>  	    confused later by replacing all immediate uses x in such
>  	    a stmt.  */
> -	 && gimple_assign_rhs1 (use_stmt) != def;
> +	 && gimple_assign_rhs1 (use_stmt) != def
> +	 && !stmt_can_throw_internal (cfun, use_stmt);
>  }
>  
>  /* Return TRUE if USE_STMT is a multiplication of DEF by A.  */
> @@ -367,13 +368,12 @@ is_division_by_square (gimple *use_stmt,
>  {
>    if (gimple_code (use_stmt) == GIMPLE_ASSIGN
>        && gimple_assign_rhs_code (use_stmt) == RDIV_EXPR
> -      && gimple_assign_rhs1 (use_stmt) != gimple_assign_rhs2 (use_stmt))
> +      && gimple_assign_rhs1 (use_stmt) != gimple_assign_rhs2 (use_stmt)
> +      && !stmt_can_throw_internal (cfun, use_stmt))
>      {
>        tree denominator = gimple_assign_rhs2 (use_stmt);
>        if (TREE_CODE (denominator) == SSA_NAME)
> -	{
> -	  return is_square_of (SSA_NAME_DEF_STMT (denominator), def);
> -	}
> +	return is_square_of (SSA_NAME_DEF_STMT (denominator), def);
>      }
>    return 0;
>  }
> --- gcc/testsuite/g++.dg/opt/pr90090.C.jj	2019-04-15 10:34:58.151821097 +0200
> +++ gcc/testsuite/g++.dg/opt/pr90090.C	2019-04-15 10:36:12.856620867 +0200
> @@ -0,0 +1,19 @@
> +// PR tree-optimization/90090
> +// { dg-do compile }
> +// { dg-options "-Ofast -fno-associative-math -fsignaling-nans -fno-tree-dce -fnon-call-exceptions" }
> +
> +double bar (double, double, double, double, double);
> +double baz ();
> +
> +double
> +foo (double a)
> +{
> +  try
> +    {
> +      return bar (1.0/a, 2.0/a, 4.0/a, 8.0/a, 16.0/a);
> +    }
> +  catch (...)
> +    {
> +      return baz ();
> +    }
> +}
> 
> 	Jakub
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany;
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah; HRB 21284 (AG NÌrnberg)

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

end of thread, other threads:[~2019-04-16  7:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-16  7:43 [PATCH] Fix recip opt ICEs with -fnon-call-exceptions (PR tree-optimization/90090) Jakub Jelinek
2019-04-16  7:52 ` 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).