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

--- Comment #16 from Vineet Gupta <vineetg at gcc dot gnu.org> ---
After ECC hack, the issue persists.

Toggles (for cc1plus): -O2 -march=rv64gc_zfa -mabi=lp64d

%sfp is the spill because 

        -fno-schedule-insns             |      -fschedule-insns
                                        |
        li      t3,2                    |       li      t5,2
        li      t1,1                    |       li      t4,1
              ---xxx---                 |       sd      s10,8(sp)       # %sfp
.L2:                                    | .L2:
              ---xxx---                 |       ld      a5,8(sp)        # %sfp
        beq     s10,zero,.L9            |       beq     a5,zero,.L9             
        mv      a1,s6                   |       mv      a1,a6                   
        beq     s6,zero,.L7             |       beq     a6,zero,.L7             
        mulw    a2,s5,s6                |       mulw    a2,a0,a6                
        mv      a0,s5                   |       mv      s10,a0                  
        slli    a6,s5,3                 |       slli    s11,a0,3                
        slli    a3,a2,3                 |       slli    a3,a2,3                 
.L6:                                    | .L6:
        fcvt.d.w fa5,a2         # 56    |       fcvt.d.w fa5,a2         # 56
        add     a5,s4,a3        # 63    |       add     a4,s5,a3        # 63
        fsd     fa5,%lo(e)(t6)  # 57    |       add     a5,s6,a3        # 58
        fld     fa4,0(a5)       # 64    |       fsd     fa5,%lo(e)(t2)  # 57
        fld     fa5,%lo(o)(t5)          |       fld     fa3,0(a4)       # 64
        add     a5,s3,a3        # 58    |       fld     fa4,0(a5)       # 60
        fmul.d  fa4,fa4,fa5             |       fld     fa5,%lo(o)(t0)  
        fld     fa5,0(a5)       # 60    |       fcvt.l.d a4,fa3,rtz

schedule_insn () is called as follows:

;; 0--> b  0: i  56 r210=flt(r185#0) :alu: GR_REGS+0(0) FP_REGS+1(1):model 0
;; 1--> b  0: i  63 r215=r141+r183   :alu: GR_REGS+1(1) FP_REGS+0(0)  
;; 2--> b  0: i  58 r211=r138+r183   :alu:@GR_REGS+1(1)@FP_REGS+0(0)


The prints between insn 63 and insn 58 show the issue

;;  point uid  prio delay  class : del   ECC-gpr          del  ECC-fpr   
ECC-tot
;;|   1   57 |   12  +2 | GR_REGS:[0 base cost 0] FP_REGS:[-1 base cost 0]ECC 0
;;|  10   61 |    4  +1 | GR_REGS:[0 base cost 0] FP_REGS:[1 base cost 0] ECC 0
;;|   8   58 |    5  +1 | GR_REGS:[1 base cost 0] FP_REGS:[0 base cost 0] ECC 0
;; --1-- RFS_PRESSURE_DELAY winner 58 looser 57
;; --2-- RFS_PRESSURE_DELAY winner 58 looser 57

1, insn 57 delta is -1 (reduces pressure), while insn 58 delta is 1 (increases
pressure) yet ECC is 0 for both, meaning for pressure considerations they are
treated the same. This ECC "dilution" happens in model_spill_cost ().

2. insn 57 is a store (so prio 2) while insn 58 is an add (so prio 1).

rank_for_schedule (): RFS_PRESSURE_DELAY chooses lower of (ECC + insn_delay)
and thus picks 58 over 57 causing the issue.

Reply via email to