[LLVMdev] Strong vs. default phi elimination and single-reg classes

Jakob Stoklund Olesen stoklund at 2pi.dk
Thu Jun 7 22:14:00 PDT 2012


On Jun 7, 2012, at 7:31 PM, Hal Finkel wrote:

> 112B    BB#1: derived from LLVM BB %for.body, ADDRESS TAKEN
>            Predecessors according to CFG: BB#0 BB#1
> %vreg12<def> = PHI %vreg13, <BB#1>, %vreg11, <BB#0>;CTRRC8:%vreg12,%vreg13,%vreg11
> %vreg13<def> = COPY %vreg12<kill>; CTRRC8:%vreg13,%vreg12
> %vreg13<def> = BDNZ8 %vreg13, <BB#1>; CTRRC8:%vreg13
> B <BB#2>
>            Successors according to CFG: BB#2 BB#1


Phi-elim works by inserting copies in the PHI predecessors before the first terminator. That isn't possible here since the first terminator defines the value of %vreg13 we want to copy. I think that phi-elim is not only causing spilling. It is miscompiling the code.

We simply don't support terminator instructions that define virtual registers ATM, it seems.

I can see how strong phi-elim would work in this case, but I don't think it can properly handle this in general. For example:

112B    BB#1: derived from LLVM BB %for.body, ADDRESS TAKEN
           Predecessors according to CFG: BB#0 BB#1
%vreg12<def> = PHI %vreg13, <BB#1>, %vreg11, <BB#0>;CTRRC8:%vreg12,%vreg13,%vreg11
%vreg99<def> = PHI %vreg13, <BB#1>, %vreg2, <BB#0>
%vreg13<def> = COPY %vreg12<kill>; CTRRC8:%vreg13,%vreg12
%vreg13<def> = BDNZ8 %vreg13, <BB#1>; CTRRC8:%vreg13
B <BB#2>
           Successors according to CFG: BB#2 BB#1

Since it is impossible to copy %vreg13 at the end of BB#1, it must be merged with %vreg12. The second PHI use means that it must also be merged with %vreg99, but that is not possible if %vreg11 and %vreg2 have different values leaving BB#0.

Instead of trying to solve this hairy problem, I think you would be better off without the CTRRC8 register class. Your problems with {Analyze,Insert,Remove}Branch should be fixable.

/jakob



More information about the llvm-dev mailing list