Closed
Description
clang at -O2 produced the wrong code.
Bisected to 3ddd1ff, which was committed by @nikic
Compiler explorer: https://godbolt.org/z/rEv69ovMj
% cat a.c
int printf(const char *, ...);
char *a;
long b, c, d, m;
int e, f, j, l;
short g;
int *k = &j;
int main() {
int *n[] = {&f, &f, &f, &f, &f, &e};
d = 0;
for (; d <= 1; d++) {
g = 0;
for (; g <= 4; g++) {
char h[] = {0, 0, 4};
char *i = h;
a = i;
do {
a++;
b /= 10;
} while (b);
c = a - i;
while (i < a){
*i = *(i+1);
i++;
}
*k ^= c;
k = n[d + g];
l ^= m;
}
}
printf("%d\n", e);
}
%
% clang -O0 a.c && ./a.out
0
% clang -O2 a.c && ./a.out
1
%
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
nikic commentedon Oct 6, 2023
I believe the problem here is that we have a load from an addrec based on a constant global. The SCEV for the load will indeed always be Unknown, but the SCEVAtScope may not be: We can determine the exit value of the addrec and based on that determine the exit value of the load.
nikic commentedon Oct 6, 2023
I think this is a nice reduction:
Results in:
[IndVars] Add test for #68260 (NFC)
Revert "[SCEV] Don't invalidate past dependency-breaking instructions"