<div dir="ltr">Random thought: what if both operands of an add come from pointers? e.g. in a naive coding of binary search as p = (p1+p2)/2<div><br></div><div>Is that simply illegal in LLVM? Or course it is in most languages including C without a lot of casts, though once you compile it that's what the machine instructions will be. And silently (but usually harmlessly) overflow if you're in the top half of the address space...</div><div><br></div><div>So of course you *should* write it as p = p1 + (p2-p1)/2, which type checks, doesn't need casts, doesn't overflow, and produces an add of a pointer and an integer. But does all code a compiler encounters actually do this? </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 27, 2014 at 2:50 PM, Ruiling Song <span dir="ltr"><<a href="mailto:ruiling.song83@gmail.com" target="_blank">ruiling.song83@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class=""><br><div class="gmail_extra">To find the source of the pointer for the LoadInst, you'll need to
climb up the def-use chain. In the case of an add instruction, you
will have to search back through both operands to figure out which
one originates from a pointer. You will also have to handle
phi-nodes, so you'll probably need a list of processed phi-nodes to
ensure that you don't iterate indefinitely.<br><br></div></span><div class="gmail_extra">I tried the above idea, but I find it is easy find out whether a operand comes from a pointer. But for the other operand, which comes from a integer, it is hard to determine it does not come from a pointer, as integer may come from various kinds of instructions, the stop-condition to prevent further search is not obvious. As for the two operands of 'Add', i don't know which comes from pointer, obviously I have to go through both of them. I am not sure whether I understand your idea fully.<br><br></div><span class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><div bgcolor="#FFFFFF" text="#000000">
<br>
The only other way to do it is find all the definitions that you
consider to be pointer "origins" (e.g., function arguments, the
results of load instructions, etc.) and iterate through their uses
until you find the load instruction that uses the pointer (in this
case, %153). In other words, instead of starting at a use and
searching for the definition, you start at all possible definitions
and look for the use. If you're searching for a lot of pointers,
this may end up being more efficient as you won't be traversing the
same definitions over and over again.<br>
<br>
In short, you're attacking the problem in the right way, and I don't
think there's really any better way of doing it.<br>
<br>
Regards,<br>
<br>
John Criswell<br>
<br>
<br></div></blockquote></div></div></span></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>