https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100511
Bug ID: 100511
Summary: Fail to remove dead code in loop
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: jiangning.liu at amperecomputing dot com
Target Milestone: ---
For this simple case, gcc doesn't know the if condition (i > c2) is always
false.
#include <stdio.h>
typedef struct {
int count;
} XX;
int g;
__attribute__((noinline)) void f(XX *x)
{
int c1 = 0;
if (x)
c1 = x->count;
for (int i=0; i<c1; i++) {
int c2 = x->count;
if (i > c2) {
printf("Unreachable!");
break;
}
else
g = i;
}
}
void main(void)
{
XX x;
x.count = 100;
f(&x);
}
If we change variable the type of variable g to float, gcc does optimize away
this if condition inside the loop, so why alias analysis can't recognize g is
different from x->count?