From a5a9400a846244d040caa6d1531434eee8fc8ec7 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 24 Mar 2020 09:34:58 +0100 Subject: if-conv: Fix -fcompare-debug bugs in ifcvt_local_dce [PR94283] The following testcase shows -fcompare-debug bugs in ifcvt_local_dce, where the decisions what statements are needed is based also on debug stmt operands, which is wrong. So, this patch makes sure to never add debug stmt to the worklist, or never add an assign to worklist just because it is used in a debug stmt in another bb. 2020-03-24 Jakub Jelinek PR debug/94283 * tree-if-conv.c (ifcvt_local_dce): For gimple debug stmts, just set GF_PLF_2, but don't add them to worklist. Don't add an assigment to worklist or set GF_PLF_2 just because it is used in a debug stmt in another bb. Formatting improvements. * gcc.target/i386/pr94283.c: New test. --- gcc/tree-if-conv.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'gcc/tree-if-conv.c') diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c index 8d24c18..dd11d80 100644 --- a/gcc/tree-if-conv.c +++ b/gcc/tree-if-conv.c @@ -2917,9 +2917,12 @@ ifcvt_local_dce (class loop *loop) for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { stmt = gsi_stmt (gsi); - if (gimple_store_p (stmt) - || gimple_assign_load_p (stmt) - || is_gimple_debug (stmt)) + if (is_gimple_debug (stmt)) + { + gimple_set_plf (stmt, GF_PLF_2, true); + continue; + } + if (gimple_store_p (stmt) || gimple_assign_load_p (stmt)) { gimple_set_plf (stmt, GF_PLF_2, true); worklist.safe_push (stmt); @@ -2940,7 +2943,7 @@ ifcvt_local_dce (class loop *loop) FOR_EACH_IMM_USE_FAST (use_p, imm_iter, lhs) { stmt1 = USE_STMT (use_p); - if (gimple_bb (stmt1) != bb) + if (!is_gimple_debug (stmt1) && gimple_bb (stmt1) != bb) { gimple_set_plf (stmt, GF_PLF_2, true); worklist.safe_push (stmt); @@ -2963,8 +2966,7 @@ ifcvt_local_dce (class loop *loop) if (TREE_CODE (use) != SSA_NAME) continue; stmt1 = SSA_NAME_DEF_STMT (use); - if (gimple_bb (stmt1) != bb - || gimple_plf (stmt1, GF_PLF_2)) + if (gimple_bb (stmt1) != bb || gimple_plf (stmt1, GF_PLF_2)) continue; gimple_set_plf (stmt1, GF_PLF_2, true); worklist.safe_push (stmt1); -- cgit v1.1 From c2133167ad58d15c2c2df0cb4fa3a3757603144e Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 25 Mar 2020 08:08:04 +0100 Subject: if-conv: Delete dead stmts backwards in ifcvt_local_dce [PR94283] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit > > This patch caused: > > > > gcc /home/marxin/Programming/gcc/gcc/testsuite/gcc.c-torture/compile/990625-2.c -O3 -g -fno-tree-dce -c > > during GIMPLE pass: ifcvt > > /home/marxin/Programming/gcc/gcc/testsuite/gcc.c-torture/compile/990625-2.c: In function ‘broken030599’: > > /home/marxin/Programming/gcc/gcc/testsuite/gcc.c-torture/compile/990625-2.c:2:1: internal compiler error: Segmentation fault > > Likely > > /* Delete dead statements. */ > gsi = gsi_start_bb (bb); > while (!gsi_end_p (gsi)) > { > > needs to instead work back-to-front for debug stmt adjustment to work Indeed, that seems to work. 2020-03-25 Richard Biener Jakub Jelinek PR debug/94283 * tree-if-conv.c (ifcvt_local_dce): Delete dead statements backwards. * gcc.dg/pr94283.c: New test. Co-authored-by: Richard Biener --- gcc/tree-if-conv.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'gcc/tree-if-conv.c') diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c index dd11d80..fc894eb 100644 --- a/gcc/tree-if-conv.c +++ b/gcc/tree-if-conv.c @@ -2973,9 +2973,11 @@ ifcvt_local_dce (class loop *loop) } } /* Delete dead statements. */ - gsi = gsi_start_bb (bb); + gsi = gsi_last_bb (bb); while (!gsi_end_p (gsi)) { + gimple_stmt_iterator gsiprev = gsi; + gsi_prev (&gsiprev); stmt = gsi_stmt (gsi); if (gimple_store_p (stmt)) { @@ -2986,14 +2988,13 @@ ifcvt_local_dce (class loop *loop) if (dse_classify_store (&write, stmt, false, NULL, NULL, latch_vdef) == DSE_STORE_DEAD) delete_dead_or_redundant_assignment (&gsi, "dead"); - else - gsi_next (&gsi); + gsi = gsiprev; continue; } if (gimple_plf (stmt, GF_PLF_2)) { - gsi_next (&gsi); + gsi = gsiprev; continue; } if (dump_file && (dump_flags & TDF_DETAILS)) @@ -3003,6 +3004,7 @@ ifcvt_local_dce (class loop *loop) } gsi_remove (&gsi, true); release_defs (stmt); + gsi = gsiprev; } } -- cgit v1.1