On Mon, Apr 24, 2006 at 05:59:30PM +0200, Frank Riese wrote:

> However, I'm still having problems with reloading/register spilling:
> 
> -------------------------------------------------------------------------------------
> /usr/local/src/gcc/objdir/./gcc/xgcc -B/usr/local/src/gcc/objdir/./gcc/ 
> -B/usr/local/zykluno-none/bin/ -B/usr/local/zykluno-none/lib/ 
> -isystem /usr/local/zykluno-none/include -isystem 
> /usr/local/zykluno-none/sys-include 
> -O2  -O2 -g -O2   -DIN_GCC -DCROSS_COMPILE   -W -Wall -Wwrite-strings 
> -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  
> -isystem ./include   -g  -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED 
> -Dinhibit_libc -I. -I. -I../../gcc -I../../gcc/. -I../../gcc/../include 
> -I../../gcc/../libcpp/include  -I../../gcc/../libdecnumber 
> -I../libdecnumber -DL_muldi3 -c ../../gcc/libgcc2.c -o libgcc/./_muldi3.o
> 
> cc1: warning: target system does not support debug output
> cc1: warning: target system does not support debug output
> ../../gcc/libgcc2.c: In function '__muldi3':
> ../../gcc/libgcc2.c:520: error: unable to find a register to spill in 
> class 'GENERAL_REGS'
> ../../gcc/libgcc2.c:520: error: this is the insn:
> (insn 436 435 442 6 ../../gcc/libgcc2.c:520 (set (reg/f:HI 5 R[5] [+6 ])
>         (mem/s/c:HI (reg/f:HI 198) [0+2 S2 A16])) 17 {movhi} (nil)
>     (expr_list:REG_DEAD (reg/f:HI 198)
>         (nil)))
> ../../gcc/libgcc2.c:520: internal compiler error: in spill_failure, at 
> reload1.c:1912
> -------------------------------------------------------------------------------------
> 
> I looked at the offending lines in libgcc2.c and it seems to me that the only 
> problem with that code is that the compiler needs a lot of registers for the 
> structures and members and thus runs out of registers.
> 
> I followed your suggestion and dumped the *.greg of libgcc2.c 
> (-fdump-rtl-greg-details):
> 
> -------------------------------------------------------------------------------------
> [...]
> Using reg 2 for reload 0
> Using reg 3 for reload 1
> Spilling for insn 425.
> Using reg 2 for reload 0
> Using reg 3 for reload 1
> Spilling for insn 426.
> Using reg 2 for reload 0
> Using reg 3 for reload 1
> Spilling for insn 433.
> Using reg 3 for reload 0
> Spilling for insn 434.
> Using reg 4 for reload 0
> Spilling for insn 435.
> Using reg 5 for reload 0
> Spilling for insn 436.
> reload failure for reload 0
> 
> Reloads for insn # 436
> Reload 0: reload_in (HI) = (reg/f:HI 198)
>         GENERAL_REGS, RELOAD_FOR_OPERAND_ADDRESS (opnum = 1)
>         reload_in_reg: (reg/f:HI 198)
> -------------------------------------------------------------------------------------

I'm guessing that reg 198 is on the stack somewhere. I would have thought
that there would be more than one reload for insn 436. I think reload
should emit these insns before insn 436 (using reg 5 itself as a temporary):

(set (reg:HI 5) (const_int offset_of_reg_198))          ; movhi/4
(set (reg:HI 5) (plus:HI (reg:HI 6 BP) (reg:HI 5)))     ; addhi3/1

And then insn 436 itself:

(set (reg:HI 5) (mem:HI (reg:HI 5)))                    ; movhi/2

Somehow reload fails to realize that the target register can be used to
build the address. It needs further analysis. Notice how this fails for
insns 433, 434 and 435 too, only they had a spare register that reload could
fritter away.

> If that helps, here are the last few instructions before the compiler fails:
> 
> -------------------------------------------------------------------------------------
> [...]
> (note 430 426 431 6 NOTE_INSN_FUNCTION_END)
> (note 431 430 433 6 ("../../gcc/libgcc2.c") 520)
> (insn 433 431 434 6 ../../gcc/libgcc2.c:520 (set (reg:HI 2 R[2] [ <result> ])
>         (subreg:HI (reg:DI 30 [ <result> ]) 0)) 17 {movhi} 
> (insn_list:REG_DEP_TRUE 426 (nil))
>     (nil))
> (insn 434 433 435 6 ../../gcc/libgcc2.c:520 (set (reg:HI 3 R[3] [+2 ])
>         (subreg:HI (reg:DI 30 [ <result> ]) 2)) 17 {movhi} (nil)
>     (nil))
> (insn 435 434 436 6 ../../gcc/libgcc2.c:520 (set (reg:HI 4 R[4] [+4 ])
>         (subreg:HI (reg:DI 30 [ <result> ]) 4)) 17 {movhi} (nil)
>     (expr_list:REG_DEAD (reg:DI 30 [ <result> ])
>         (nil)))
> (insn 436 435 442 6 ../../gcc/libgcc2.c:520 (set (reg/f:HI 5 R[5] [+6 ])
>         (mem/s/c:HI (reg/f:HI 198) [0+2 S2 A16])) 17 {movhi} (nil)
>     (expr_list:REG_DEAD (reg/f:HI 198)
>         (nil)))
> (insn 442 436 0 6 ../../gcc/libgcc2.c:520 (use (reg/i:DI 2 R[2])) -1 
> (insn_list:REG_DEP_TRUE 433 (nil))
>     (nil))
> ;; End of basic block 6, registers live:
>  2 [R[2]] 3 [R[3]] 4 [R[4]] 5 [R[5]] 6 [BP] 7 [SP]
> -------------------------------------------------------------------------------------

Oh, interesting, you're trying to return a 64-bit result in 4 16-bit
registers. While I think it ought to work, you might at least be able to get
your compile going by telling GCC to return the value in memory instead.
I don't recall exactly how this is done - my i8086 backend returns anything
larger than 32 bits in memory - but see the sections "How Scalar Function
Values Are Returned" and "How Large Values Are Returned".

-- 
Rask Ingemann Lambertsen

Reply via email to