From 75473a91bc054c229cdc58fb06dc5a6311899f5c Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 3 Mar 2017 08:08:08 +0000 Subject: [PATCH] re PR middle-end/79818 (wrong code with -fwrapv and -Os/-O1/-O2/-O3) 2017-03-03 Richard Biener PR middle-end/79818 * match.pd ( X +- C1 CMP C2 -> X CMP C2 -+ C1): Add missing TYPE_OVERFLOW_UNDEFINED check. * gcc.dg/torture/pr79818.c: New testcase. From-SVN: r245860 --- gcc/ChangeLog | 6 ++++++ gcc/match.pd | 3 ++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr79818.c | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr79818.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c8b375ecf5c..73b2f215a79 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-03-03 Richard Biener + + PR middle-end/79818 + * match.pd ( X +- C1 CMP C2 -> X CMP C2 -+ C1): Add missing + TYPE_OVERFLOW_UNDEFINED check. + 2017-03-02 Bill Schmidt * config/rs6000/vector.md (vector_ne__p): Correct operand diff --git a/gcc/match.pd b/gcc/match.pd index 7b968009473..4e6f7199947 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3688,7 +3688,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && !TYPE_OVERFLOW_TRAPS (TREE_TYPE (@0)) && !TYPE_SATURATING (TREE_TYPE (@0))) (with { tree res = int_const_binop (rop, @2, @1); } - (if (TREE_OVERFLOW (res)) + (if (TREE_OVERFLOW (res) + && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))) { constant_boolean_node (cmp == NE_EXPR, type); } (if (single_use (@3)) (cmp @0 { res; })))))))) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b0034ed4fac..e5a08ac0290 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-03-03 Richard Biener + + PR middle-end/79818 + * gcc.dg/torture/pr79818.c: New testcase. + 2017-03-02 Jakub Jelinek PR c++/79782 diff --git a/gcc/testsuite/gcc.dg/torture/pr79818.c b/gcc/testsuite/gcc.dg/torture/pr79818.c new file mode 100644 index 00000000000..5c12089a7a6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr79818.c @@ -0,0 +1,19 @@ +/* { dg-do run } */ +/* { dg-additional-options "-fwrapv" } */ + +static void __attribute__((noinline,noclone)) +func(void) +{ + signed char c = 0; + + for(; c >= 0; c++); + + if(c != -128) + __builtin_abort(); +} + +int main(int argc, char* argv[]) +{ + func(); + return 0; +} -- 2.30.2