<div dir="ltr">Hi Riyaz,<div><br></div><div>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.</div><div>If the returned clobber access dominates the load, then there are no additional clobbering accesses between the load and the call.</div><div><br></div><div>Alina</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">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:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div dir="ltr">
<div></div>
<div>
<div><span style="color:rgb(33,33,33)">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></span></span>
<div dir="ltr" style="color:rgb(33,33,33)"><br>
</div>
<div dir="ltr" style="color:rgb(33,33,33)">Consider this code:</div>
<div dir="ltr" style="color:rgb(33,33,33)"><br>
</div>
<div dir="ltr" style="color:rgb(33,33,33)">%foo = load i256, i256* @G</div>
<div dir="ltr" style="color:rgb(33,33,33)">…</div>
<div dir="ltr" style="color:rgb(33,33,33)">possible uses of %foo</div>
<div dir="ltr" style="color:rgb(33,33,33)">…</div>
<div dir="ltr" style="color:rgb(33,33,33)">%bar = call i32 @Bar(i256 %foo)</div>
<div dir="ltr" style="color:rgb(33,33,33)"><br>
</div>
<div dir="ltr" style="color:rgb(33,33,33)">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:</div>
<div dir="ltr" style="color:rgb(33,33,33)"><br>
</div>
<div dir="ltr" style="color:rgb(33,33,33)"><span style="background-color:rgb(255,255,255);display:inline">%bar = call i32 @BarP(i256* @G)</span><br>
</div>
<div dir="ltr" style="color:rgb(33,33,33)"><span style="background-color:rgb(255,255,255);display:inline"><br>
</span></div>
<div dir="ltr" style="color:rgb(33,33,33)"><span style="background-color:rgb(255,255,255);display:inline">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></span></div>
<div dir="ltr" style="color:rgb(33,33,33)"><span style="background-color:rgb(255,255,255);display:inline"><br>
</span></div>
<div dir="ltr" style="color:rgb(33,33,33)"><span style="background-color:rgb(255,255,255);display:inline">%foop = alloca i256</span></div>
<div dir="ltr" style="color:rgb(33,33,33)"><span style="background-color:rgb(255,255,255);display:inline">store i256 %foo, i256* %foop</span></div>
<div dir="ltr" style="color:rgb(33,33,33)">…</div>
<div dir="ltr" style="color:rgb(33,33,33)"><span style="background-color:rgb(255,255,255);display:inline"><span style="background-color:rgb(255,255,255);display:inline">%bar<span> </span><span style="background-color:rgb(255,255,255);display:inline">=
call i32 @BarP(i256* %foop)</span></span><br>
</span></div>
<div dir="ltr" style="color:rgb(33,33,33)"><span style="background-color:rgb(255,255,255);display:inline"><br>
</span></div>
<div dir="ltr" style="color:rgb(33,33,33)"><span style="background-color:rgb(255,255,255);display:inline">Note that I am trying to avoid creating a copy of %foo on the stack when possible.</span></div>
<div dir="ltr" style="color:rgb(33,33,33)"><span style="background-color:rgb(255,255,255);display:inline"><br>
</span></div>
<div dir="ltr" style="color:rgb(33,33,33)"><span style="background-color:rgb(255,255,255);display:inline">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></span></div>
<br>
<br>
</div>
<div id="gmail-m_-3585682335794567144ms-outlook-mobile-signature">
<div><br>
</div>
<div style="color:rgb(33,33,33);background-color:rgb(255,255,255)" dir="auto">
/Riyaz</div>
</div>
</div>
</div>
</div>
_______________________________________________<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://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>