From 28fd0ba2d17a09ddf5106f1e60c475a93fba3090 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 9 Sep 2013 19:09:59 +0200 Subject: [PATCH] re PR tree-optimization/58364 (likely wrong code bug) PR tree-optimization/58364 * tree-ssa-reassoc.c (init_range_entry): For BIT_NOT_EXPR on BOOLEAN_TYPE, only invert in_p and continue with arg0 if the current range can't be an unconditional true or false. * gcc.c-torture/execute/pr58364.c: New test. From-SVN: r202409 --- gcc/ChangeLog | 7 +++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.c-torture/execute/pr58364.c | 17 +++++++++++++++++ gcc/tree-ssa-reassoc.c | 9 ++++++++- 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr58364.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3edd10076b7..dd9a3e0cbc1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2013-09-09 Jakub Jelinek + + PR tree-optimization/58364 + * tree-ssa-reassoc.c (init_range_entry): For BIT_NOT_EXPR on + BOOLEAN_TYPE, only invert in_p and continue with arg0 if + the current range can't be an unconditional true or false. + 2013-09-09 James Greenhalgh * config/aarch64/arm_neon.h (vrsqrte_f64): Fix parameter type. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 177ed3fdfad..befd28d2690 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2013-09-09 Jakub Jelinek + + PR tree-optimization/58364 + * gcc.c-torture/execute/pr58364.c: New test. + 2013-09-09 Paolo Carlini PR c++/43452 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr58364.c b/gcc/testsuite/gcc.c-torture/execute/pr58364.c new file mode 100644 index 00000000000..59ad7b47a16 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr58364.c @@ -0,0 +1,17 @@ +/* PR tree-optimization/58364 */ + +int a = 1, b, c; + +int +foo (int x) +{ + return x < 0 ? 1 : x; +} + +int +main () +{ + if (foo (a > c == (b = 0))) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 03c6c5dbfa4..b4a3b0a2df9 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -1801,7 +1801,14 @@ init_range_entry (struct range_entry *r, tree exp, gimple stmt) switch (code) { case BIT_NOT_EXPR: - if (TREE_CODE (TREE_TYPE (exp)) == BOOLEAN_TYPE) + if (TREE_CODE (TREE_TYPE (exp)) == BOOLEAN_TYPE + /* Ensure the range is either +[-,0], +[0,0], + -[-,0], -[0,0] or +[1,-], +[1,1], -[1,-] or + -[1,1]. If it is e.g. +[-,-] or -[-,-] + or similar expression of unconditional true or + false, it should not be negated. */ + && ((high && integer_zerop (high)) + || (low && integer_onep (low)))) { in_p = !in_p; exp = arg0; -- 2.30.2