From c05f748218a0d556972212d6aecfce0eb4c8a31c Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 2 Nov 2023 10:39:03 +0100 Subject: tree-optimization/112320 - bougs debug IL after SCCP The following addresses wrong debug IL created by SCCP rewriting stmts to defined overflow. I addressed another inefficiency there but needed to adjust the API of rewrite_to_defined_overflow for this which is now taking a stmt iterator for in-place operation and a stmt for sequence producing because gsi_for_stmt doesn't work for stmts not in the IL. PR tree-optimization/112320 * gimple-fold.h (rewrite_to_defined_overflow): New overload for in-place operation. * gimple-fold.cc (rewrite_to_defined_overflow): Add stmt iterator argument to worker, define separate API for in-place and not in-place operation. * tree-if-conv.cc (predicate_statements): Simplify. * tree-scalar-evolution.cc (final_value_replacement_loop): Likewise. * tree-ssa-ifcombine.cc (pass_tree_ifcombine::execute): Adjust. * tree-ssa-reassoc.cc (update_range_test): Likewise. * gcc.dg/pr112320.c: New testcase. --- gcc/gimple-fold.cc | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'gcc/gimple-fold.cc') diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 853edd9..a5be2ee 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -8769,12 +8769,14 @@ arith_code_with_undefined_signed_overflow (tree_code code) its operand, carrying out the operation in the corresponding unsigned type and converting the result back to the original type. - If IN_PLACE is true, adjust the stmt in place and return NULL. + If IN_PLACE is true, *GSI points to STMT, adjust the stmt in place and + return NULL. Otherwise returns a sequence of statements that replace STMT and also contain a modified form of STMT itself. */ -gimple_seq -rewrite_to_defined_overflow (gimple *stmt, bool in_place /* = false */) +static gimple_seq +rewrite_to_defined_overflow (gimple_stmt_iterator *gsi, gimple *stmt, + bool in_place) { if (dump_file && (dump_flags & TDF_DETAILS)) { @@ -8801,9 +8803,8 @@ rewrite_to_defined_overflow (gimple *stmt, bool in_place /* = false */) gimple_set_modified (stmt, true); if (in_place) { - gimple_stmt_iterator gsi = gsi_for_stmt (stmt); if (stmts) - gsi_insert_seq_before (&gsi, stmts, GSI_SAME_STMT); + gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT); stmts = NULL; } else @@ -8811,8 +8812,7 @@ rewrite_to_defined_overflow (gimple *stmt, bool in_place /* = false */) gimple *cvt = gimple_build_assign (lhs, NOP_EXPR, gimple_assign_lhs (stmt)); if (in_place) { - gimple_stmt_iterator gsi = gsi_for_stmt (stmt); - gsi_insert_after (&gsi, cvt, GSI_SAME_STMT); + gsi_insert_after (gsi, cvt, GSI_SAME_STMT); update_stmt (stmt); } else @@ -8821,6 +8821,17 @@ rewrite_to_defined_overflow (gimple *stmt, bool in_place /* = false */) return stmts; } +void +rewrite_to_defined_overflow (gimple_stmt_iterator *gsi) +{ + rewrite_to_defined_overflow (gsi, gsi_stmt (*gsi), true); +} + +gimple_seq +rewrite_to_defined_overflow (gimple *stmt) +{ + return rewrite_to_defined_overflow (nullptr, stmt, false); +} /* The valueization hook we use for the gimple_build API simplification. This makes us match fold_buildN behavior by only combining with -- cgit v1.1