From 66c4f4d8c4399c499f1af5f550bf28878a8d69db Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Wed, 22 Aug 2018 08:07:36 +0000 Subject: [PATCH] re PR tree-optimization/86945 (BUG with optimisation of select case statement in gfortran) 2018-08-22 Richard Biener PR tree-optimization/86945 * tree-cfg.c (generate_range_test): Use unsigned arithmetic. * gcc.dg/torture/pr86945.c: New testcase. From-SVN: r263761 --- gcc/ChangeLog | 5 +++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr86945.c | 18 ++++++++++++++++++ gcc/tree-cfg.c | 18 +++++++----------- 4 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr86945.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 04542dc5ca8..3a67b236a37 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-08-22 Richard Biener + + PR tree-optimization/86945 + * tree-cfg.c (generate_range_test): Use unsigned arithmetic. + 2018-08-22 Alexandre Oliva * config/rs6000/rs6000.c (SMALL_DATA_RELOC, SMALL_DATA_REG): Add diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f0a5ff50877..4e38d714ef4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-08-22 Richard Biener + + PR tree-optimization/86945 + * tree-cfg.c (generate_range_test): Use unsigned arithmetic. + 2018-08-21 Janne Blomqvist * gfortran.dg/nan_1.f90: Remove tests that test MAX/MIN with NaNs. diff --git a/gcc/testsuite/gcc.dg/torture/pr86945.c b/gcc/testsuite/gcc.dg/torture/pr86945.c new file mode 100644 index 00000000000..4b722f5f685 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr86945.c @@ -0,0 +1,18 @@ +/* { dg-do run } */ + +void __attribute__((noinline,noipa)) +foo(int id) +{ + switch (id) + { + case (-__INT_MAX__ - 1)...-1: + __builtin_abort (); + default:; + } +} + +int main() +{ + foo(1); + return 0; +} diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 14d66b7a728..463dd8a3bf9 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -9131,20 +9131,16 @@ generate_range_test (basic_block bb, tree index, tree low, tree high, tree type = TREE_TYPE (index); tree utype = unsigned_type_for (type); - low = fold_convert (type, low); - high = fold_convert (type, high); + low = fold_convert (utype, low); + high = fold_convert (utype, high); - tree tmp = make_ssa_name (type); - gassign *sub1 - = gimple_build_assign (tmp, MINUS_EXPR, index, low); + gimple_seq seq = NULL; + index = gimple_convert (&seq, utype, index); + *lhs = gimple_build (&seq, MINUS_EXPR, utype, index, low); + *rhs = const_binop (MINUS_EXPR, utype, high, low); - *lhs = make_ssa_name (utype); - gassign *a = gimple_build_assign (*lhs, NOP_EXPR, tmp); - - *rhs = fold_build2 (MINUS_EXPR, utype, high, low); gimple_stmt_iterator gsi = gsi_last_bb (bb); - gsi_insert_before (&gsi, sub1, GSI_SAME_STMT); - gsi_insert_before (&gsi, a, GSI_SAME_STMT); + gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT); } /* Emit return warnings. */ -- 2.30.2