<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 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:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;
        color:black;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;
        mso-fareast-language:EN-US;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle22
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle23
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
span.EmailStyle24
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@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 bgcolor="white" lang="RU" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">I have uploaded a patch with the straightforward fix (clearing function’s assumption cache after extracting blocks from it) -
<a href="https://reviews.llvm.org/D57215">https://reviews.llvm.org/D57215</a></span><span lang="EN-US" style="color:windowtext">.
</span><span lang="EN-US" style="color:#1F497D">Please take a look.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">Sergey<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><a name="_____replyseparator"></a><b><span lang="EN-US" style="color:windowtext;mso-fareast-language:RU">From:</span></b><span lang="EN-US" style="color:windowtext;mso-fareast-language:RU"> Finkel, Hal J. [mailto:hfinkel@anl.gov]
<br>
<b>Sent:</b> Thursday, January 17, 2019 9:45 AM<br>
<b>To:</b> Dmitriev, Serguei N <serguei.n.dmitriev@intel.com>; llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] stale info in the assumption cache<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal">On 1/17/19 11:19 AM, Dmitriev, Serguei N wrote:<span style="font-size:12.0pt;mso-fareast-language:RU"><o:p></o:p></span></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">Hi Hal,</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D"> </span><o:p></o:p></p>
<div>
<p class="MsoNormal" style="text-indent:35.4pt"><span lang="EN-US">On 1/16/19 6:59 PM, Dmitriev, Serguei N via llvm-dev wrote:</span><o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US">Hi all,</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US">We have recently encountered a problem with AssumptionCache that it does not get updated when a block with llvm.assume calls gets outlined by the CodeExtractor. As a result we end up with stale
 references to the llvm.assume calls that were moved to the outlined function in the parent function’s cache.</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US">The problem can be reproduced on the attached file as follows (many thanks to Andy Kaylor for creating this reproducer)</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US">$ opt -slp-vectorizer -hotcoldsplit -slp-vectorizer -S -o - extract.ll</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US">opt: .../llvm/lib/Analysis/CodeMetrics.cpp:107: static void llvm::CodeMetrics::collectEphemeralValues(const llvm::Function*, llvm::AssumptionCache*, llvm::SmallPtrSetImpl<const llvm::Value*>&):
 Assertion `I->getParent()->getParent() == F && "Found assumption for the wrong function!"' failed.</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US">...</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US">The comments in the AssumptionCache seem to indicate that we should never get into this situation because AssumptionCache is supposed to be self-updating, but the case when a block with llvm.assume
 call is moved from one function to another is not correctly handled now. I wonder what the right way to fix this problem is.</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US">I guess a straightforward solution would be just changing CodeExtractor to clear function’s assumption cache right after extracting blocks from it, but that would require adding assumption analysis
 as a dependency to every pass that uses CodeExtractor.</span><o:p></o:p></p>
</blockquote>
<p style="margin-left:34.8pt"> <o:p></o:p></p>
<p style="margin-left:34.8pt">I don't, on first impression, have a better idea.<o:p></o:p></p>
<p style="margin-left:34.8pt"><span style="color:windowtext"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">Ok, I will probably implement this solution so far.</span><o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US">Or maybe there could be other solutions like for example somehow extending callback mechanism to handle updates of the basic block parent. Can you please suggest any ideas?</span><o:p></o:p></p>
</blockquote>
<p style="margin-left:34.8pt"> <o:p></o:p></p>
<p style="margin-left:34.8pt">I don't think that our current ValueHandle callbacks will give us this functionality. We'd need a new callback?<o:p></o:p></p>
<p style="margin-left:34.8pt"><span style="color:windowtext"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D">I also think that existing callbacks cannot handle the case when block’s parent is changed, so something new will be needed. AssumptionCache as I understand was designed to be self-updating, so maybe
 it would be nice to maintain this property.</span><o:p></o:p></p>
</blockquote>
<p><o:p> </o:p></p>
<p>I agree. Unfortunately, when writing the code I didn't think about this use case. Also, we need to weigh the cost of adding the callback vs. updating the more-rare transformation code. If the callback would appear on an otherwise hot path, it might not be
 the right trade off.<o:p></o:p></p>
<p> -Hal<o:p></o:p></p>
<p><o:p> </o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D;mso-fareast-language:RU">Thanks,</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US" style="color:#1F497D;mso-fareast-language:RU">Sergey</span><o:p></o:p></p>
<p class="MsoNormal"><span style="color:windowtext"> </span><o:p></o:p></p>
<p style="margin-left:34.8pt">Thanks again,<o:p></o:p></p>
<p style="margin-left:34.8pt">Hal<o:p></o:p></p>
<p style="margin-left:34.8pt"> <o:p></o:p></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US">Thanks,</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:34.8pt"><span lang="EN-US">Sergey</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt"><br>
<br>
<br>
</span><o:p></o:p></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>LLVM Developers mailing list<o:p></o:p></pre>
<pre><a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><o:p></o:p></pre>
<pre><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></pre>
</blockquote>
<pre>-- <o:p></o:p></pre>
<pre>Hal Finkel<o:p></o:p></pre>
<pre>Lead, Compiler Technology and Programming Languages<o:p></o:p></pre>
<pre>Leadership Computing Facility<o:p></o:p></pre>
<pre>Argonne National Laboratory<o:p></o:p></pre>
</blockquote>
<pre>-- <o:p></o:p></pre>
<pre>Hal Finkel<o:p></o:p></pre>
<pre>Lead, Compiler Technology and Programming Languages<o:p></o:p></pre>
<pre>Leadership Computing Facility<o:p></o:p></pre>
<pre>Argonne National Laboratory<o:p></o:p></pre>
</div>
</body>
</html>