http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59689

            Bug ID: 59689
           Summary: Code bloat introduced by pointer arithmetic
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: til...@code-monkey.de

The C snippet below contains two lines which AFAICS should be equivalent, but
depending on which of the two is used, gcc will either generate "good" (few
instructions) or "bad" (more instructions) code.

$ armv5tel-softfloat-linux-gnueabi-gcc -O2 t.c -S -DGOOD -o good.S -std=gnu99
$ armv5tel-softfloat-linux-gnueabi-gcc -O2 t.c -S -DBAD -o bad.S -std=gnu99
$ wc -l good.S bad.S 
 132 good.S
 206 bad.S
$

#define M(c) \
    do { \
        c = *(++ptr); \
        if (!flag && f2()) \
            flag = 1; \
        if (!flag) { \
            f3 (c); \
        } \
    } while (0)

unsigned f2 (void);
void f3 (unsigned c);

void f()
{
    const int size = 512;
    char *ptr, line[size];
    unsigned flag = 0;

#ifdef GOOD
    ptr = &line[0] - 1;             // !!
#elif BAD
    ptr = line; ptr--;              // !!
#else
# error need either GOOD or BAD
#endif

    for (;;) {
        unsigned c;

        M (c); M (c); M (c); M (c);
        M (c); M (c); M (c); M (c);

        M (c); M (c); M (c); M (c);
        M (c); M (c); M (c); M (c);
    }
}

Reply via email to