[LLVMdev] Linearscan allocator bug?

Chris Lattner sabre at nondot.org
Tue Jun 22 22:35:02 PDT 2004


On Tue, 22 Jun 2004, Vladimir Prus wrote:

> First, I attach two files -- LLVM asm and the asm for my target. The problem
> with assembler is: on line 171 it uses register gr2, which is copied from gr6
> above, on line 161. The only predecessor of this basic block is jump on line
> 90. The problem is that gr6 is not initialized in the interval from the
> function entry till the jump.

Okay, I see the problem.  You need to tell the compiler that the
conditional branches are terminators.  You're getting code that looks like
this:

<LBB7> // // shortcirc_next.0.selectcont.selectcont
        gr1 = gr1;
        gr1 = gr1;
        gr5 = 0;
        gr2 - gr5;
        if <>0 goto LBB11;
*       gr2 = gr4;
*       gr5 = gr1;
*       gr6 = gr4;
*       gr1 = gr1;
        goto LBB8;

I'm guessing that those copies are inserted by the register allocator, and
in particular, that is probably where gr6 is supposed to get it's value.
If you set the isTerminator flag on your 'if <>0 goto LBB11;' things will
probably magically start working for you, as the copies will be inserted
BEFORE the branch instead of after it.

Also, if you haven't already, you might want to teach TargetInstrInfo
that '=' is a move instruction (implement isMoveInstr), so instructinos
like 'gr1 = gr1' will go away and you'll get coallescing.  :)

-Chris

> I also attach the debug dumps from my backend.
>
> The basic block in question is shortcirc_done.1 (line 198 in the log). It
> starts with:
>
>     %reg1060 = phi %reg1032, mbb<shortcirc_next.0.selectcont.selectcont,
>
> The predecessor is at line 155 and the register 1032 is assigned a value on
> line 140 (in shortcirc_next.0.selectcont):
>
>     %reg1032 = move %reg103
>
> After register allocation the code in shortcirc_done.1 is (line 334):
>
>     %gr2 = move %gr6
>
> the predecessor in at line 285 and the code in shortcirc_next.0.selectcont is
> (line 268)
>
>     %gr4 = move %gr2
>
> while I'd expect destination register should be gr6.
>
> In fact, gr6 is first used here (line 289):
>
>         if <>0 goto %disp(label shortcirc_done.1)
> 	%gr2 = move %gr4
> 	%gr5 = move %gr1
> 	%gr6 = move %gr4
> 	%gr1 = move %gr1
>
> So, it's possible that jump goes to shortcirc_done.1 which then uses gr6 and
> gets back results.
>
> Any ideas?
>
> - Volodya
>

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/





More information about the llvm-dev mailing list