The following avoids merging a vector compare with EH with a VEC_COND_EXPR. We should be able to do fallback expansion and if we really are for the optimization we need quite some shuffling to arrange for the proper EH redirection in all cases, IMHO not worth it.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk sofar. 2022-02-09 Richard Biener <rguent...@suse.de> PR middle-end/104450 * gimple-isel.cc: Pass cfun around. (+gimple_expand_vec_cond_expr): Do not combine a throwing comparison with the select. * g++.dg/torture/pr104450.C: New testcase. --- gcc/gimple-isel.cc | 24 ++++++++++++++---------- gcc/testsuite/g++.dg/torture/pr104450.C | 16 ++++++++++++++++ 2 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr104450.C diff --git a/gcc/gimple-isel.cc b/gcc/gimple-isel.cc index 3d4f02c7fec..1d93766b704 100644 --- a/gcc/gimple-isel.cc +++ b/gcc/gimple-isel.cc @@ -50,7 +50,7 @@ along with GCC; see the file COPYING3. If not see u = _8; */ static gimple * -gimple_expand_vec_set_expr (gimple_stmt_iterator *gsi) +gimple_expand_vec_set_expr (struct function *fun, gimple_stmt_iterator *gsi) { enum tree_code code; gcall *new_stmt = NULL; @@ -76,7 +76,7 @@ gimple_expand_vec_set_expr (gimple_stmt_iterator *gsi) tree pos = TREE_OPERAND (lhs, 1); tree view_op0 = TREE_OPERAND (op0, 0); machine_mode outermode = TYPE_MODE (TREE_TYPE (view_op0)); - if (auto_var_in_fn_p (view_op0, cfun->decl) + if (auto_var_in_fn_p (view_op0, fun->decl) && !TREE_ADDRESSABLE (view_op0) && can_vec_set_var_idx_p (outermode)) { location_t loc = gimple_location (stmt); @@ -110,7 +110,7 @@ gimple_expand_vec_set_expr (gimple_stmt_iterator *gsi) function based on type of selected expansion. */ static gimple * -gimple_expand_vec_cond_expr (gimple_stmt_iterator *gsi, +gimple_expand_vec_cond_expr (struct function *fun, gimple_stmt_iterator *gsi, hash_map<tree, unsigned int> *vec_cond_ssa_name_uses) { tree lhs, op0a = NULL_TREE, op0b = NULL_TREE; @@ -178,7 +178,11 @@ gimple_expand_vec_cond_expr (gimple_stmt_iterator *gsi, } gassign *def_stmt = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (op0)); - if (def_stmt) + if (def_stmt + /* When the compare has EH we do not want to forward it when + it has multiple uses and in general because of the complication + with EH redirection. */ + && !stmt_can_throw_internal (fun, def_stmt)) { tcode = gimple_assign_rhs_code (def_stmt); op0a = gimple_assign_rhs1 (def_stmt); @@ -279,18 +283,18 @@ gimple_expand_vec_cond_expr (gimple_stmt_iterator *gsi, VEC_COND_EXPR assignments. */ static unsigned int -gimple_expand_vec_exprs (void) +gimple_expand_vec_exprs (struct function *fun) { gimple_stmt_iterator gsi; basic_block bb; hash_map<tree, unsigned int> vec_cond_ssa_name_uses; auto_bitmap dce_ssa_names; - FOR_EACH_BB_FN (bb, cfun) + FOR_EACH_BB_FN (bb, fun) { for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { - gimple *g = gimple_expand_vec_cond_expr (&gsi, + gimple *g = gimple_expand_vec_cond_expr (fun, &gsi, &vec_cond_ssa_name_uses); if (g != NULL) { @@ -299,7 +303,7 @@ gimple_expand_vec_exprs (void) gsi_replace (&gsi, g, false); } - gimple_expand_vec_set_expr (&gsi); + gimple_expand_vec_set_expr (fun, &gsi); if (gsi_end_p (gsi)) break; } @@ -342,9 +346,9 @@ public: return true; } - virtual unsigned int execute (function *) + virtual unsigned int execute (function *fun) { - return gimple_expand_vec_exprs (); + return gimple_expand_vec_exprs (fun); } }; // class pass_gimple_isel diff --git a/gcc/testsuite/g++.dg/torture/pr104450.C b/gcc/testsuite/g++.dg/torture/pr104450.C new file mode 100644 index 00000000000..402a4849e54 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr104450.C @@ -0,0 +1,16 @@ +// { dg-do compile } +// { dg-additional-options "-fnon-call-exceptions" } +// { dg-additional-options "-mavx512f" { target x86_64-*-* i?86-*-* } } + +#define vectsize 64 +typedef int __attribute__((__vector_size__ (vectsize))) V; +typedef float __attribute__((__vector_size__ (vectsize))) F; +F f; +V v; +struct g{~g();}; +void +foo (void) +{ + g t; + v += (V) (0 <= f); +} -- 2.34.1