gimple: Remove special handling of COND_EXPR for COMPARISON_CLASS_P [PR116949, PR114785]
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_gcc_check--master-arm |
success
|
Test passed
|
Commit Message
After r13-707-g68e0063397ba82, COND_EXPR for gimple assign no longer could contain a comparison.
The vectorizer was builting gimple assigns with comparison until r15-4695-gd17e672ce82e69
(which added an assert to make sure it no longer builds it).
So let's remove the special handling COND_EXPR in a few places and add an assert to
gimple_build_assign_1 to make sure we don't build a gimple assign any more with a comparison.
Bootstrapped and tested on x86_64-linux-gnu.
gcc/ChangeLog:
PR middle-end/114785
PR middle-end/116949
* gimple-match-exports.cc (maybe_push_res_to_seq): Remove special
handling of COMPARISON_CLASS_P in COND_EXPR/VEC_COND_EXPR.
(gimple_extract): Likewise.
* gimple-walk.cc (walk_stmt_load_store_addr_ops): Likewise.
* gimple.cc (gimple_build_assign_1):
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
---
gcc/gimple-match-exports.cc | 12 +-----------
gcc/gimple-walk.cc | 11 -----------
gcc/gimple.cc | 3 +++
3 files changed, 4 insertions(+), 22 deletions(-)
Comments
On Wed, Oct 30, 2024 at 1:56 AM Andrew Pinski <quic_apinski@quicinc.com> wrote:
>
> After r13-707-g68e0063397ba82, COND_EXPR for gimple assign no longer could contain a comparison.
> The vectorizer was builting gimple assigns with comparison until r15-4695-gd17e672ce82e69
> (which added an assert to make sure it no longer builds it).
>
> So let's remove the special handling COND_EXPR in a few places and add an assert to
> gimple_build_assign_1 to make sure we don't build a gimple assign any more with a comparison.
>
> Bootstrapped and tested on x86_64-linux-gnu.
OK.
The biggest offender still present is phiopt building a GENERIC
comparison for the
piecewise COND_EXPR simplification in gimple_simplify_phiopt (so
genmatch needs to
create both GIMPLE and GENERIC match variants for COND_EXPR conditions).
maybe_fold_comparisons_from_match_pd uses on-stack temporary GIMPLE for
a similar (more complex) case.
Richard.
> gcc/ChangeLog:
>
> PR middle-end/114785
> PR middle-end/116949
> * gimple-match-exports.cc (maybe_push_res_to_seq): Remove special
> handling of COMPARISON_CLASS_P in COND_EXPR/VEC_COND_EXPR.
> (gimple_extract): Likewise.
> * gimple-walk.cc (walk_stmt_load_store_addr_ops): Likewise.
> * gimple.cc (gimple_build_assign_1):
>
> Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
> ---
> gcc/gimple-match-exports.cc | 12 +-----------
> gcc/gimple-walk.cc | 11 -----------
> gcc/gimple.cc | 3 +++
> 3 files changed, 4 insertions(+), 22 deletions(-)
>
> diff --git a/gcc/gimple-match-exports.cc b/gcc/gimple-match-exports.cc
> index 77d225825cf..bc8038c19f0 100644
> --- a/gcc/gimple-match-exports.cc
> +++ b/gcc/gimple-match-exports.cc
> @@ -489,12 +489,6 @@ maybe_push_res_to_seq (gimple_match_op *res_op, gimple_seq *seq, tree res)
> && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[i]))
> return NULL_TREE;
>
> - if (num_ops > 0 && COMPARISON_CLASS_P (ops[0]))
> - for (unsigned int i = 0; i < 2; ++i)
> - if (TREE_CODE (TREE_OPERAND (ops[0], i)) == SSA_NAME
> - && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0], i)))
> - return NULL_TREE;
> -
> if (res_op->code.is_tree_code ())
> {
> auto code = tree_code (res_op->code);
> @@ -786,11 +780,7 @@ gimple_extract (gimple *stmt, gimple_match_op *res_op,
> }
> case GIMPLE_TERNARY_RHS:
> {
> - tree rhs1 = gimple_assign_rhs1 (stmt);
> - if (code == COND_EXPR && COMPARISON_CLASS_P (rhs1))
> - rhs1 = valueize_condition (rhs1);
> - else
> - rhs1 = valueize_op (rhs1);
> + tree rhs1 = valueize_op (gimple_assign_rhs1 (stmt));
> tree rhs2 = valueize_op (gimple_assign_rhs2 (stmt));
> tree rhs3 = valueize_op (gimple_assign_rhs3 (stmt));
> res_op->set_op (code, type, rhs1, rhs2, rhs3);
> diff --git a/gcc/gimple-walk.cc b/gcc/gimple-walk.cc
> index 9f768ca20fd..00520319aa9 100644
> --- a/gcc/gimple-walk.cc
> +++ b/gcc/gimple-walk.cc
> @@ -835,17 +835,6 @@ walk_stmt_load_store_addr_ops (gimple *stmt, void *data,
> ;
> else if (TREE_CODE (op) == ADDR_EXPR)
> ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
> - /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
> - tree with two operands. */
> - else if (i == 1 && COMPARISON_CLASS_P (op))
> - {
> - if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
> - ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
> - 0), op, data);
> - if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
> - ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
> - 0), op, data);
> - }
> }
> }
> else if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
> diff --git a/gcc/gimple.cc b/gcc/gimple.cc
> index eeb1badff5f..f7b313be40e 100644
> --- a/gcc/gimple.cc
> +++ b/gcc/gimple.cc
> @@ -475,6 +475,9 @@ gimple_build_assign_1 (tree lhs, enum tree_code subcode, tree op1,
> gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops
> PASS_MEM_STAT));
> gimple_assign_set_lhs (p, lhs);
> + /* For COND_EXPR, op1 should not be a comparison. */
> + if (op1 && subcode == COND_EXPR)
> + gcc_assert (!COMPARISON_CLASS_P (op1));
> gimple_assign_set_rhs1 (p, op1);
> if (op2)
> {
> --
> 2.43.0
>
On Wed, Oct 30, 2024 at 2:12 AM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Wed, Oct 30, 2024 at 1:56 AM Andrew Pinski <quic_apinski@quicinc.com> wrote:
> >
> > After r13-707-g68e0063397ba82, COND_EXPR for gimple assign no longer could contain a comparison.
> > The vectorizer was builting gimple assigns with comparison until r15-4695-gd17e672ce82e69
> > (which added an assert to make sure it no longer builds it).
> >
> > So let's remove the special handling COND_EXPR in a few places and add an assert to
> > gimple_build_assign_1 to make sure we don't build a gimple assign any more with a comparison.
> >
> > Bootstrapped and tested on x86_64-linux-gnu.
>
> OK.
>
> The biggest offender still present is phiopt building a GENERIC
> comparison for the
> piecewise COND_EXPR simplification in gimple_simplify_phiopt (so
> genmatch needs to
> create both GIMPLE and GENERIC match variants for COND_EXPR conditions).
> maybe_fold_comparisons_from_match_pd uses on-stack temporary GIMPLE for
> a similar (more complex) case.
Let me look into doing that; though I might not get to it until next
year for GCC 16. I filed
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117385 to make sure I
don't lose track of implementing it.
Thanks,
Andrew Pinski
>
> Richard.
>
> > gcc/ChangeLog:
> >
> > PR middle-end/114785
> > PR middle-end/116949
> > * gimple-match-exports.cc (maybe_push_res_to_seq): Remove special
> > handling of COMPARISON_CLASS_P in COND_EXPR/VEC_COND_EXPR.
> > (gimple_extract): Likewise.
> > * gimple-walk.cc (walk_stmt_load_store_addr_ops): Likewise.
> > * gimple.cc (gimple_build_assign_1):
> >
> > Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
> > ---
> > gcc/gimple-match-exports.cc | 12 +-----------
> > gcc/gimple-walk.cc | 11 -----------
> > gcc/gimple.cc | 3 +++
> > 3 files changed, 4 insertions(+), 22 deletions(-)
> >
> > diff --git a/gcc/gimple-match-exports.cc b/gcc/gimple-match-exports.cc
> > index 77d225825cf..bc8038c19f0 100644
> > --- a/gcc/gimple-match-exports.cc
> > +++ b/gcc/gimple-match-exports.cc
> > @@ -489,12 +489,6 @@ maybe_push_res_to_seq (gimple_match_op *res_op, gimple_seq *seq, tree res)
> > && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[i]))
> > return NULL_TREE;
> >
> > - if (num_ops > 0 && COMPARISON_CLASS_P (ops[0]))
> > - for (unsigned int i = 0; i < 2; ++i)
> > - if (TREE_CODE (TREE_OPERAND (ops[0], i)) == SSA_NAME
> > - && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0], i)))
> > - return NULL_TREE;
> > -
> > if (res_op->code.is_tree_code ())
> > {
> > auto code = tree_code (res_op->code);
> > @@ -786,11 +780,7 @@ gimple_extract (gimple *stmt, gimple_match_op *res_op,
> > }
> > case GIMPLE_TERNARY_RHS:
> > {
> > - tree rhs1 = gimple_assign_rhs1 (stmt);
> > - if (code == COND_EXPR && COMPARISON_CLASS_P (rhs1))
> > - rhs1 = valueize_condition (rhs1);
> > - else
> > - rhs1 = valueize_op (rhs1);
> > + tree rhs1 = valueize_op (gimple_assign_rhs1 (stmt));
> > tree rhs2 = valueize_op (gimple_assign_rhs2 (stmt));
> > tree rhs3 = valueize_op (gimple_assign_rhs3 (stmt));
> > res_op->set_op (code, type, rhs1, rhs2, rhs3);
> > diff --git a/gcc/gimple-walk.cc b/gcc/gimple-walk.cc
> > index 9f768ca20fd..00520319aa9 100644
> > --- a/gcc/gimple-walk.cc
> > +++ b/gcc/gimple-walk.cc
> > @@ -835,17 +835,6 @@ walk_stmt_load_store_addr_ops (gimple *stmt, void *data,
> > ;
> > else if (TREE_CODE (op) == ADDR_EXPR)
> > ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
> > - /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
> > - tree with two operands. */
> > - else if (i == 1 && COMPARISON_CLASS_P (op))
> > - {
> > - if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
> > - ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
> > - 0), op, data);
> > - if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
> > - ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
> > - 0), op, data);
> > - }
> > }
> > }
> > else if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
> > diff --git a/gcc/gimple.cc b/gcc/gimple.cc
> > index eeb1badff5f..f7b313be40e 100644
> > --- a/gcc/gimple.cc
> > +++ b/gcc/gimple.cc
> > @@ -475,6 +475,9 @@ gimple_build_assign_1 (tree lhs, enum tree_code subcode, tree op1,
> > gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops
> > PASS_MEM_STAT));
> > gimple_assign_set_lhs (p, lhs);
> > + /* For COND_EXPR, op1 should not be a comparison. */
> > + if (op1 && subcode == COND_EXPR)
> > + gcc_assert (!COMPARISON_CLASS_P (op1));
> > gimple_assign_set_rhs1 (p, op1);
> > if (op2)
> > {
> > --
> > 2.43.0
> >
@@ -489,12 +489,6 @@ maybe_push_res_to_seq (gimple_match_op *res_op, gimple_seq *seq, tree res)
&& SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ops[i]))
return NULL_TREE;
- if (num_ops > 0 && COMPARISON_CLASS_P (ops[0]))
- for (unsigned int i = 0; i < 2; ++i)
- if (TREE_CODE (TREE_OPERAND (ops[0], i)) == SSA_NAME
- && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (TREE_OPERAND (ops[0], i)))
- return NULL_TREE;
-
if (res_op->code.is_tree_code ())
{
auto code = tree_code (res_op->code);
@@ -786,11 +780,7 @@ gimple_extract (gimple *stmt, gimple_match_op *res_op,
}
case GIMPLE_TERNARY_RHS:
{
- tree rhs1 = gimple_assign_rhs1 (stmt);
- if (code == COND_EXPR && COMPARISON_CLASS_P (rhs1))
- rhs1 = valueize_condition (rhs1);
- else
- rhs1 = valueize_op (rhs1);
+ tree rhs1 = valueize_op (gimple_assign_rhs1 (stmt));
tree rhs2 = valueize_op (gimple_assign_rhs2 (stmt));
tree rhs3 = valueize_op (gimple_assign_rhs3 (stmt));
res_op->set_op (code, type, rhs1, rhs2, rhs3);
@@ -835,17 +835,6 @@ walk_stmt_load_store_addr_ops (gimple *stmt, void *data,
;
else if (TREE_CODE (op) == ADDR_EXPR)
ret |= visit_addr (stmt, TREE_OPERAND (op, 0), op, data);
- /* COND_EXPR and VCOND_EXPR rhs1 argument is a comparison
- tree with two operands. */
- else if (i == 1 && COMPARISON_CLASS_P (op))
- {
- if (TREE_CODE (TREE_OPERAND (op, 0)) == ADDR_EXPR)
- ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 0),
- 0), op, data);
- if (TREE_CODE (TREE_OPERAND (op, 1)) == ADDR_EXPR)
- ret |= visit_addr (stmt, TREE_OPERAND (TREE_OPERAND (op, 1),
- 0), op, data);
- }
}
}
else if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
@@ -475,6 +475,9 @@ gimple_build_assign_1 (tree lhs, enum tree_code subcode, tree op1,
gimple_build_with_ops_stat (GIMPLE_ASSIGN, (unsigned)subcode, num_ops
PASS_MEM_STAT));
gimple_assign_set_lhs (p, lhs);
+ /* For COND_EXPR, op1 should not be a comparison. */
+ if (op1 && subcode == COND_EXPR)
+ gcc_assert (!COMPARISON_CLASS_P (op1));
gimple_assign_set_rhs1 (p, op1);
if (op2)
{