<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=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @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;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        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;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</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=Section1>

<p class=MsoNormal>Hi all,<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>I’m getting more impressed by LLVM day by day, but
what’s a bit unclear to me now is the order of optimization passes, and their
performance. I think I have a pretty solid understanding of what each pass does
at a high level, but I couldn’t find any documentation about how they
interact at a lower level.<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>I’d like to use LLVM for generating high-performance
stream processing code at run-time. Obviously the resulting code should be as
optimized as possible, but performing the optimizations themselves should also
be very fast. The code I’m compiling is comparable to C (without any
exception handling or garbage collection, so none of the related passes are
needed). My first attempt at collecting useful optimizations looks like this:<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'>passManager->add(<span style='color:blue'>new</span>
TargetData(*executionEngine->getTargetData()));<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'>passManager->add(createScalarReplAggregatesPass());  
// Convert to SSA form<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'>passManager->add(createSCCPPass());                  
// Propagate constants<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'>passManager->add(createInstructionCombiningPass());  
// Peephole optimization<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'>passManager->add(createDeadStoreEliminationPass());  
// Dead store elimination<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>passManager->add(createAggressiveDCEPass());         
// Aggressive dead code elimination<o:p></o:p></span></p>

<p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;
font-family:"Courier New"'>passManager->add(createCFGSimplificationPass());     
// Control-flow optimization<o:p></o:p></span></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>I have several questions about this:<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>1) Does ScalarReplAggregates totally superscede
PromoteMemoryToRegister? I think I need it to optimize small arrays, but what
is the expected added complexity?<o:p></o:p></p>

<p class=MsoNormal>2) Does SCCP also eliminate multiplying/dividing by 1 and
adding/subtracting 0?<o:p></o:p></p>

<p class=MsoNormal>3) Is it arbitrary where to place InstructionCombining? Is
there a better order?<o:p></o:p></p>

<p class=MsoNormal>4) Is DeadStoreElimination still necessary when we have
AggressiveDCE?<o:p></o:p></p>

<p class=MsoNormal>5) What are the tradeoffs between the different dead code
elimination variants (why not always use the aggressive one)? <o:p></o:p></p>

<p class=MsoNormal>6) Is there a better place for CFGSimplification? Should I
perform it at multiple points?<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>Also, my code will frequently have vectors, that are either
initialized to all 0.0 or 1.0. This offers a lot of opportunity for eliminating
many multiplications and additions, but I was wondering which passes I need for
this (probably a Reassociate pass, what else)? And I also wonder whether these
passes actually work with vectors?<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>Is there any other highly recommended pass for this kind of
applications that I’m forgetting? Any passes that I better avoid due to poor
gains and long optimization time?<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>Sorry for the many question marks. :-) I don’t expect
there is an absolute definite answer to each of them, but some guidelines and
insights would be very welcome and much appreciated.<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>Thanks!<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>Nicolas Capens<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

</div>

</body>

</html>