Hi! As discussed in the PR, ix86_expand_set_or_movmem assumes that count == 0 means !CONST_INT_P (count_exp), but that is not necessarily true with -O0 -ftree-ter, when the middle-end doesn't immediately see the length argument be integer_zerop, yet TER results in it being expanded as const0_rtx.
There is nothing to set or move in that case, so this patch makes the backend more tolerand just by returning true immediately. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2014-05-12 Jakub Jelinek <ja...@redhat.com> PR target/61060 * config/i386/i386.c (ix86_expand_set_or_movmem): If count_exp is const0_rtx, return immediately. Don't test count == 0 when it is always true. * gcc.dg/pr61060.c: New test. --- gcc/config/i386/i386.c.jj 2014-05-11 22:21:28.000000000 +0200 +++ gcc/config/i386/i386.c 2014-05-12 10:59:18.940416162 +0200 @@ -24156,8 +24156,13 @@ ix86_expand_set_or_movmem (rtx dst, rtx align = MEM_ALIGN (dst) / BITS_PER_UNIT; if (CONST_INT_P (count_exp)) - min_size = max_size = probable_max_size = count = expected_size - = INTVAL (count_exp); + { + min_size = max_size = probable_max_size = count = expected_size + = INTVAL (count_exp); + /* When COUNT is 0, there is nothing to do. */ + if (!count) + return true; + } else { if (min_size_exp) @@ -24166,7 +24171,7 @@ ix86_expand_set_or_movmem (rtx dst, rtx max_size = INTVAL (max_size_exp); if (probable_max_size_exp) probable_max_size = INTVAL (probable_max_size_exp); - if (CONST_INT_P (expected_size_exp) && count == 0) + if (CONST_INT_P (expected_size_exp)) expected_size = INTVAL (expected_size_exp); } --- gcc/testsuite/gcc.dg/pr61060.c.jj 2014-05-12 11:03:10.797222337 +0200 +++ gcc/testsuite/gcc.dg/pr61060.c 2014-05-12 11:03:02.882263281 +0200 @@ -0,0 +1,19 @@ +/* PR target/61060 */ +/* { dg-do compile } */ +/* { dg-options "-O0 -ftree-ter" } */ + +typedef __SIZE_TYPE__ size_t; + +extern inline __attribute__ ((gnu_inline, always_inline, artificial)) +void *memset (void *dest, int ch, size_t len) +{ + return __builtin_memset (dest, ch, len); +} + +char buf[10]; + +void +foo (void) +{ + memset (buf, sizeof (buf), 0); +} Jakub