[Bug tree-optimization/100511] Fail to remove dead code in loop

jiangning.liu at amperecomputing dot com gcc-bugzilla@gcc.gnu.org
Tue May 11 04:54:40 GMT 2021


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

--- Comment #2 from Jiangning Liu <jiangning.liu at amperecomputing dot com> ---
Then why gcc can't optimize this case either? sizeof (XX) <> sizeof(g) here.

#include <stdio.h>

int a;
typedef struct {
    int b;
    int count;
} XX;

int g;

__attribute__((noinline)) void f(XX *x)
{
    int c1 = 0;
    int c3 = a;
    if (x)
        c1 = x->count;
    for (int i=0; i<c1; i++) {
        if (c3 == x->count) {
            if (i > c3) {
                printf("Unreachable!");
                break;
            }
            else
                g = 2;
        } else
            g = i;
    }
}

void main(void)
{
    XX x;
    x.count = 100;
    a = 100;
    f(&x);
}


More information about the Gcc-bugs mailing list