Sheng Zhou
2008-Aug-12 08:24 UTC
[LLVMdev] 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. Any comments for this? Thanks in advance. Sheng.
Bill Wendling
2008-Aug-12 20:23 UTC
[LLVMdev] A case where llvm created different cfg for same code
On Tue, Aug 12, 2008 at 1:24 AM, Sheng Zhou <zhousheng at autoesl.com> wrote:> Hi, > > The following two segments of code are actually the same, > but llvm created different cfg for them. >...> > 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. > > Any comments for this? Thanks in advance. >The code is not the same. 7 is commented out in the first and 8 in the second. Why would you expect the CFGs to match? Is there something wrong (inefficient) in the resulting output of these two functions when compiled? -bw
Possibly Parallel Threads
- [LLVMdev] A case where llvm created different cfg for same code
- [LLVMdev] A case where llvm created different cfg for same code
- problem with nested loops
- Setting up list of many equations for systemfit
- [LLVMdev] scalar-evolution + indvars fail to get the loop trip count?