From 494e75321f6ce62918be661ef6b38c5888f0acaf Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Thu, 21 Jun 2018 12:44:38 +0000 Subject: [PATCH] [tail-merge] Fix side-effect test in stmt_local_def 2018-06-21 Tom de Vries 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 | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr85859.c | 19 +++++++++++++++++++ gcc/tree-ssa-tail-merge.c | 10 +++++++++- 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr85859.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 09af1347758..266ab55206e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-06-21 Tom de Vries + + 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 PR tree-optimization/86232 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3d53dd41937..93ba5e10f5c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-06-21 Tom de Vries + + PR tree-optimization/85859 + * gcc.dg/pr85859.c: New test. + 2018-06-21 Richard Biener PR tree-optimization/86232 diff --git a/gcc/testsuite/gcc.dg/pr85859.c b/gcc/testsuite/gcc.dg/pr85859.c new file mode 100644 index 00000000000..96eb9671137 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr85859.c @@ -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; +} diff --git a/gcc/tree-ssa-tail-merge.c b/gcc/tree-ssa-tail-merge.c index f482ce197cd..15838816d86 100644 --- a/gcc/tree-ssa-tail-merge.c +++ b/gcc/tree-ssa-tail-merge.c @@ -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); -- 2.30.2