diff options
author | Andrew Pinski <quic_apinski@quicinc.com> | 2024-10-26 02:14:18 -0700 |
---|---|---|
committer | Andrew Pinski <quic_apinski@quicinc.com> | 2024-10-26 11:44:39 -0700 |
commit | 5596572b6bf72031de888301ebfe8e984df04dc9 (patch) | |
tree | 893ad12049f57649f13a807923a11f24b2843c4d /gcc | |
parent | 4727bfb37701f3fef98a5f8b60dcd2daa82e8143 (diff) | |
download | gcc-5596572b6bf72031de888301ebfe8e984df04dc9.zip gcc-5596572b6bf72031de888301ebfe8e984df04dc9.tar.gz gcc-5596572b6bf72031de888301ebfe8e984df04dc9.tar.bz2 |
tree: Mark PAREN_EXPR and VEC_DUPLICATE_EXPR as non-trapping [PR117234]
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>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/g++.dg/eh/noncall-fp-1.C | 15 | ||||
-rw-r--r-- | gcc/testsuite/g++.target/aarch64/sve/noncall-eh-fp-1.C | 16 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/trapping-1.c | 21 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/aarch64/sve/trapping-1.c | 21 | ||||
-rw-r--r-- | gcc/tree-eh.cc | 2 |
5 files changed, 75 insertions, 0 deletions
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 index 0000000..bb6f8af --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/noncall-fp-1.C @@ -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 index 0000000..778b63d --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/sve/noncall-eh-fp-1.C @@ -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 index 0000000..ea07562 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/trapping-1.c @@ -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 index 0000000..1ac7ac7 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/trapping-1.c @@ -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" } } */ diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc index ae0a4e3..769785f 100644 --- a/gcc/tree-eh.cc +++ b/gcc/tree-eh.cc @@ -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; |