[LLVMdev] Alias Analysis: zero terminated strings

Carl-Philip Hänsch cphaensch at googlemail.com
Mon Sep 12 11:52:30 PDT 2011


2011/9/12 Nick Lewycky <nicholas at mxc.ca>

> LLVM could figure out that there is no "below the pointer" by noticing that
> the object came from malloc. I think the missing optimization here is a
> heap->stack transform.
>

That sounds good for me. I myself have to concentrate on the compiler, so I
dont have so much time to implement one of these things on my own in the
near future.

I note that in your example the exit is not post-dominated by free(). The
> transform could still fire by noticing that the pointer returned by malloc
> never escaped the function. (A more expensive check would be to see that it
> never escaped the function along the path that didn't call free. This is
> related to http://llvm.org/PR8908#c1 .)
>

But the pointer left the function. The pointer was sent to puts (not the
pointer itself, but a getelementptr of it). I think, the best way would be
to do a heap->stack when malloc and free are in the same control flow.


>
> One other thing we may want is a flag for "does not care about the pointer
> itself, only what the pointer points to". Currently, nothing tells LLVM that
> puts() doesn't check whether the pointer argument == &string_00000001, so we
> can't actually remove the copy. We could special-case that optimization into
> SimplifyLibCalls.
>
> Nick
>

But: A heap->stack optimization would not remove the mem copying. The
parameter flags to determine a zero extended string are still needed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110912/b47e8516/attachment.html>


More information about the llvm-dev mailing list