<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:"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: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;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.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">Thanks Alina. This is exactly what I wanted to do. But what would “MemoryAccess associated with Bar” be? Notice that in the original code Bar (before I rewrite Bar to BarP), Bar didn’t read any memory. It was passed %foo (target of load)
 by value. Do I have to create an artificial memory access instruction before calling MemorySSA? Am I missing something here?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>From:</b> Alina Sbirlea <alina.sbirlea@gmail.com> <br>
<b>Sent:</b> Monday, November 8, 2021 1:42 PM<br>
<b>To:</b> Riyaz Puthiyapurayil <riyaz@synopsys.com><br>
<b>Cc:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] Memory SSA for this problem?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hi Riyaz,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">With MemorySSA you could query clobbering on the G at the Bar callsite using the API: `MemoryAccess *getClobberingMemoryAccess(MemoryAccess *MA, const MemoryLocation &Loc)`, where MA is "the MemoryAccess associated with Bar"->getDefiningAccess()
 and Loc is the memorylocation defining G.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">If the returned clobber access dominates the load, then there are no additional clobbering accesses between the load and the call.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Alina<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Mon, Nov 8, 2021 at 12:19 PM Riyaz Puthiyapurayil via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<div>
<p class="MsoNormal"><span style="color:#212121">I am trying to figure what is the best way to do the following in LLVM. Specifically wonder if MemorySSA can be used here…any pointers to existing code that does something similar will be useful.</span>
<o:p></o:p></p>
<div>
<p class="MsoNormal"><span style="color:#212121"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121">Consider this code:<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121">%foo = load i256, i256* @G<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121">…<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121">possible uses of %foo<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121">…<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121">%bar = call i32 @Bar(i256 %foo)<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121">Now if I know that there are no writes to @G between the load and the call, I would like to convert the call to @Bar to a call to @BarP which accepts a pointer to i256:<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121;background:white">%bar = call i32 @BarP(i256* @G)</span><span style="color:#212121"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121;background:white">How can I check if there are no clobbers of @G between the load and the call? @G does not alias with any other memory but there can be writes to @G between the above load and the call and if
 so, the safe thing to do is:</span><span style="color:#212121"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121;background:white">%foop = alloca i256</span><span style="color:#212121"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121;background:white">store i256 %foo, i256* %foop</span><span style="color:#212121"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121">…<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121;background:white">%bar = call i32 @BarP(i256* %foop)</span><span style="color:#212121"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121;background:white">Note that I am trying to avoid creating a copy of %foo on the stack when possible.</span><span style="color:#212121"><o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121"><o:p> </o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#212121;background:white">The goal here is to keep the wide integer in SSA form (there is performance benefit in doing this) but when I have to pass the wide vector to a library function, I want to pass its address. Since
 @G may be a copy of %foo, I would like to pass @G instead of creating a temp with alloca whenever it is safe to do so. The question is how to check if @G still has the same value as %foo.</span><span style="color:#212121"><o:p></o:p></span></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
</div>
<div id="gmail-m_-3585682335794567144ms-outlook-mobile-signature">
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="background:white"><span style="color:#212121">/Riyaz<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
<p class="MsoNormal">_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://urldefense.com/v3/__https:/lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev__;!!A4F2R9G_pg!IiUsjHksGaaFO5c4V01C4QL4ID-PqtsFYsYkU5Cq60T2sVw0wEw_MR75IaZW6i2n0n8VNxNqwL1o$" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</body>
</html>