]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree: Mark PAREN_EXPR and VEC_DUPLICATE_EXPR as non-trapping [PR117234]
authorAndrew Pinski <quic_apinski@quicinc.com>
Sat, 26 Oct 2024 09:14:18 +0000 (02:14 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Sat, 26 Oct 2024 18:44:39 +0000 (11:44 -0700)
While looking to fix a possible trapping issue in PHI-OPT's factor,
I noticed that some tree codes could be marked as trapping even
though they don't have a possibility to trap. In the case of PAREN_EXPR,
it is basically a nop except when it comes to association across it so
it can't trap.
In the case of VEC_DUPLICATE_EXPR, it is similar to a CONSTRUCTOR, so it
can't trap.

This fixes those 2 issues and adds 4 testcases, 2 which are specific to aarch64
since the only way to get a VEC_DUPLICATE_EXPR is to use intrinsics currently.

Build and tested for aarch64-linux-gnu.

PR tree-optimization/117234

gcc/ChangeLog:

* tree-eh.cc (operation_could_trap_helper_p): Treat
PAREN_EXPR and VEC_DUPLICATE_EXPR like constructing
expressions.

gcc/testsuite/ChangeLog:

* g++.dg/eh/noncall-fp-1.C: New test.
* g++.target/aarch64/sve/noncall-eh-fp-1.C: New test.
* gcc.dg/tree-ssa/trapping-1.c: New test.
* gcc.target/aarch64/sve/trapping-1.c: New test.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/testsuite/g++.dg/eh/noncall-fp-1.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/sve/noncall-eh-fp-1.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/trapping-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/sve/trapping-1.c [new file with mode: 0644]
gcc/tree-eh.cc

diff --git a/gcc/testsuite/g++.dg/eh/noncall-fp-1.C b/gcc/testsuite/g++.dg/eh/noncall-fp-1.C
new file mode 100644 (file)
index 0000000..bb6f8af
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fnon-call-exceptions -fdump-tree-optimized" } */
+
+/* PR tree-optimization/117234  */
+/* PAREN_EXPR should not be declared as trapping.  */
+
+float f1(float a)
+{
+  try {
+    return __builtin_assoc_barrier (a);
+  }  catch(...)
+  { __builtin_trap (); }
+}
+
+/* { dg-final { scan-tree-dump-not "__builtin_trap" "optimized" } } */
diff --git a/gcc/testsuite/g++.target/aarch64/sve/noncall-eh-fp-1.C b/gcc/testsuite/g++.target/aarch64/sve/noncall-eh-fp-1.C
new file mode 100644 (file)
index 0000000..778b63d
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fnon-call-exceptions -fdump-tree-optimized" } */
+
+/* PR tree-optimization/117234  */
+/* VEC_DUPLICATE_EXPR should not be declared as trapping.  */
+#include <arm_sve.h>
+
+svfloat32_t f(float a)
+{
+  try {
+    return svdup_f32(a);
+  }  catch(...)
+  { __builtin_trap (); }
+}
+
+/* { dg-final { scan-tree-dump-not "__builtin_trap" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/trapping-1.c b/gcc/testsuite/gcc.dg/tree-ssa/trapping-1.c
new file mode 100644 (file)
index 0000000..ea07562
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-lim-details" } */
+
+/* PR tree-optimization/117234  */
+/* PAREN_EXPR should not be declared as
+   a trapping.  */
+
+float f1(float a, int t, _Bool *b, float c)
+{
+  float tt = 0;
+  for (int i = 0; i < t; i++)
+  {
+    if (b[i])
+      tt *= -__builtin_assoc_barrier (-a);
+  }
+  return tt;
+}
+
+/* There should be 3 `invariant up to level`, two for each `-` and one
+   for the PAREN_EXPR. */
+/* { dg-final { scan-tree-dump-times "invariant up to level" 3 "lim2" } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/sve/trapping-1.c b/gcc/testsuite/gcc.target/aarch64/sve/trapping-1.c
new file mode 100644 (file)
index 0000000..1ac7ac7
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-lim-details" } */
+
+/* PR tree-optimization/117234  */
+/* VEC_DUPLICATE_EXPR should not be declared as
+   a trapping.  */
+#include <arm_sve.h>
+
+svfloat32_t f(float a, int t, _Bool *b)
+{
+  svfloat32_t tt = svdup_f32(0.0);
+  for (int i =0 ;i < t; i++)
+  {
+    if (b[i])
+      tt = svadd_f32_z(svptrue_b32(),tt,svdup_f32(a));
+  }
+  return tt;
+}
+
+/* There should be 1 `invariant up to level`, one for the VEC_DUPLICATE_EXPR. */
+/* { dg-final { scan-tree-dump-times "invariant up to level" 1 "lim2" } } */
index ae0a4e3864cd51b3654355af71a4ffe432064b4c..769785fad2b98d9ab38462c80c0000dafa76ae5b 100644 (file)
@@ -2532,6 +2532,8 @@ operation_could_trap_helper_p (enum tree_code op,
 
     case COMPLEX_EXPR:
     case CONSTRUCTOR:
+    case VEC_DUPLICATE_EXPR:
+    case PAREN_EXPR:
       /* Constructing an object cannot trap.  */
       return false;