From 46d85442680fa0d518d59b35a794a85341a20dc3 Mon Sep 17 00:00:00 2001 From: ebotcazou Date: Mon, 28 Jul 2014 08:55:17 +0000 Subject: [PATCH] PR middle-end/61734 * fold-const.c (fold_comparison): Disable X - Y CMP 0 to X CMP Y for operators other than the equality operators. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@213118 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/fold-const.c | 6 +++++- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/Wstrict-overflow-25.c | 2 +- gcc/testsuite/gcc.dg/fold-abs-5.c | 11 +++++++++++ gcc/testsuite/gcc.dg/fold-compare-8.c | 2 +- 6 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/fold-abs-5.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fcb95b1a9cb..1db45878799 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-07-28 Eric Botcazou + + PR middle-end/61734 + * fold-const.c (fold_comparison): Disable X - Y CMP 0 to X CMP Y for + operators other than the equality operators. + 2014-07-28 Richard Biener PR middle-end/52478 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 0999625dc28..718066238ef 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9026,9 +9026,13 @@ fold_comparison (location_t loc, enum tree_code code, tree type, /* Transform comparisons of the form X - Y CMP 0 to X CMP Y. */ if (TREE_CODE (arg0) == MINUS_EXPR - && (equality_code || TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (arg0))) + && equality_code && integer_zerop (arg1)) { + /* ??? The transformation is valid for the other operators if overflow + is undefined for the type, but performing it here badly interacts + with the transformation in fold_cond_expr_with_comparison which + attempts to synthetize ABS_EXPR. */ if (!equality_code) fold_overflow_warning ("assuming signed overflow does not occur " "when changing X - Y cmp 0 to X cmp Y", diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 014896c627c..ac3bd472a8f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-07-28 Eric Botcazou + + * gcc.dg/fold-abs-5.c: New test. + * gcc.dg/Wstrict-overflow-25.c: XFAIL everywhere. + * gcc.dg/fold-compare-8.c: Likewise. + 2014-07-28 Richard Biener PR middle-end/52478 diff --git a/gcc/testsuite/gcc.dg/Wstrict-overflow-25.c b/gcc/testsuite/gcc.dg/Wstrict-overflow-25.c index 00916446371..774474d1123 100644 --- a/gcc/testsuite/gcc.dg/Wstrict-overflow-25.c +++ b/gcc/testsuite/gcc.dg/Wstrict-overflow-25.c @@ -7,5 +7,5 @@ int foo (int x, int y) { - return x - y < 0; /* { dg-warning "assuming signed overflow does not occur" "correct warning" } */ + return x - y < 0; /* { dg-warning "assuming signed overflow does not occur" "correct warning" { xfail *-*-* } } */ } diff --git a/gcc/testsuite/gcc.dg/fold-abs-5.c b/gcc/testsuite/gcc.dg/fold-abs-5.c new file mode 100644 index 00000000000..dba4e4bf89a --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-abs-5.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-original" } */ + +int test (int a, int b, int sum) +{ + sum += ((a - b) > 0 ? (a - b) : -(a - b)); + return sum; +} + +/* { dg-final { scan-tree-dump "ABS" "original" } } */ +/* { dg-final { cleanup-tree-dump "original" } } */ diff --git a/gcc/testsuite/gcc.dg/fold-compare-8.c b/gcc/testsuite/gcc.dg/fold-compare-8.c index b6e42fdef10..2fb5fe9d1d4 100644 --- a/gcc/testsuite/gcc.dg/fold-compare-8.c +++ b/gcc/testsuite/gcc.dg/fold-compare-8.c @@ -7,5 +7,5 @@ foo (int x, int y) return x - y < 0; } -/* { dg-final { scan-tree-dump "x < y" "original" } } */ +/* { dg-final { scan-tree-dump "x < y" "original" { xfail *-*-* } } } */ /* { dg-final { cleanup-tree-dump "original" } } */ -- 2.11.4.GIT