https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69195

--- Comment #10 from Vladimir Makarov <vmakarov at gcc dot gnu.org> ---
(In reply to Peter Bergner from comment #9)
> I think we have another bug in addition to the bug where we reuse a register
> that is already in use.  We have the rtl below which is used to initialize
> a[] before the call to foo:
> 
> (insn 5 39 40 2 (set (reg/f:DI 172)
>         (unspec:DI [
>                 (symbol_ref:DI ("*.LANCHOR0") [flags 0x182])
>                 (reg:DI 2 2)
>             ] UNSPEC_TOCREL)) bug.c:6 622 {*tocrefdi}
>      (expr_list:REG_EQUAL (symbol_ref:DI ("*.LANCHOR0") [flags 0x182])
>         (nil)))
> (insn 40 5 6 2 (set (reg:DI 3 3)
>         (plus:DI (reg/f:DI 113 sfp)
>             (const_int 96 [0x60]))) bug.c:9 81 {*adddi3}
>      (nil))
> (insn 6 40 8 2 (set (reg:DI 173)
>         (mem/u/c:DI (reg/f:DI 172) [0  S8 A32])) bug.c:6 540
> {*movdi_internal64}
>      (nil))
> (insn 8 6 10 2 (set (reg:DI 174)
>         (mem/u/c:DI (plus:DI (reg/f:DI 172)
>                 (const_int 8 [0x8])) [0  S8 A32])) bug.c:6 540
> {*movdi_internal64}
>      (nil))
> (insn 10 8 12 2 (set (reg:DI 175)
>         (mem/u/c:DI (plus:DI (reg/f:DI 172)
>                 (const_int 16 [0x10])) [0  S8 A32])) bug.c:6 540
> {*movdi_internal64}
>      (nil))
> 
> .....
> 
> (insn 7 29 9 2 (set (mem/c:DI (plus:DI (reg/f:DI 113 sfp)
>                 (const_int 96 [0x60])) [1 aD.2356+0 S8 A128])
>         (reg:DI 173)) bug.c:6 540 {*movdi_internal64}
>      (expr_list:REG_DEAD (reg:DI 173)
>         (nil)))
> (insn 9 7 11 2 (set (mem/c:DI (plus:DI (reg/f:DI 113 sfp)
>                 (const_int 104 [0x68])) [1 aD.2356+8 S8 A64])
>         (reg:DI 174)) bug.c:6 540 {*movdi_internal64}
>      (expr_list:REG_DEAD (reg:DI 174)
>         (nil)))
> (insn 11 9 13 2 (set (mem/c:DI (plus:DI (reg/f:DI 113 sfp)
>                 (const_int 112 [0x70])) [1 aD.2356+16 S8 A128])
>         (reg:DI 175)) bug.c:6 540 {*movdi_internal64}
>      (expr_list:REG_DEAD (reg:DI 175)
>         (nil)))
> 
> During allocation, we happily allocate volatiles to the above pseudos until
> run out...when trying to allocate pseudos 173 and 174.  Having run out of
> volatile regs, we allocate non-volatiles to pseudos 173 and 174.  However,
> in assign_hard_reg(), we think it's cheaper to use memory than to use a
> non-volatile, so we proactively spill 173 and 174:
> 
>       Popping a34(r174,l0)  -- (memory is more profitable 0 vs 7) spill!
>       Popping a35(r173,l0)  -- (memory is more profitable 0 vs 7) spill!
> 
> The above says the cost of using memory is zero, which doesn't seem correct
> to me.  In fact, all of the pseudos being used to initialize a[] have a zero
> memory cost, but since the volatile regs also have zero cost, we don't spill
> them.  It doesn't seem correct to me, that these pseudos have a zero memory
> cost.  I'll try to track down where that occurs.

Thanks, Peter.  The memory cost for 174 and 173 can not be zero as we will have
mem-mem move.  I think the problem is coming from ira-costs.c which was pretty
much adopted from the old RA.  I want to rewrite long ago this code as the
algorithm does not look right to me.  The algorithm ignores the fact that
operands should be from the same alternative.  Frequently, it takes best cost
for one operand from one alternative and best cost for another operand from
different alternative.

I'll try to find time to rewrite ira-costs.c for GCC7 and see the results.

Reply via email to