re PR tree-optimization/86945 (BUG with optimisation of select case statement in...
authorRichard Biener <rguenther@suse.de>
Wed, 22 Aug 2018 08:07:36 +0000 (08:07 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 22 Aug 2018 08:07:36 +0000 (08:07 +0000)
2018-08-22  Richard Biener  <rguenther@suse.de>

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
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr86945.c [new file with mode: 0644]
gcc/tree-cfg.c

index 04542dc..3a67b23 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-22  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/86945
+       * tree-cfg.c (generate_range_test): Use unsigned arithmetic.
+
 2018-08-22  Alexandre Oliva <oliva@adacore.com>
 
        * config/rs6000/rs6000.c (SMALL_DATA_RELOC, SMALL_DATA_REG): Add
index f0a5ff5..4e38d71 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-22  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/86945
+       * tree-cfg.c (generate_range_test): Use unsigned arithmetic.
+
 2018-08-21  Janne Blomqvist  <jb@gcc.gnu.org>
 
        * 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 (file)
index 0000000..4b722f5
--- /dev/null
@@ -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;
+}
index 14d66b7..463dd8a 100644 (file)
@@ -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.  */