diff options
author | Richard Biener <rguenther@suse.de> | 2021-01-22 10:34:42 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2021-01-22 10:37:51 +0100 |
commit | fd61ca67f97acc5462d02676380af92329c37bb2 (patch) | |
tree | 8b2f0f563677b6bb8e2ec3bfd3c3a907308f8e69 /gcc | |
parent | 4e3beaca15cab2de88a68d76f0aabc68e68f678a (diff) | |
download | gcc-fd61ca67f97acc5462d02676380af92329c37bb2.zip gcc-fd61ca67f97acc5462d02676380af92329c37bb2.tar.gz gcc-fd61ca67f97acc5462d02676380af92329c37bb2.tar.bz2 |
tree-optimization/98786 - fix issue with phiopt and abnormals
This fixes factor_out_conditional_conversion to avoid creating overlapping
lifetimes for abnormals. It also makes sure we do deal with a conditional
conversion (at least for one PHI arg def) - for the testcase that wasn't the case.
2021-01-22 Richard Biener <rguenther@suse.de>
PR tree-optimization/98786
* tree-ssa-phiopt.c (factor_out_conditional_conversion): Avoid
adding new uses of abnormals. Verify we deal with a conditional
conversion.
* gcc.dg/torture/pr98786.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr98786.c | 23 | ||||
-rw-r--r-- | gcc/tree-ssa-phiopt.c | 15 |
2 files changed, 38 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr98786.c b/gcc/testsuite/gcc.dg/torture/pr98786.c new file mode 100644 index 0000000..ea36471 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr98786.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fno-tree-dce" } */ + +void +func_30 (void); + +int __attribute__ ((pure, returns_twice)) +func_38 (int g_15, int p_39) +{ + return !!g_15 ? p_39 : 0; +} + +void +func_26 (int func_26___trans_tmp_1) +{ + long int l_37 = 0; + int __trans_tmp_1; + + func_26___trans_tmp_1 = func_38 (func_26___trans_tmp_1, 1); + __trans_tmp_1 = func_38 (func_26___trans_tmp_1, l_37); + l_37 = 1; + func_30 (); +} diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index bbc78af..ddd9d53 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -474,6 +474,9 @@ factor_out_conditional_conversion (edge e0, edge e1, gphi *phi, if (!is_gimple_reg_type (TREE_TYPE (new_arg0))) return NULL; } + if (TREE_CODE (new_arg0) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_arg0)) + return NULL; if (TREE_CODE (arg1) == SSA_NAME) { @@ -484,13 +487,25 @@ factor_out_conditional_conversion (edge e0, edge e1, gphi *phi, || gimple_assign_rhs_code (arg1_def_stmt) != convert_code) return NULL; + /* Either arg1_def_stmt or arg0_def_stmt should be conditional. */ + if (dominated_by_p (CDI_DOMINATORS, gimple_bb (phi), gimple_bb (arg0_def_stmt)) + && dominated_by_p (CDI_DOMINATORS, + gimple_bb (phi), gimple_bb (arg1_def_stmt))) + return NULL; + /* Use the RHS as new_arg1. */ new_arg1 = gimple_assign_rhs1 (arg1_def_stmt); if (convert_code == VIEW_CONVERT_EXPR) new_arg1 = TREE_OPERAND (new_arg1, 0); + if (TREE_CODE (new_arg1) == SSA_NAME + && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (new_arg1)) + return NULL; } else { + /* arg0_def_stmt should be conditional. */ + if (dominated_by_p (CDI_DOMINATORS, gimple_bb (phi), gimple_bb (arg0_def_stmt))) + return NULL; /* If arg1 is an INTEGER_CST, fold it to new type. */ if (INTEGRAL_TYPE_P (TREE_TYPE (new_arg0)) && int_fits_type_p (arg1, TREE_TYPE (new_arg0))) |