[tail-merge] Fix side-effect test in stmt_local_def
authorTom de Vries <tdevries@suse.de>
Thu, 21 Jun 2018 12:44:38 +0000 (12:44 +0000)
committerTom de Vries <vries@gcc.gnu.org>
Thu, 21 Jun 2018 12:44:38 +0000 (12:44 +0000)
2018-06-21  Tom de Vries  <tdevries@suse.de>

PR tree-optimization/85859
* tree-ssa-tail-merge.c (stmt_local_def): Copy gimple_is_call
test with comment from bb_no_side_effects_p.

* gcc.dg/pr85859.c: New test.

From-SVN: r261844

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr85859.c [new file with mode: 0644]
gcc/tree-ssa-tail-merge.c

index 09af13477587ac14361f995b6083fc54542b813d..266ab55206e5f50a455f3f3c3923d35fb7425463 100644 (file)
@@ -1,3 +1,9 @@
+2018-06-21  Tom de Vries  <tdevries@suse.de>
+
+       PR tree-optimization/85859
+       * tree-ssa-tail-merge.c (stmt_local_def): Copy gimple_is_call
+       test with comment from bb_no_side_effects_p.
+
 2018-06-21  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/86232
index 3d53dd41937cbd52b012802200ff1cde296f0bb2..93ba5e10f5cb6884ae4ecd8a2c80a2fed748c692 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-21  Tom de Vries  <tdevries@suse.de>
+
+       PR tree-optimization/85859
+       * gcc.dg/pr85859.c: New test.
+
 2018-06-21  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/86232
diff --git a/gcc/testsuite/gcc.dg/pr85859.c b/gcc/testsuite/gcc.dg/pr85859.c
new file mode 100644 (file)
index 0000000..96eb967
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-options "-ftree-tail-merge -Wno-div-by-zero -O2 -fno-dce -fno-isolate-erroneous-paths-dereference -fno-tree-dce -fno-tree-vrp" } */
+
+int b, c, d, e;
+
+__attribute__ ((noinline, noclone))
+int foo (short f)
+{
+  f %= 0;
+  return f;
+}
+
+int
+main (void)
+{
+  b = (unsigned char) __builtin_parity (d);
+  e ? foo (0) : (long) &c;
+  return 0;
+}
index f482ce197cd8e0b1ad9b1bd995c2d1d33ff21256..15838816d8674429f24bf23a785f6c89e7be28f8 100644 (file)
@@ -301,7 +301,15 @@ stmt_local_def (gimple *stmt)
   if (gimple_vdef (stmt) != NULL_TREE
       || gimple_has_side_effects (stmt)
       || gimple_could_trap_p_1 (stmt, false, false)
-      || gimple_vuse (stmt) != NULL_TREE)
+      || gimple_vuse (stmt) != NULL_TREE
+      /* Copied from tree-ssa-ifcombine.c:bb_no_side_effects_p():
+        const calls don't match any of the above, yet they could
+        still have some side-effects - they could contain
+        gimple_could_trap_p statements, like floating point
+        exceptions or integer division by zero.  See PR70586.
+        FIXME: perhaps gimple_has_side_effects or gimple_could_trap_p
+        should handle this.  */
+      || is_gimple_call (stmt))
     return false;
 
   def_p = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_DEF);