[LLVMdev] dead store elimination with external functions

Peng Cheng
Wed, 12 Sep 2012 17:57:30 -0000

Maybe I should say b2 should be eliminated.

Since b1 and b2 are same type and b1 is not used any more after the
function call, b2 can be replaced by b1.  This will save an alloca.

In my test, if the function is not external, b1 is eliminated.  But with
external function, it did not.

Since the ir is generated, I cannot manually update b2 with b1.  I would
like the optim pass do it.


On Wednesday, September 12, 2012, Duncan Sands wrote:

> Hi Peng,
>
>  Here is an llvm ir of a module.  It seems that "b1" should be
eliminated
>> by dead
>> store elimination.  But it did not.
>>
>> Could anyone explain why and how "b1" can be eliminated?
>>
>> Thanks,
>> -Peng
>>
>> %0 = type { [3 x [1 x i32]] }
>>
>> declare %0 @external_fcn3(i32, i32, i32, i32, [3 x [1 x i32]]*)
>>
>> define i32 @f3(i32 %a) readnone {
>> entry:
>>    %b1 = alloca [3 x [1 x i32]]
>>    %b2 = alloca [3 x [1 x i32]]
>>    %c = alloca %0
>>    %0 = getelementptr [3 x [1 x i32]]* %b1, i32 0, i32 0, i32 0
>>    store i32 0, i32* %0
>>    %1 = getelementptr [3 x [1 x i32]]* %b1, i32 0, i32 1, i32 0
>>    store i32 1, i32* %1
>>    %2 = getelementptr [3 x [1 x i32]]* %b1, i32 0, i32 2, i32 0
>>    store i32 2, i32* %2
>>    %3 = call %0 @external_fcn3(i32 100, i32 200, i32 %a, i32 200, [3 x
[1
>> x
>> i32]]* %b1)
>>
>
> here %b1 is passed to external_fcn3, thus %b1 can't be eliminated.
>
> Ciao, Duncan.
> ______________________________**_________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>
http://lists.cs.uiuc.edu/**mailman/listinfo/llvmdev<http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20120912/139eb341/attachment.html>