Zhou Sheng
2008-Aug-12 08:29 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080812/ea6129b3/attachment.html>
Seemingly Similar Threads
- [LLVMdev] A case where llvm created different cfg for same code
- [LLVMdev] A case where llvm created different cfg for same code
- Loops, Paste, Apply? What is the best way to set up a list of many equations?
- Modal dialogs getting out of focus
- problem with nested loops