<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 8, 2014 at 3:10 PM, Evan Cheng <span dir="ltr"><<a href="mailto:evan.cheng@apple.com" target="_blank">evan.cheng@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":g7o" style="overflow:hidden">Attached is a patch (and the test case) that fix a SROA edge case. An alloca can be added back to the worklist to be revisited during rewrite of a MemTransferInst. If the alloca is added to the "promotable" queue and then added again when it's revisited, mem2reg will crash. The patch simply prevents promotion of an alloca that is scheduled to be revisited.<br>
</div></blockquote><div><br></div><div>Ow! Good catch!</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":g7o" style="overflow:hidden">
<br>
The patch isn't ideal. It's following the AllocaSliceRewriter::isUsedByRewrittenSpeculatableInstructions() example by caching a boolean state. But it's correct and as clean a patch as I can come up with.</div>
</blockquote></div><div class="gmail_extra"><br></div>Hmm, yea. I hated isUsedByRewrittenSpeculatableInstructions when it went in, but I still don't have a better solution. However, there might be a better solution here. The speculation case is particularly hard because the place where this is being "used" can't easily be updated. But this case might be easier. Could you instead of this, either:</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">1) Check for promotability prior to adding the alloca back to the worklist (I doubt this would work), or</div><div class="gmail_extra">2) Remove the alloca from the worklist (or skip it when popping it off of the worklist) when it has already be slated for promotion?</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">I'm hopeful that we could do #2, but not confident. I feel like we really should go ahead and promote in this case rather than carrying on and re-processing the alloca *again* when it is already in a good state.</div>
<div class="gmail_extra"><br></div></div>