https://gcc.gnu.org/g:5596572b6bf72031de888301ebfe8e984df04dc9
commit r15-4698-g5596572b6bf72031de888301ebfe8e984df04dc9 Author: Andrew Pinski <quic_apin...@quicinc.com> Date: Sat Oct 26 02:14:18 2024 -0700 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_apin...@quicinc.com> Diff: --- gcc/testsuite/g++.dg/eh/noncall-fp-1.C | 15 +++++++++++++++ .../g++.target/aarch64/sve/noncall-eh-fp-1.C | 16 ++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/trapping-1.c | 21 +++++++++++++++++++++ gcc/testsuite/gcc.target/aarch64/sve/trapping-1.c | 21 +++++++++++++++++++++ gcc/tree-eh.cc | 2 ++ 5 files changed, 75 insertions(+) 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 000000000000..bb6f8afb58a5 --- /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 000000000000..778b63d82d56 --- /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 000000000000..ea07562e47eb --- /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 000000000000..1ac7ac708d22 --- /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 ae0a4e3864cd..769785fad2b9 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;