Loop interchange for a multiple loop containing if-statement may be performed incorrectly.
Therefore, I modified the loop interchange so that it does not optimize loops that contain conditional statements.
For example, in the following example, "-1, -1" is correct. However, if the loop is interchanged, "1, 1" is output.
#include <stdio.h> void bar(int x[restrict 2], int a[restrict 2][2]) { for (int i=0; i<2; ++i) { for (int j=0; j<2; ++j) { for (int k=0; k<2; ++k) { if (x[j] == a[k][i]) { x[j] = i - k; } } } } } int main(void) { int x[2] = {2, 2}; int a[2][2] = {{0, 2}, {2, 0}}; bar(x, a); printf("%d, %d\n", x[0], x[1]); return 0; }
Specified options are "-Ofast -mllvm -enable-loopinterchange=true -flegacy-pass-manager".
clang-tidy: warning: field 'ORE' will be initialized after field 'DT' [clang-diagnostic-reorder-ctor]
not useful
clang-format: please reformat the code