<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:PMingLiU;
panose-1:2 2 5 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@PMingLiU";
panose-1:2 2 5 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;
font-weight:normal;
font-style:normal;
text-decoration:none none;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:9.0pt;color:#1F497D">Try the combo:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.0pt;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.0pt;color:#1F497D">-enable-unroll-and-jam -allow-unroll-and-jam -unroll-and-jam-count=4<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:9.0pt;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> <b>On Behalf Of
</b>ZHEN WEI via llvm-dev<br>
<b>Sent:</b> Thursday, April 25, 2019 12:13 PM<br>
<b>To:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> [llvm-dev] How to use the pass 'Unroll and Jam'<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<p class="MsoNormal">Dear LLVM developers,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Recently I want to try the pass '-loop-unroll-and-jam' to observe how the IR is transformed, but I don't see the IR changed after doing the following steps.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Here are the details for preparing my experiment and I have tried the LLVM 6, 7 and 8:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">1) Simple 2D array source code (loop.c) is given<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal">#define M 32768<o:p></o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal">#define N 32768<o:p></o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal">double a[M][N], b[M][N], c[M][N];<o:p></o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal">int main() {<o:p></o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal"> for (int i = 0; i < M; i++) {<o:p></o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal"> for (int j = 0; j < N; j++) {<o:p></o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal"> c[i][j] = a[i][j] + b[i][j];<o:p></o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal"> }<o:p></o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal"> }<o:p></o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal"> return 0;<o:p></o:p></p>
</div>
<div style="margin-left:30.0pt">
<p class="MsoNormal">}<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">2) Create an LLVM IR file<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">./bin/clang -O1 loop.c -emit-llvm -S -o loop.ll<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">3) Run the 'unroll-and-jam' pass<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">./bin/opt -loop-unroll-and-jam loop.ll -S -o loop-unrolljam.ll<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I added the option '--debug-pass=Structure' to the opt, and I can see the 'Unroll and Jam loops' indeed executed by the Loop Pass Manager.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<div style="margin-left:30.0pt">
<p class="MsoNormal"> ModulePass Manager<br>
FunctionPass Manager<br>
Dominator Tree Construction<br>
Basic Alias Analysis (stateless AA impl)<br>
Function Alias Analysis Results<br>
Natural Loop Information<br>
Scalar Evolution Analysis<br>
Dependence Analysis<br>
Canonicalize natural loops<br>
LCSSA Verifier<br>
Loop-Closed SSA Form Pass<br>
Loop Pass Manager<br>
Unroll and Jam loops<br>
Module Verifier<br>
Print Module IR<o:p></o:p></p>
</div>
<p class="MsoNormal">```<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I also tried to add the option '-debug' to the opt to see if there is the debug information printed by LoopUnrollAndJam, but nothing.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thank you very much.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">-- <o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-family:"PMingLiU",serif">Zhen Wei (魏禛)</span><br>
<span style="font-family:"PMingLiU",serif">Master Student</span><br>
<span style="font-family:"PMingLiU",serif;color:black">Department of Computer Science & Information Engineering</span><br>
<span style="font-family:"PMingLiU",serif;color:black">National Taiwan University</span><br>
<span style="font-family:"PMingLiU",serif">Email: <a href="mailto:zhenwei.tw@gmail.com" target="_blank">
zhenwei.tw@gmail.com</a></span><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>