<div dir="ltr"><pre>Hi,<br><br>The following two segments of code are actually the same,<br>but llvm created different cfg for them.<br><br>Form1:<br><br>1 #define N 10<br>2 int test(int A[N][N])<br>3 {<br>4 int i, j;<br>5 int result =0;<br>
6 for(j=0; j+2<N; ++j) {<br>7 //for(i=0; i<j && i+j+1<N; i++) {<br>8 for(i=0; i<j && i<N-j-1; i++) {<br>9 A[i+j+1][j] = A[j + 2][j-i] + i;<br>10 }<br>11 }<br>12<br>13 for (i=0; i<N-2; ++i)<br>
14 for (j=0; j<N; ++j)<br>15 result ^= A[i][j];<br>16 return result;<br>17 }<br><br>Form2:<br><br>1 #define N 10<br>2 int test(int A[N][N])<br>3 {<br>4 int i, j;<br>5 int result =0;<br>6 for(j=0; j+2<N; ++j) {<br>7 for(i=0; i<j && i+j+1<N; i++) {<br>
8 //for(i=0; i<j && i<N-j-1; i++) {<br>9 A[i+j+1][j] = A[j + 2][j-i] + i;<br>10 }<br>11 }<br>12<br>13 for (i=0; i<N-2; ++i)<br>14 for (j=0; j<N; ++j)<br>15 result ^= A[i][j];<br>16 return result;<br>17 }<br>
<br>The prime difference is that: cfg of form2 has additional basic block<br>which has a back edge to a non-header-block<br>I think the loop in that cfg is not canonical.<br><br>I tried -loopsimplify and -indvars , but no improvement.<br>
<br>Any comments for this? Thanks in advance.<br><br><br>Sheng.<br></pre></div>