A case where llvm created different cfg for same code

``````Hi,

The following two segments of code are actually the same,
but llvm created different cfg for them.

Form1:

1 #define N 10
2 int test(int A[N][N])
3 {
4 int i, j;
5 int result =0;

6 for(j=0; j+2<N; ++j) {
7 //for(i=0; i<j && i+j+1<N; i++) {
8 for(i=0; i<j && i<N-j-1; i++) {
9 A[i+j+1][j] = A[j + 2][j-i] + i;
10 }
11 }
12
13 for (i=0; i<N-2; ++i)

14 for (j=0; j<N; ++j)
15 result ^= A[i][j];
16 return result;
17 }

Form2:

1 #define N 10
2 int test(int A[N][N])
3 {
4 int i, j;
5 int result =0;
6 for(j=0; j+2<N; ++j) {
7 for(i=0; i<j && i+j+1<N; i++) {

8 //for(i=0; i<j && i<N-j-1; i++) {
9 A[i+j+1][j] = A[j + 2][j-i] + i;
10 }
11 }
12
13 for (i=0; i<N-2; ++i)
14 for (j=0; j<N; ++j)
15 result ^= A[i][j];
16 return result;
17 }

The prime difference is that: cfg of form2 has additional basic block
which has a back edge to a non-header-block
I think the loop in that cfg is not canonical.

I tried -loopsimplify and -indvars , but no improvement.