public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-9259] middle-end/103181 - fix operation_could_trap_p for vector division
@ 2021-11-22  8:00 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-11-22  8:00 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2f0c8f74daef93c0c7b33294213e7db6df58c4d1

commit r11-9259-g2f0c8f74daef93c0c7b33294213e7db6df58c4d1
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Nov 11 09:40:36 2021 +0100

    middle-end/103181 - fix operation_could_trap_p for vector division
    
    For integer vector division we only checked for all zero vector
    constants rather than checking whether any element in the constant
    vector is zero.
    
    It also fixes the adjustment to operation_could_trap_helper_p
    where I failed to realize that RDIV_EXPR is also used for
    fixed-point types.  It also fixes that handling by properly
    checking for a fixed_zerop divisor.
    
    2021-11-11  Richard Biener  <rguenther@suse.de>
    
            PR middle-end/103181
            PR middle-end/103248
            * tree-eh.c (operation_could_trap_helper_p): Properly
            check vector constants for a zero element for integer
            division.  Separate floating point and integer division code.
            Properly handle fixed-point RDIV_EXPR.
    
            * gcc.dg/torture/pr103181.c: New testcase.
            * gcc.dg/pr103248.c: Likewise.

Diff:
---
 gcc/testsuite/gcc.dg/pr103248.c         |  8 ++++++++
 gcc/testsuite/gcc.dg/torture/pr103181.c | 24 ++++++++++++++++++++++++
 gcc/tree-eh.c                           | 32 +++++++++++++++++++++++++++-----
 3 files changed, 59 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/pr103248.c b/gcc/testsuite/gcc.dg/pr103248.c
new file mode 100644
index 00000000000..da6232d21ee
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr103248.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target fixed_point } */
+/* { dg-options "-fnon-call-exceptions" } */
+
+_Accum sa;
+int c;
+
+void div_csa() { c /= sa; }
diff --git a/gcc/testsuite/gcc.dg/torture/pr103181.c b/gcc/testsuite/gcc.dg/torture/pr103181.c
new file mode 100644
index 00000000000..6bc705ab52e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr103181.c
@@ -0,0 +1,24 @@
+/* { dg-do run } */
+
+typedef unsigned char __attribute__((__vector_size__ (2))) U;
+typedef unsigned short S;
+typedef unsigned int __attribute__((__vector_size__ (64))) V;
+
+V v;
+U a, b, c;
+
+U
+foo (S s)
+{
+  v += __builtin_bswap16 (s) || (S) (a / ((U){3, 0}));
+  return b + c;
+}
+
+int
+main (void)
+{
+  U x = foo (4);
+  if (x[0] || x[1])
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c
index 08c97325484..0bc1b5d9706 100644
--- a/gcc/tree-eh.c
+++ b/gcc/tree-eh.c
@@ -2454,13 +2454,35 @@ operation_could_trap_helper_p (enum tree_code op,
     case FLOOR_MOD_EXPR:
     case ROUND_MOD_EXPR:
     case TRUNC_MOD_EXPR:
-    case RDIV_EXPR:
-      if (honor_snans)
-	return true;
-      if (fp_operation)
-	return flag_trapping_math;
       if (!TREE_CONSTANT (divisor) || integer_zerop (divisor))
         return true;
+      if (TREE_CODE (divisor) == VECTOR_CST)
+	{
+	  /* Inspired by initializer_each_zero_or_onep.  */
+	  unsigned HOST_WIDE_INT nelts = vector_cst_encoded_nelts (divisor);
+	  if (VECTOR_CST_STEPPED_P (divisor)
+	      && !TYPE_VECTOR_SUBPARTS (TREE_TYPE (divisor))
+		    .is_constant (&nelts))
+	    return true;
+	  for (unsigned int i = 0; i < nelts; ++i)
+	    {
+	      tree elt = vector_cst_elt (divisor, i);
+	      if (integer_zerop (elt))
+		return true;
+	    }
+	}
+      return false;
+
+    case RDIV_EXPR:
+      if (fp_operation)
+	{
+	  if (honor_snans)
+	    return true;
+	  return flag_trapping_math;
+	}
+      /* Fixed point operations also use RDIV_EXPR.  */
+      if (!TREE_CONSTANT (divisor) || fixed_zerop (divisor))
+	return true;
       return false;
 
     case LT_EXPR:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-22  8:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22  8:00 [gcc r11-9259] middle-end/103181 - fix operation_could_trap_p for vector division 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).