]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
if-conv: Fix -fcompare-debug bugs in ifcvt_local_dce [PR94283]
authorJakub Jelinek <jakub@redhat.com>
Tue, 7 Apr 2020 18:57:37 +0000 (20:57 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 7 Apr 2020 18:57:37 +0000 (20:57 +0200)
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  <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/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/pr94283.c [new file with mode: 0644]
gcc/tree-if-conv.c

index 356e7c14e3b2122999b71f280f6977e1787075ba..95b7cc8f7ca291a35ef6ef4c048ca5ac42e4548f 100644 (file)
@@ -3,14 +3,18 @@
        Backported from mainline
        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.
+
        PR debug/94277
        * cgraphunit.c (check_global_declaration): For DECL_EXTERNAL and
        non-TREE_PUBLIC non-DECL_ARTIFICIAL FUNCTION_DECLs, set TREE_PUBLIC
        regardless of whether TREE_NO_WARNING is set on it or whether
        warn_unused_function is true or not.
 
-2020-04-07  Jakub Jelinek  <jakub@redhat.com>
-
        2020-03-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/94211
index a43da5200a28840e0b6f9f9b3ebb7fd28b7b216a..30ce191dfef8c04ee6879c592ae8aed83a6f2dff 100644 (file)
@@ -3,6 +3,9 @@
        Backported from mainline
        2020-03-24  Jakub Jelinek  <jakub@redhat.com>
 
+       PR debug/94283
+       * gcc.target/i386/pr94283.c: New test.
+
        PR debug/94277
        * gcc.dg/pr94277.c: New test.
 
diff --git a/gcc/testsuite/gcc.target/i386/pr94283.c b/gcc/testsuite/gcc.target/i386/pr94283.c
new file mode 100644 (file)
index 0000000..4982f7d
--- /dev/null
@@ -0,0 +1,5 @@
+/* PR debug/94283 */
+/* { dg-do compile } */
+/* { dg-options "-O3 -fcompare-debug -mavx2" } */
+
+#include "../../gcc.dg/fold-bopcond-1.c"
index 2780a4b243fcd839da76f60d1b70faaa2c1ad771..8a6e2415d7c9a4d2d11c0fb71d02cb5e5e1ed0e5 100644 (file)
@@ -2913,9 +2913,12 @@ ifcvt_local_dce (basic_block bb)
   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);
@@ -2936,7 +2939,7 @@ ifcvt_local_dce (basic_block bb)
          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);
@@ -2959,8 +2962,7 @@ ifcvt_local_dce (basic_block bb)
          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);