From 87d6dae308d604bad111b1c0bfea7835888eed8d Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 8 Aug 2020 11:07:09 +0200 Subject: [PATCH] openmp: Avoid floating point comparison at the end of bb with -fnon-call-exceptions The following testcase ICEs with -fexceptions -fnon-call-exceptions because in that mode floating point comparisons should not be done at the end of bb in GIMPLE_COND. Fixed by forcing it into a bool SSA_NAME and comparing that against false. 2020-08-08 Jakub Jelinek PR tree-optimization/96424 * omp-expand.c: Include tree-eh.h. (expand_omp_for_init_vars): Handle -fexceptions -fnon-call-exceptions by forcing floating point comparison into a bool temporary. * c-c++-common/gomp/pr96424.c: New test. --- gcc/omp-expand.c | 22 ++++++++++++++++++---- gcc/testsuite/c-c++-common/gomp/pr96424.c | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/pr96424.c diff --git a/gcc/omp-expand.c b/gcc/omp-expand.c index ea4c77aff98..eb37b38e25d 100644 --- a/gcc/omp-expand.c +++ b/gcc/omp-expand.c @@ -58,6 +58,7 @@ along with GCC; see the file COPYING3. If not see #include "gimple-pretty-print.h" #include "stringpool.h" #include "attribs.h" +#include "tree-eh.h" /* OMP region information. Every parallel and workshare directive is enclosed between two markers, the OMP_* directive @@ -2553,10 +2554,23 @@ expand_omp_for_init_vars (struct omp_for_data *fd, gimple_stmt_iterator *gsi, flag_rounding_math = save_flag_rounding_math; t = force_gimple_operand_gsi (gsi, t, true, NULL_TREE, false, GSI_CONTINUE_LINKING); - cond_stmt - = gimple_build_cond (LT_EXPR, t, - build_zero_cst (double_type_node), - NULL_TREE, NULL_TREE); + if (flag_exceptions + && cfun->can_throw_non_call_exceptions + && operation_could_trap_p (LT_EXPR, true, false, NULL_TREE)) + { + tree tem = fold_build2 (LT_EXPR, boolean_type_node, t, + build_zero_cst (double_type_node)); + tem = force_gimple_operand_gsi (gsi, tem, true, NULL_TREE, + false, GSI_CONTINUE_LINKING); + cond_stmt = gimple_build_cond (NE_EXPR, tem, + boolean_false_node, + NULL_TREE, NULL_TREE); + } + else + cond_stmt + = gimple_build_cond (LT_EXPR, t, + build_zero_cst (double_type_node), + NULL_TREE, NULL_TREE); gsi_insert_after (gsi, cond_stmt, GSI_CONTINUE_LINKING); e = split_block (gsi_bb (*gsi), cond_stmt); basic_block bb1 = e->src; diff --git a/gcc/testsuite/c-c++-common/gomp/pr96424.c b/gcc/testsuite/c-c++-common/gomp/pr96424.c new file mode 100644 index 00000000000..2a3dd007730 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/pr96424.c @@ -0,0 +1,23 @@ +/* PR tree-optimization/96424 */ +/* { dg-do compile } */ +/* { dg-options "-fopenmp -O0 -fexceptions -fnon-call-exceptions -fprofile-use -Wno-missing-profile" } */ + +void +foo (void) +{ + int i, j; +#pragma omp for collapse (2) + for (i = 0; i < 10; ++i) + for (j = 0; j <= i; ++j) + ; +} + +void +bar (void) +{ + int i, j; +#pragma omp for collapse (2) + for (i = 0; i < 10; ++i) + for (j = 0; j < i; ++j) + ; +} -- 2.30.2