https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66648

--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
Untested patch:

--cut here--
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c  (revision 224993)
+++ config/i386/i386.c  (working copy)
@@ -25008,7 +25008,8 @@ ix86_expand_set_or_movmem (rtx dst, rtx src, rtx c
       dst = change_address (dst, BLKmode, destreg);
       set_mem_align (dst, desired_align * BITS_PER_UNIT);
       epilogue_size_needed = 0;
-      if (need_zero_guard && !min_size)
+      if (need_zero_guard
+         && min_size < (unsigned HOST_WIDE_INT) size_needed)
        {
          /* It is possible that we copied enough so the main loop will not
             execute.  */
@@ -25140,7 +25141,7 @@ ix86_expand_set_or_movmem (rtx dst, rtx src, rtx c
          max_size -= align_bytes;
        }
       if (need_zero_guard
-         && !min_size
+         && min_size < (unsigned HOST_WIDE_INT) size_needed
          && (count < (unsigned HOST_WIDE_INT) size_needed
              || (align_bytes == 0
                  && count < ((unsigned HOST_WIDE_INT) size_needed
--cut here--

We have to emit check for main loop execution UNLESS we guarantee that min_size
is at least equal to size_needed. In this testcase, VRP declared minimum
copying size, and after unaligned prologue adjustment, min_size was still
non-zero. The !min_size check didn't account for the case that min_size can be
non-zero, but still less than size_needed.

Reply via email to