<div dir="ltr">Dear all,<div><br></div><div>Imagine we have following code:<div>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(200,20,201);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space" style=""> </span>1 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">#define ny </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">10</span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(200,20,201);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>2 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">#define Batch_Size </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">10</span></font></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(159,160,28);background-color:rgba(0,0,0,0.85)"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><font size="1"><span class="gmail-Apple-converted-space"> </span>3<span class="gmail-Apple-converted-space"> </span></font></span></p>
<p class="gmail-p3" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(47,180,29);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>4 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">typedef</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(160,160,160)"> </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">float</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(160,160,160)"> data_t;</span></font></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(159,160,28);background-color:rgba(0,0,0,0.85)"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><font size="1"><span class="gmail-Apple-converted-space"> </span>5<span class="gmail-Apple-converted-space"> </span></font></span></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>6 </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">void</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"> foo(data_t out[ny][Batch_Size], data_t max[Batch_Size]);</span></font></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(159,160,28);background-color:rgba(0,0,0,0.85)"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><font size="1"><span class="gmail-Apple-converted-space"> </span>7<span class="gmail-Apple-converted-space"> </span></font></span></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>8 </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">void</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"> Softmax_Activation(data_t l_Z2[ny][Batch_Size],</span></font></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>9 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>data_t out[ny][Batch_Size]) {</span></font></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(159,160,28);background-color:rgba(0,0,0,0.85)"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><font size="1"><span class="gmail-Apple-converted-space"> </span>10<span class="gmail-Apple-converted-space"> </span></font></span></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>11 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>data_t max[Batch_Size];</span></font></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(159,160,28);background-color:rgba(0,0,0,0.85)"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><font size="1"><span class="gmail-Apple-converted-space"> </span>12<span class="gmail-Apple-converted-space"> </span></font></span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(159,160,28);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>13 SA_MAX2</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(160,160,160)">:</span></font></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>14 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">for</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"> (</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">int</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"> i = </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">0</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">; i < Batch_Size; i++) {</span></font></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>15 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>max[i] = </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">0</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">;</span></font></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(159,160,28);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>16 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(160,160,160)"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">SA_MAX1</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(160,160,160)">:</span></font></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>17 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">for</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"> (</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">int</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"> j = </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">0</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">; j < ny; j++) {</span></font></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>18 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">if</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"> (l_Z2[j][i] > max[i])</span></font></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>19 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>max[i] = l_Z2[j][i];</span></font></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>20 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>}</span></font></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(159,160,28);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>21 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(160,160,160)"><span class="gmail-Apple-converted-space"> </span>}</span></font></p>
<p class="gmail-p4" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>22 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>foo(out, max);</span></font></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(159,160,28);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>23 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(160,160,160)">}</span></font></p></div><div>we can see 'max[i]' is an invariant variable to loop 'SA_MAX1', so I want to know which pass can following following transformation/optimization:</div><div>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space" style=""> </span>1 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)">#define ny </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">10</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>2 </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(200,20,201)">#define Batch_Size </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">10</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>3 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>4 </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">typedef</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">float</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> data_t; <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>5 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>6 </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">void</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> foo(data_t out[ny][Batch_Size], data_t max[Batch_Size]); <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>7 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>8 </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">void</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> Softmax_Activation(data_t l_Z2[ny][Batch_Size],<span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>9 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>data_t out[ny][Batch_Size]) { <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>10 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>11 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>data_t max[Batch_Size]; <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>12 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>13 SA_MAX2</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">:<span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>14 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">for</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> (</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">int</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> i = </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">0</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">; i < Batch_Size; i++) {<span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>15 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>data_t Max = </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">0</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">; <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>16 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">SA_MAX1</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">:<span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>17 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">for</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> (</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(47,180,29)">int</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> j = </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(180,36,25)">0</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures">; j < ny; j++) {<span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>18 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)">if</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"> (l_Z2[j][i] > Max) <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>19 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>Max = l_Z2[j][i]; <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>20 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>} <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>21 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>max[i] = Max; <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>22 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>} <span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(160,160,160);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(159,160,28)"><span class="gmail-Apple-converted-space"> </span>23 </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>foo(out, max);<span class="gmail-Apple-converted-space"> </span></span></font></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;line-height:normal;font-family:Monaco;color:rgb(159,160,28);background-color:rgba(0,0,0,0.85)"><font size="1"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space"> </span>24 </span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(160,160,160)">}<span class="gmail-Apple-converted-space" style=""> </span></span></font></p></div><div>Which will use a local scalar 'Max' to replace the original 'max[i]', and sink the original write out of the loop 'SA_MAX1'.</div><div><br></div><div>I did some experiment with godbolt, looks like currently we don't have such kind of optimization.</div><div><a href="https://godbolt.org/z/9PK3hYvPs">https://godbolt.org/z/9PK3hYvPs</a><br></div><div><br></div><div>Do you know which pass can do this? Or it's not necessary for CPU?</div><div><br></div><div>Thanks,</div><div>Fangqing</div><div>Xilinx Inc.</div><div><br></div><div><br></div><div><br></div></div></div>