public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix ICE with widen_mult and -ftrapv (PR tree-optimization/83523)
@ 2017-12-21 17:54 Jakub Jelinek
  2017-12-21 18:57 ` Richard Biener
  2017-12-21 23:09 ` Jeff Law
  0 siblings, 2 replies; 3+ messages in thread
From: Jakub Jelinek @ 2017-12-21 17:54 UTC (permalink / raw)
  To: Richard Biener, Jeff Law; +Cc: gcc-patches

Hi!

Converting widening mult, or widen_{plus,minus}_expr, or integral mult to
fma is IMNSHO undesirable with -ftrapv for signed types - the expansion of
those doesn't detect overflows and by giving up we don't need to worry about
formerly trapping MULT_EXPR becoming something that isn't trapping and
performing EH cleanups etc.

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

2017-12-21  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/83523
	* tree-ssa-math-opts.c (is_widening_mult_p): Return false if
	for INTEGER_TYPE TYPE_OVERFLOW_TRAPS.
	(convert_mult_to_fma): Likewise.

	* g++.dg/tree-ssa/pr83523.C: New test.

--- gcc/tree-ssa-math-opts.c.jj	2017-12-21 09:43:19.000000000 +0100
+++ gcc/tree-ssa-math-opts.c	2017-12-21 12:22:10.576488270 +0100
@@ -2196,8 +2196,12 @@ is_widening_mult_p (gimple *stmt,
 {
   tree type = TREE_TYPE (gimple_assign_lhs (stmt));
 
-  if (TREE_CODE (type) != INTEGER_TYPE
-      && TREE_CODE (type) != FIXED_POINT_TYPE)
+  if (TREE_CODE (type) == INTEGER_TYPE)
+    {
+      if (TYPE_OVERFLOW_TRAPS (type))
+	return false;
+    }
+  else if (TREE_CODE (type) != FIXED_POINT_TYPE)
     return false;
 
   if (!is_widening_mult_rhs_p (type, gimple_assign_rhs1 (stmt), type1_out,
@@ -2656,7 +2660,7 @@ convert_mult_to_fma (gimple *mul_stmt, t
 
   /* We don't want to do bitfield reduction ops.  */
   if (INTEGRAL_TYPE_P (type)
-      && !type_has_mode_precision_p (type))
+      && (!type_has_mode_precision_p (type) || TYPE_OVERFLOW_TRAPS (type)))
     return false;
 
   /* If the target doesn't support it, don't generate it.  We assume that
--- gcc/testsuite/g++.dg/tree-ssa/pr83523.C.jj	2017-12-21 12:20:56.555403891 +0100
+++ gcc/testsuite/g++.dg/tree-ssa/pr83523.C	2017-12-21 12:20:02.000000000 +0100
@@ -0,0 +1,25 @@
+// PR tree-optimization/83523
+// { dg-do compile }
+// { dg-options "-O2 -fexceptions -fnon-call-exceptions -ftrapv" }
+
+#ifdef __SIZEOF_INT128__
+typedef __int128 T;
+typedef long long int U;
+#else
+typedef long long int T;
+typedef int U;
+#endif
+
+struct S { S (); ~S (); };
+void bar ();
+
+T
+foo (U x, U y)
+{
+  T z = x;
+  S s;
+  bar ();
+  z *= y;
+  bar ();
+  return z;
+}

	Jakub

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

* Re: [PATCH] Fix ICE with widen_mult and -ftrapv (PR tree-optimization/83523)
  2017-12-21 17:54 [PATCH] Fix ICE with widen_mult and -ftrapv (PR tree-optimization/83523) Jakub Jelinek
@ 2017-12-21 18:57 ` Richard Biener
  2017-12-21 23:09 ` Jeff Law
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Biener @ 2017-12-21 18:57 UTC (permalink / raw)
  To: Jakub Jelinek, Jeff Law; +Cc: gcc-patches

On December 21, 2017 6:54:51 PM GMT+01:00, Jakub Jelinek <jakub@redhat.com> wrote:
>Hi!
>
>Converting widening mult, or widen_{plus,minus}_expr, or integral mult
>to
>fma is IMNSHO undesirable with -ftrapv for signed types - the expansion
>of
>those doesn't detect overflows and by giving up we don't need to worry
>about
>formerly trapping MULT_EXPR becoming something that isn't trapping and
>performing EH cleanups etc.
>
>Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK. 

Richard. 

>2017-12-21  Jakub Jelinek  <jakub@redhat.com>
>
>	PR tree-optimization/83523
>	* tree-ssa-math-opts.c (is_widening_mult_p): Return false if
>	for INTEGER_TYPE TYPE_OVERFLOW_TRAPS.
>	(convert_mult_to_fma): Likewise.
>
>	* g++.dg/tree-ssa/pr83523.C: New test.
>
>--- gcc/tree-ssa-math-opts.c.jj	2017-12-21 09:43:19.000000000 +0100
>+++ gcc/tree-ssa-math-opts.c	2017-12-21 12:22:10.576488270 +0100
>@@ -2196,8 +2196,12 @@ is_widening_mult_p (gimple *stmt,
> {
>   tree type = TREE_TYPE (gimple_assign_lhs (stmt));
> 
>-  if (TREE_CODE (type) != INTEGER_TYPE
>-      && TREE_CODE (type) != FIXED_POINT_TYPE)
>+  if (TREE_CODE (type) == INTEGER_TYPE)
>+    {
>+      if (TYPE_OVERFLOW_TRAPS (type))
>+	return false;
>+    }
>+  else if (TREE_CODE (type) != FIXED_POINT_TYPE)
>     return false;
> 
>if (!is_widening_mult_rhs_p (type, gimple_assign_rhs1 (stmt),
>type1_out,
>@@ -2656,7 +2660,7 @@ convert_mult_to_fma (gimple *mul_stmt, t
> 
>   /* We don't want to do bitfield reduction ops.  */
>   if (INTEGRAL_TYPE_P (type)
>-      && !type_has_mode_precision_p (type))
>+      && (!type_has_mode_precision_p (type) || TYPE_OVERFLOW_TRAPS
>(type)))
>     return false;
> 
>/* If the target doesn't support it, don't generate it.  We assume that
>--- gcc/testsuite/g++.dg/tree-ssa/pr83523.C.jj	2017-12-21
>12:20:56.555403891 +0100
>+++ gcc/testsuite/g++.dg/tree-ssa/pr83523.C	2017-12-21
>12:20:02.000000000 +0100
>@@ -0,0 +1,25 @@
>+// PR tree-optimization/83523
>+// { dg-do compile }
>+// { dg-options "-O2 -fexceptions -fnon-call-exceptions -ftrapv" }
>+
>+#ifdef __SIZEOF_INT128__
>+typedef __int128 T;
>+typedef long long int U;
>+#else
>+typedef long long int T;
>+typedef int U;
>+#endif
>+
>+struct S { S (); ~S (); };
>+void bar ();
>+
>+T
>+foo (U x, U y)
>+{
>+  T z = x;
>+  S s;
>+  bar ();
>+  z *= y;
>+  bar ();
>+  return z;
>+}
>
>	Jakub

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

* Re: [PATCH] Fix ICE with widen_mult and -ftrapv (PR tree-optimization/83523)
  2017-12-21 17:54 [PATCH] Fix ICE with widen_mult and -ftrapv (PR tree-optimization/83523) Jakub Jelinek
  2017-12-21 18:57 ` Richard Biener
@ 2017-12-21 23:09 ` Jeff Law
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Law @ 2017-12-21 23:09 UTC (permalink / raw)
  To: Jakub Jelinek, Richard Biener; +Cc: gcc-patches

On 12/21/2017 10:54 AM, Jakub Jelinek wrote:
> Hi!
> 
> Converting widening mult, or widen_{plus,minus}_expr, or integral mult to
> fma is IMNSHO undesirable with -ftrapv for signed types - the expansion of
> those doesn't detect overflows and by giving up we don't need to worry about
> formerly trapping MULT_EXPR becoming something that isn't trapping and
> performing EH cleanups etc.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2017-12-21  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR tree-optimization/83523
> 	* tree-ssa-math-opts.c (is_widening_mult_p): Return false if
> 	for INTEGER_TYPE TYPE_OVERFLOW_TRAPS.
> 	(convert_mult_to_fma): Likewise.
> 
> 	* g++.dg/tree-ssa/pr83523.C: New test.
OK.
jeff

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

end of thread, other threads:[~2017-12-21 23:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-21 17:54 [PATCH] Fix ICE with widen_mult and -ftrapv (PR tree-optimization/83523) Jakub Jelinek
2017-12-21 18:57 ` Richard Biener
2017-12-21 23:09 ` Jeff Law

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