[LLVMdev] Kinda noob questions

John McCall rjmccall at apple.com
Mon Mar 14 18:23:11 PDT 2011


On Mar 14, 2011, at 5:56 PM, John Criswell wrote:
> On 3/14/11 7:52 PM, Judison wrote:
>> 
>> 2) does the LLVM optimizes this:
>> 
>> ; this code (arg -> var) is very similar to what gcc generates
>> define void @foo(i32 %arg0) {
>> entry:
>>     %var0 = alloca i32
>>     store i32 %arg0, i32* var0
>>     ...
>>     %x = load i32* %var0
>>     ....
>>     ; never more stores to %var0 or pass it to any function
>> }
>> 
>> to something like:
>> 
>> define void @foo(i32 arg0) {
>> entry:
>>     ; no alloca
>>     ....
>>     %x = %arg0
>>    ....
>> }
>> 
>> does it???
> 
> I suspect that mem2reg plus a few additional optimizations will do this for you.

mem2reg is sufficient.  There's also no limit on the number of loads
and stores you can do without disturbing the optimization;  just
don't do anything too opaque with the address.

John.



More information about the llvm-dev mailing list