ldist: Further fixes for -ftrapv [PR94114]
authorJakub Jelinek <jakub@redhat.com>
Wed, 11 Mar 2020 08:32:22 +0000 (09:32 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 11 Mar 2020 08:32:22 +0000 (09:32 +0100)
As the testcase shows, arithmetics that for -ftrapv would need multiple
basic blocks can show up not just in nb_bytes expressions where we
are calling rewrite_to_non_trapping_overflow for a while already,
but also in the pointer expression to the start of the region.
While the testcase covers just the first hunk and I've failed to create
a testcase for the latter, it is at least in theory possible too, so I've
adjusted that hunk too.

2020-03-11  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/94114
* tree-loop-distribution.c (generate_memset_builtin): Call
rewrite_to_non_trapping_overflow even on mem.
(generate_memcpy_builtin): Call rewrite_to_non_trapping_overflow even
on dest and src.

* gcc.dg/pr94114.c: New test.

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr94114.c [new file with mode: 0644]
gcc/tree-loop-distribution.c

index 887a55097dbf15f140e0706c50bcde2877be74ad..6630a20a6252fdc9633a6723ca36ed37f62b00c9 100644 (file)
@@ -1,3 +1,11 @@
+2020-03-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/94114
+       * tree-loop-distribution.c (generate_memset_builtin): Call
+       rewrite_to_non_trapping_overflow even on mem.
+       (generate_memcpy_builtin): Call rewrite_to_non_trapping_overflow even
+       on dest and src.
+
 2020-03-10  Jeff Law  <law@redhat.com>
 
        * config/bfin/bfin.md (movsi_insv): Add length attribute.
index d243255b07c2202aec7162d0d3f0b5a7f0f1cb06..954c4511816406c82cbcca80454d47fc139fb3ee 100644 (file)
@@ -1,3 +1,8 @@
+2020-03-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/94114
+       * gcc.dg/pr94114.c: New test.
+
 2020-03-10  Marek Polacek  <polacek@redhat.com>
 
        PR c++/94124 - wrong conversion error with non-viable overload.
diff --git a/gcc/testsuite/gcc.dg/pr94114.c b/gcc/testsuite/gcc.dg/pr94114.c
new file mode 100644 (file)
index 0000000..8d6d0eb
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR tree-optimization/94114 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-loop-distribute-patterns -ftrapv" } */
+
+void
+foo (int *x, int *y, int *z, long int w)
+{
+  while (y + w > z)
+    {
+      x[w] = 0;
+      --w;
+    }
+}
index a4f0b1effbe735370e7c69e9dd78c04770ef633a..35d3821bb0789e3b800c8c12a58d498b7b3d1de7 100644 (file)
@@ -1151,7 +1151,7 @@ generate_memset_builtin (class loop *loop, partition *partition)
   nb_bytes = rewrite_to_non_trapping_overflow (builtin->size);
   nb_bytes = force_gimple_operand_gsi (&gsi, nb_bytes, true, NULL_TREE,
                                       false, GSI_CONTINUE_LINKING);
-  mem = builtin->dst_base;
+  mem = rewrite_to_non_trapping_overflow (builtin->dst_base);
   mem = force_gimple_operand_gsi (&gsi, mem, true, NULL_TREE,
                                  false, GSI_CONTINUE_LINKING);
 
@@ -1205,8 +1205,8 @@ generate_memcpy_builtin (class loop *loop, partition *partition)
   nb_bytes = rewrite_to_non_trapping_overflow (builtin->size);
   nb_bytes = force_gimple_operand_gsi (&gsi, nb_bytes, true, NULL_TREE,
                                       false, GSI_CONTINUE_LINKING);
-  dest = builtin->dst_base;
-  src = builtin->src_base;
+  dest = rewrite_to_non_trapping_overflow (builtin->dst_base);
+  src = rewrite_to_non_trapping_overflow (builtin->src_base);
   if (partition->kind == PKIND_MEMCPY
       || ! ptr_derefs_may_alias_p (dest, src))
     kind = BUILT_IN_MEMCPY;