[gnu.gcc.bug] Missed optimization in `gcc'

derek@UUNET.UU.NET (Derek Clegg) (03/10/89)

/* Version:
 *     gcc version 1.34
 * File:
 *     <this file>
 * Problem:
 *     `gcc' fails to optimize fully in the case of dereference +
 *     autoincrement + pointer cast.
 * Repeat by:
 *     % gcc -O -S <this file>
 * Notes:
 *     `gcc' doesn't always take into account the size of the object pointed
 *     to by a pointer when dereferencing & autoincrementing.  If the size is
 *     1, 2, or 4 bytes, a simpler set of instructions could often be generated.
 *
 *     The generated assembler isn't affected by any of the `-f' flags.
 *
 *     gcc was compiled with `config.gcc sun3'.
 *     I am using a Sun 3/60 with UNIX 4.2 (Sun release 3.5).
 *
 *		Derek B Clegg ({uunet,ucbcad,sun}!island!derek)
 */
void
xyzzy(int n, int *i1, int *i2, int k, char *s1, char *s2)
{
    while (--n >= 0)
	*i1++ = *i2++;
    /* 
     * The above generates something similar to
     * L4:
     *     movel a0@+,a1@+
     * L2:
     *     subql #1,d0
     *     jpl L4
     */

    while (--k >= 0)
	*((int *)s1)++ = *((int *)s2)++;

    /*
     * This generates, however, something similar to
     * L7:
     *     movel d2,a0
     *     addql #4,d2
     *     movel d1,a1
     *     addql #4,d1
     *     movel a1@,a0@
     * L5:
     *     subql #1,d3
     *     jpl L7
     *
     * when, of course, the first sequence would be perfectly appropriate.
     */
}