Description
This looks like a long-standing issue since Clang-15. Clang at -O2/3 produces the wrong code. opt-bisect-limit
suggests that the issue might be in LoopVectorizePass
.
Compiler explorer: https://godbolt.org/z/dssMcdz55
% cat a.c
int printf(const char *, ...);
long a, c;
long *b = &a;
char d;
char *const e = &d;
int f, g, h;
int main() {
long i[] = {1, 4, 4, 1, 4, 4};
for (; g >= -6; g--) {
f = 0;
for (; f <= 5; f++)
c = i[f] ^= *e > *b;
*e = 1;
}
for (; h < 1; h++)
printf("%d\n", (int)c);
}
%
% clang-tk -O0 a.c && ./a.out
4
% clang-tk -O2 a.c && ./a.out
1
% clang-tk -O3 a.c && ./a.out
1
%
% clang-tk -v
clang version 17.0.0 (https://github.com/llvm/llvm-project.git a5bba98a58b7406f81629d3942e03b1eff1e2b33)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/shaoli/compilers/ccbuilder-compilers
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Candidate multilib: .;@m64
Selected multilib: .;@m64
%
Metadata
Metadata
Assignees
Type
Projects
Status
Done