Patch attached which addresses most of your comments, and also is much cleaner. Lots of small inefficiencies are removed, etc. It also uses the common routines that you suggested adding to LLVM and now are in the core Value api.<br>

<br>There is one issue which, after discussion on IRC, I think we both agreed wasn't an actual problem:<br><br><div class="gmail_quote">On Thu, Mar 8, 2012 at 10:41 PM, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>+      if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(I)) {</div>
+        // If the GEP has variable indices, we won't be able to do much<br>
with it.<br>
+        if (!GEP->hasAllConstantIndices())<br>
+          continue;<br>
<br>
inbounds should be sufficient as well.<br>
<br>
Also, this function should handle SelectInst. Something like:<br></blockquote><div><br></div><div>Chatted about this and i clarified why we actually need constant indices. The goal is to detect comparisons and subtracts which produce actual constants after inlining, and that prevents looking through inbounds GEPs or selects. We could get extra clever w/ select and a few other instructions, but it doesn't seem terribly important.</div>

</div>