From 833bbf60ce6414801d3a381a2a4b1f244bd0d969 Mon Sep 17 00:00:00 2001 From: Segher Boessenkool Date: Tue, 4 Apr 2017 02:10:02 +0200 Subject: [PATCH] simplify-rtx: Fix compare of comparisons (PR60818) The function simplify_binary_operation_1 has code that does /* Convert (compare (gt (flags) 0) (lt (flags) 0)) to (flags). */ but this transformation is only valid if "flags" has the same machine mode as the outer compare. This fixes it. PR rtl-optimization/60818 * simplify-rtx.c (simplify_binary_operation_1): Do not replace a compare of comparisons with the thing compared if this results in a different machine mode. gcc/testsuite/ PR rtl-optimization/60818 * gcc.c-torture/compile/pr60818.c: New testcase. From-SVN: r246666 --- gcc/ChangeLog | 7 +++++++ gcc/simplify-rtx.c | 6 +++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.c-torture/compile/pr60818.c | 5 +++++ 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr60818.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a92c3a5b5e0..4d113af985d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2017-04-04 Segher Boessenkool + + PR rtl-optimization/60818 + * simplify-rtx.c (simplify_binary_operation_1): Do not replace + a compare of comparisons with the thing compared if this results + in a different machine mode. + 2017-04-03 Jonathan Wakely * alias.c (base_alias_check): Fix typo in comment. diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 640ccb7cb95..cff7e4d3e3f 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -2306,10 +2306,10 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, return xop00; if (REG_P (xop00) && REG_P (xop10) - && GET_MODE (xop00) == GET_MODE (xop10) && REGNO (xop00) == REGNO (xop10) - && GET_MODE_CLASS (GET_MODE (xop00)) == MODE_CC - && GET_MODE_CLASS (GET_MODE (xop10)) == MODE_CC) + && GET_MODE (xop00) == mode + && GET_MODE (xop10) == mode + && GET_MODE_CLASS (mode) == MODE_CC) return xop00; } break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4a05eba88b9..9ac0c0b8dc9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-04-04 Segher Boessenkool + + PR rtl-optimization/60818 + * gcc.c-torture/compile/pr60818.c: New testcase. + 2017-04-03 Jonathan Wakely * g++.old-deja/g++.benjamin/scope02.C: Fix typo in comment. diff --git a/gcc/testsuite/gcc.c-torture/compile/pr60818.c b/gcc/testsuite/gcc.c-torture/compile/pr60818.c new file mode 100644 index 00000000000..b6171bbcdf0 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr60818.c @@ -0,0 +1,5 @@ +int +lx (int oi, int mb) +{ + return (oi < mb) < (mb < oi); +} -- 2.30.2