<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Dear all,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
    Hi! Recently, I use loop extractor pass in the latest version, which extracts loops into functions, to optimize part of the code.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
    However, I notice some problems which might be caused by the assumption of loop extractor and lead to some functionalities may miss in the transformed IR code.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
    I walk around the problem by inserting redundant basic blocks for loop header but I think it could cause problem for someone else.<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
    I guess the problem is caused by the assumption shown in llvm/lib/Transforms/Utils/CodeExtractor.cpp<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
=================================================<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>Function *CodeExtractor::extractCodeRegion() {</span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
  // Assumption: this is a single-entry code region, and the header is the first<br>
<span>  // block in the region.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>=================================================</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>  <br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span><br>
</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span>   You can try to reproduce the problem with the following simple source code. You can notice that the if-else branch is gone and the IR code is wrong.</span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span></span><br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div style="color: #d4d4d4; background-color: #1e1e1e; font-family: 'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback'; font-weight: normal; font-size: 14px; line-height: 19px">
<br>
<div><span style="color: #569cd6">void</span><span> </span><span style="color: #dcdcaa">f</span><span>(
</span><span style="color: #569cd6">int</span><span> </span><span style="color: #9cdcfe">A</span><span>[</span><span style="color: #b5cea8">56</span><span>][</span><span style="color: #b5cea8">100</span><span>],  </span><span style="color: #569cd6">int</span><span> </span><span>*</span><span style="color: #9cdcfe">C</span><span>)
</span></div>
<div><span>{</span></div>
<div><span>    </span><span style="color: #569cd6">int</span><span> N </span><span>=</span><span> </span><span style="color: #b5cea8">100</span><span>;</span></div>
<div><span>    </span><span style="color: #569cd6">int</span><span> M </span><span>=</span><span> </span><span style="color: #b5cea8">56</span><span>;</span></div>
<div><span>    </span><span style="color: #c586c0">for</span><span> ( </span><span style="color: #569cd6">int</span><span> j
</span><span>=</span><span> </span><span style="color: #b5cea8">1</span><span>; j
</span><span><</span><span> N; j</span><span>++</span><span> )</span></div>
<div><span>        </span><span style="color: #c586c0">for</span><span> ( </span>
<span style="color: #569cd6">int</span><span> i </span><span>=</span><span> </span><span style="color: #b5cea8">1</span><span>; i
</span><span><</span><span> M</span><span>+</span><span style="color: #b5cea8">1</span><span>; i</span><span>++</span><span> )</span></div>
<div><span>        {</span></div>
<div><span>            </span><span style="color: #9cdcfe">A</span><span>[i][j] </span>
<span>=</span><span> </span><span style="color: #9cdcfe">A</span><span>[i</span><span>-</span><span style="color: #b5cea8">1</span><span>][j</span><span>-</span><span style="color: #b5cea8">1</span><span>]
</span><span>+</span><span> </span><span style="color: #9cdcfe">A</span><span>[i][j</span><span>-</span><span style="color: #b5cea8">1</span><span>]
</span><span>+</span><span> </span><span style="color: #9cdcfe">A</span><span>[i</span><span>-</span><span style="color: #b5cea8">1</span><span>][j]
</span><span>+</span><span> </span><span style="color: #b5cea8">1</span><span>;          
</span></div>
<div><span>        }</span></div>
<br>
<div><span>    </span><span style="color: #c586c0">if</span><span> (</span><span>*</span><span>C</span><span>></span><span style="color: #b5cea8">10</span><span>)</span></div>
<div><span>    {</span></div>
<div><span>      </span><span>*</span><span>C </span><span>=</span><span> </span><span style="color: #b5cea8">10</span><span>;</span></div>
<div><span>      </span><span style="color: #c586c0">for</span><span> ( </span><span style="color: #569cd6">int</span><span> j
</span><span>=</span><span> </span><span style="color: #b5cea8">1</span><span>; j
</span><span><</span><span> N; j</span><span>++</span><span> )</span></div>
<div><span>          </span><span style="color: #c586c0">for</span><span> ( </span>
<span style="color: #569cd6">int</span><span> i </span><span>=</span><span> </span><span style="color: #b5cea8">1</span><span>; i
</span><span><</span><span> M</span><span>+</span><span style="color: #b5cea8">1</span><span>; i</span><span>++</span><span> )</span></div>
<div><span>          {</span></div>
<div><span>              </span><span style="color: #9cdcfe">A</span><span>[i][j]
</span><span>=</span><span> </span><span style="color: #9cdcfe">A</span><span>[i</span><span>-</span><span style="color: #b5cea8">1</span><span>][j</span><span>-</span><span style="color: #b5cea8">1</span><span>]
</span><span>+</span><span> </span><span style="color: #9cdcfe">A</span><span>[i][j</span><span>-</span><span style="color: #b5cea8">1</span><span>]
</span><span>+</span><span> </span><span style="color: #9cdcfe">A</span><span>[i</span><span>-</span><span style="color: #b5cea8">1</span><span>][j]
</span><span>+</span><span> </span><span style="color: #b5cea8">1</span><span>;            
</span></div>
<div><span>          }</span></div>
<div><span>    }</span></div>
<div><span>    </span><span style="color: #c586c0">return</span><span>;</span></div>
<div><span>}</span></div>
<br>
</div>
<span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span><span>=</span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<span id="ms-rterangepaste-start"></span>
<div><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Best regards,</span></font><span style="font-size:12pt">
</span><span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">------------------------------------------</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Tingyuan LIANG</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">MPhil Student</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">Department of Electronic and Computer Engineering</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span>
<div><span style="font-size:12pt"></span>
<div style="margin:0"><font size="2" face="Calibri,sans-serif"><span style="font-size:12pt">The Hong Kong University of Science and Technology</span></font></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span></div>
<span style="font-size:12pt"></span><span style="font-size:12pt"></span><span id="ms-rterangepaste-end"></span></div>
</div>
</body>
</html>