[LLVMdev] Undoing SSA and Phi instructions

Andrew Lenharth andrewl at lenharth.org
Mon Jan 24 10:45:51 PST 2011


On Sun, Jan 23, 2011 at 12:45 AM, Nick Lewycky <nicholas at mxc.ca> wrote:
> On 01/22/2011 10:30 PM, Surinder wrote:
>> Hi,
>>
>> I am emitting llvm bit code using
>>
>> llvm-gcc -c -emit-llvm -O0 -o test.bc test.c
>>
>> and then optimizing it with
>>
>> opt -O3 -print-module test.bc
>>
>> in order to obtain a dump of generated IR.
>>
>>
>> The resulting code has Phi nodes and is perhaps in SSA form.  I want
>> to undo the SSA form while retaining all the other optimizations.  Is
>> mem2reg the right optimization to be added after -O3, i.e.,
>>
>> opt -O3 -mem2reg -print-module test.bc
>>
>> will print the llvm in non-SSA form with no Phi nodes.
>
> I think you're looking for "opt -O3 -reg2mem -S test.bc" though I don't
> think it *guarantees* that it will remove all phi nodes. I don't think
> we have anything besides codegen that does.

reg2mem inserts allocas to store values going into phis.  It doesn't
exactly undo SSA, but it should remove all phis.

Andrew




More information about the llvm-dev mailing list