Loop-interchange : Some triangular loop nests are interchanged
| Bugzilla Link | 49306 |
| Version | 11.0 |
| OS | Linux |
| CC | @CongzheUalberta |
Extended Description
$ clang -Os -mllvm -enable-loopinterchange=true traingular_fail.c && ./a.out 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
$ clang -Os -mllvm -enable-loopinterchange=false triangular_fail.c && ./a.out 0 2 7 83 0 0 9 43 0 0 0 0 0 0 0 0
$ cat triangular_fail.c #include <stdio.h>
int foo() {
int A[4][4] = {{ 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}, { 0, 0, 0, 0}}; int B[4][4] = {{ 16, 2, 7, 83}, { 35, 8, 9, 43}, { 47, 123, 32, 0}, { 21, 11, 19, 29}}; for (int i = 0; i < 4; ++i) for (int j = 0; j < i; ++j) A[j][i] = B[j][i];
for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; j++) printf("%d ", A[i][j]);
printf("\n");
return 0; }
int main() { foo(); return 0; }
LoopInterchange does not detect the issue with the operation j<i in the inner loop, thus, breaking the program correctness.
Should be fixed by https://reviews.llvm.org/D101305
Fixed by https://reviews.llvm.org/D101305 . I confirmed LLVM 12 has the problem and LLVM 13 doesn't have the problem.