llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Loop-interchange : Some triangular loop nests are interchanged

Open N-SysR opened this issue 5 years ago • 2 comments

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.

N-SysR avatar Feb 22 '21 09:02 N-SysR

Should be fixed by https://reviews.llvm.org/D101305

CongzheUalberta avatar May 12 '21 04:05 CongzheUalberta

Fixed by https://reviews.llvm.org/D101305 . I confirmed LLVM 12 has the problem and LLVM 13 doesn't have the problem.

kawashima-fj avatar Jun 29 '22 04:06 kawashima-fj