Message ID | 20200324081001.GM2156@tucnak |
---|---|
State | New |
Headers | show |
Series | if-conv: Fix -fcompare-debug bugs in ifcvt_local_dce [PR94283] | expand |
On Tue, 24 Mar 2020, Jakub Jelinek wrote: > Hi! > > 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. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. > 2020-03-24 Jakub Jelinek <jakub@redhat.com> > > 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.jj 2020-01-12 11:54:38.495381997 +0100 > +++ gcc/tree-if-conv.c 2020-03-23 17:13:13.823724294 +0100 > @@ -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); > --- gcc/testsuite/gcc.target/i386/pr94283.c.jj 2020-03-23 17:16:50.324494226 +0100 > +++ gcc/testsuite/gcc.target/i386/pr94283.c 2020-03-23 17:16:42.238614863 +0100 > @@ -0,0 +1,5 @@ > +/* PR debug/94283 */ > +/* { dg-do compile } */ > +/* { dg-options "-O3 -fcompare-debug -mavx2" } */ > + > +#include "../../gcc.dg/fold-bopcond-1.c" > > Jakub > >
Hi. 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 2 | broken030599(int *n) | ^~~~~~~~~~~~ 0xe32f1f crash_signal ../../gcc/toplev.c:328 0x7ffff7999f1f ??? /usr/src/debug/glibc-2.31-3.1.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0 0x104ffe5 verify_use ../../gcc/tree-ssa.c:884 0x1054607 verify_ssa(bool, bool) ../../gcc/tree-ssa.c:1161 0xd4fb05 execute_function_todo ../../gcc/passes.c:1992 0xd507ae execute_todo ../../gcc/passes.c:2039 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See <https://gcc.gnu.org/bugs/> for instructions. Martin
On Tue, 24 Mar 2020, Martin Liška wrote: > Hi. > > 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 > 2 | broken030599(int *n) > | ^~~~~~~~~~~~ > 0xe32f1f crash_signal > ../../gcc/toplev.c:328 > 0x7ffff7999f1f ??? > /usr/src/debug/glibc-2.31-3.1.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0 > 0x104ffe5 verify_use > ../../gcc/tree-ssa.c:884 > 0x1054607 verify_ssa(bool, bool) > ../../gcc/tree-ssa.c:1161 > 0xd4fb05 execute_function_todo > ../../gcc/passes.c:1992 > 0xd507ae execute_todo > ../../gcc/passes.c:2039 > Please submit a full bug report, > with preprocessed source if appropriate. > Please include the complete backtrace with any bug report. > See <https://gcc.gnu.org/bugs/> for instructions. 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
--- gcc/tree-if-conv.c.jj 2020-01-12 11:54:38.495381997 +0100 +++ gcc/tree-if-conv.c 2020-03-23 17:13:13.823724294 +0100 @@ -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); --- gcc/testsuite/gcc.target/i386/pr94283.c.jj 2020-03-23 17:16:50.324494226 +0100 +++ gcc/testsuite/gcc.target/i386/pr94283.c 2020-03-23 17:16:42.238614863 +0100 @@ -0,0 +1,5 @@ +/* PR debug/94283 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -fcompare-debug -mavx2" } */ + +#include "../../gcc.dg/fold-bopcond-1.c"