<html 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=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (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;}
@font-face
        {font-family:Monaco;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="en-PK" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB">Hello,</span><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;mso-fareast-language:EN-GB"><br>
<span style="background:#F8F8F8">I wanted to inquire if there is a way within LLVM/Clang to limit (function-level) optimizations to certain contiguous regions within the function. E.g.</span></span><span style="mso-fareast-language:EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">void foo(int* A, int n1, int n2){<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">        
</span><span lang="EN-US" style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">// Enable optimizations above this loop<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">         ...<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">        
</span><span lang="EN-US" style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">// (#pragma clang loop nolicm?)<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">         for(int i = 0; i < n1; ++i){<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">                 for(int j=0; j< n2; j++){<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">                          int i_offset = (n2*i); // Do not Hoist</span><span lang="EN-US" style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">
 to outside current loop<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">                          int net_offset = i_offset + j;<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">                          A[net_offset] = ...;<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">                 }       
<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">         }<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">        
</span><span lang="EN-US" style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">// Enable optimizations below this loop</span><span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">         ...<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:3.0pt;margin-right:0cm;margin-bottom:3.0pt;margin-left:0cm">
<span style="font-size:9.0pt;font-family:Monaco;color:#1D1C1D;mso-fareast-language:EN-GB">}<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB">In the above case, would it be possible to disable Loop Invariant Code motion just for that loop nest in the function
 foo, but enable it to be used elsewhere in the function? We would like to disable certain passes like LICM for our use-case</span><span lang="EN-US" style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB">
 (We’ve defined markers inside the functions specifying the start and end of certain regions and we want to limit certain optimizations as we will be extracting those code regions later on)</span><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB">.</span><span style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB">
<span lang="EN-US"><o:p></o:p></span></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB">The clang pragma at
<a href="https://bcain-llvm.readthedocs.io/projects/clang/en/latest/LanguageExtensions/#id20">
https://bcain-llvm.readthedocs.io/projects/clang/en/latest/LanguageExtensions/#id20</a> acts at a per function level. Similarly the loop optimizations pragmas
<a href="https://clang.llvm.org/docs/LanguageExtensions.html#id30">https://clang.llvm.org/docs/LanguageExtensions.html#id30</a> only cover some of the loop specific metadata’s available in LLVM (For example, I wasn’t able to find a way to add ‘llvm.licm.disable’
 to loops at the source level). <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB">Thank you,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB">Abdul Rafae Noor<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB">Grad Student,
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:11.5pt;font-family:"Arial",sans-serif;color:#1D1C1D;background:#F8F8F8;mso-fareast-language:EN-GB">University of Illinois, Urbana Champaign</span><span lang="EN-US" style="mso-fareast-language:EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>