<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Oct 30, 2016 at 4:08 PM, Bryant Wong <span dir="ltr"><<a href="mailto:3.14472+reviews.llvm.org@gmail.com" target="_blank">3.14472+reviews.llvm.org@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote"><span class="gmail-">On Sun, Oct 30, 2016 at 6:48 PM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">In particular:<br>"<div><span>I'm not so sure that it's sufficient. Suppose, for instance, that I wanted to insert a MemoryDef between 1 and 2 in the below AccessList:<div dir="ltr" class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><div class="gmail_extra gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><div class="gmail_quote gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><br class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><br class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><span class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029m_-6466548616601174784m_7998958474538251886gmail- gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">  0 = MemoryDef(liveOnEntry)<br class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">  1 = MemoryDef(0)<br class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"></span></div></div></div></div></span><div dir="ltr" class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><div class="gmail_extra gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><div class="gmail_quote gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><span><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">  2 = MemoryDef(1)<br class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">  3 = MemoryUse(1)<br class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><br class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"></div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">Invoking createMemoryAccess followed by RAUW of 1's uses with 4 would result in:</div></span><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">....</div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">"</div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><br></div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">Which is why this is not the way one does this, anywhere.</div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">If you wish to *replace* an existing access, the normal way is:<br><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><br></div></div></div></div></div></div></div></blockquote><div><br></div></span><div>As my original post indicates, I wish to insert an access, not replace anything. I've inserted a new memory instruction (memmove, memcpy, or memset), into the IR and wish to keep the MSSA tree synchronized.<br></div></div></div></div></blockquote><div><br></div><div>This, in general, is not possible right now. See below.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><span class="gmail-"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div dir="ltr" class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><div class="gmail_extra gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><div class="gmail_quote gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"></div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">           MemoryAccess *Def = OldMemAcc->getDefiningAccess()<wbr>;<br></div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">           NewMemAcc =</div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">               MSSA->createMemoryAccessAfter<wbr>(Repl, Def, OldMemAccess->getMemoryInst())<wbr>;</div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">           OldMemAcc->replaceAllUsesWith<wbr>(NewMemAcc);</div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><br></div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg">It doesn't make any sense to create a replacing access with the thing you are going to replace as the definition.</div><div class="gmail-m_-5163252058372285921m_-5437082179567694066gmail-m_-868984512930983029gmail_msg"><br></div></div></div></div></div></div></div></blockquote></span><div>Really, I don't want to replace anything. I'm interested in insertions. We have removals and replacements. So might insertion also be a valid concept with MSSA?<br></div></div></div></div></blockquote><div><br></div><div>Yes-  but you said "<span style="color:rgb(80,0,80)">Additionally, when inserting a new Def after an existing Def, there is currently no (clean) way to update the users of the old Def to use the new Def."</span></div></div><div class="gmail_quote"><br></div><div class="gmail_quote"><font color="#500050">But this is not a sensible thing to do, either in LLVM's SSA IR or MemorySSA, unless you a replacing an access.</font></div><div class="gmail_quote"><font color="#500050"><br></font></div><div class="gmail_quote"><font color="#500050">There can be no clean way to update the users because insert of stores in random places may cause new phi nodes to need to exist, etc[1]</font></div><div class="gmail_quote"><br></div><div class="gmail_quote"><font color="#500050">The existing API's are meant for the existing users, which do not insert completely new accesses, but instead, are moving or replacing existing accesses.</font></div><div class="gmail_quote"><font color="#500050">This is why they all say this in their docs:<br><br></font></div><div class="gmail_quote"><font color="#500050">"</font>This should be called when a memory instruction is created that is being used to replace an existing memory instruction."</div><div class="gmail_quote"><br></div><div class="gmail_quote"><font color="#500050">If you wish to insert brand new accesses, it needs a new API.</font></div><div class="gmail_quote"><font color="#500050"><br></font></div><div class="gmail_quote"><font color="#500050">I have a batch updater in my work queue that would do this for you, and take care of the easy cases easily, and make the hard cases possible. </font></div><div class="gmail_quote"><font color="#500050"><br>Until then, you have no real choice but to rebuild MemorySSA if you are inserting brand new memory instructions.</font></div><div class="gmail_quote"><br></div><br><div class="gmail_quote"><font color="#500050">[1] </font><span style="color:rgb(80,0,80)">The only cases you can handle easily are insertion in the middle of a block with stores above and below you, insertion at the end of a block with a store above you, insertion at the beginning of a block with a store below you.</span></div><div class="gmail_quote"><span style="color:rgb(80,0,80)"><br></span></div><div class="gmail_quote"><span style="color:rgb(80,0,80)">IMHO, it's not worth making APIs for each of these, each with verification, and it will expensive if you need MemorySSA correct at all times vs say "can update it once per iteration of my optimization"</span></div><div><span style="color:rgb(80,0,80)"><br></span></div><div class="gmail_quote"><br></div><div class="gmail_quote"><br></div></div></div>