[LLVMdev] PHI nodes in machine code

Vladimir Prus ghost at cs.msu.su
Fri Jul 9 03:03:01 PDT 2004


Misha Brukman wrote:

> LLVM Machine code is in SSA.

This explains quite a lot. I though it's possible to just reduce convert phis 
into copy instructions in predecessors -- all of which will have the same 
destination register.

> gets you two definitions of r.  So we have machine PHI nodes merge the
> two possible values into one for result of r.  These phis get removed
> after register allocation. So you would write code like:
>
>   if (a cond b) then
>     r1 = 1
>   else
>     r2 = 0
>
>   r = phi(r1, r2)

Ok, I see.

> > The reason I'm asking is that I try to support 64-bit comparison and I do
> > it by generating code like:
> >
> >           //    if high1 cond high2: goto operand0
> >           //    if high1 reverse_cond high2: goto operand1
>
> the second if should just be an unconditional branch to operand1:
> clearly, if (high1 cond high2) is false, the reverse condition is true.

Actually, you've found a bug: it should be swapped_cond, not reverse_cond.

> > but this means that operand0 and operand1 (the successor basic blocks)
> > suddenly get more predecessor than recorded in phi nodes, and
> > LiveVariables.cpp asserts on that.
>
> Naturally, as PHI nodes need to have as many entries as there are
> predecessors.

Ehmm... this means the 'SelectPHINodes' function I've copy-pasted from X86 
backend needs more work... gotta do that now.

- Volodya




More information about the llvm-dev mailing list