From 56a6d474ab255eddf334bd77df014673d4035336 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 28 Jun 2017 14:24:00 +0000 Subject: [PATCH] re PR tree-optimization/81227 (ICE in get_single_symbol, at tree-vrp.c:799) 2017-06-28 Richard Biener PR middle-end/81227 * fold-const.c (negate_expr_p): Use TYPE_UNSIGNED, not TYPE_OVERFLOW_WRAPS. * match.pd (negate_expr_p): Likewise. * tree-ssa-reassoc.c (optimize_range_tests_diff): Use fold_build2, not fold_binary. * gcc.dg/pr81227.c: New testcase. From-SVN: r249742 --- gcc/ChangeLog | 9 +++++++++ gcc/fold-const.c | 2 +- gcc/match.pd | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr81227.c | 22 ++++++++++++++++++++++ gcc/tree-ssa-reassoc.c | 2 +- 6 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr81227.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 293671b8ff2..34de7cf2bce 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2017-06-28 Richard Biener + + PR middle-end/81227 + * fold-const.c (negate_expr_p): Use TYPE_UNSIGNED, not + TYPE_OVERFLOW_WRAPS. + * match.pd (negate_expr_p): Likewise. + * tree-ssa-reassoc.c (optimize_range_tests_diff): Use + fold_build2, not fold_binary. + 2017-06-28 Wilco Dijkstra * config/aarch64/aarch64 (aarch64_expand_mov_immediate): diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 379a30ea285..1bcbbb58154 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -383,7 +383,7 @@ negate_expr_p (tree t) switch (TREE_CODE (t)) { case INTEGER_CST: - if (INTEGRAL_TYPE_P (type) && TYPE_OVERFLOW_WRAPS (type)) + if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)) return true; /* Check that -CST will not overflow type. */ diff --git a/gcc/match.pd b/gcc/match.pd index ede5504bdf1..4c64b21b463 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -914,7 +914,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (match negate_expr_p INTEGER_CST (if ((INTEGRAL_TYPE_P (type) - && TYPE_OVERFLOW_WRAPS (type)) + && TYPE_UNSIGNED (type)) || (!TYPE_OVERFLOW_SANITIZED (type) && may_negate_without_overflow_p (t))))) (match negate_expr_p diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d50a9d8c646..a96d5abb65c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-06-28 Richard Biener + + PR middle-end/81227 + * gcc.dg/pr81227.c: New testcase. + 2017-06-28 Michael Meissner PR target/81193 diff --git a/gcc/testsuite/gcc.dg/pr81227.c b/gcc/testsuite/gcc.dg/pr81227.c new file mode 100644 index 00000000000..bdaa8cbab2b --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr81227.c @@ -0,0 +1,22 @@ +/* Copy of gcc.c-torture/compile/pr80443.c */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fwrapv" } */ + +struct S { int a : 1; } b, c; +signed char d, e, f; + +void +foo () +{ + while (f) + { + signed char g = b.a; + if (g) + b.a = ~(1 + (d || c.a)); + if (b.a < g && b.a) + g = 0; + if (b.a > c.a) + b.a = g; + c.a = e; + } +} diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c index 35eb72ce310..982ab790cb3 100644 --- a/gcc/tree-ssa-reassoc.c +++ b/gcc/tree-ssa-reassoc.c @@ -2561,7 +2561,7 @@ optimize_range_tests_diff (enum tree_code opcode, tree type, tem2 = fold_convert (type, tem2); lowi = fold_convert (type, lowi); mask = fold_build1 (BIT_NOT_EXPR, type, tem1); - tem1 = fold_binary (MINUS_EXPR, type, + tem1 = fold_build2 (MINUS_EXPR, type, fold_convert (type, rangei->exp), lowi); tem1 = fold_build2 (BIT_AND_EXPR, type, tem1, mask); lowj = build_int_cst (type, 0); -- 2.30.2