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

--- Comment #12 from Vineet Gupta <vineetg at gcc dot gnu.org> ---
Interim update as I unpack sched1.

There's the "main" scheduling algorithm which involves 4 queues and an FSM but
can be ignored for this update.

There's "model" schedule which is the pressure sensitive sub-algorithm and can
be considered separate from the main one.

Note that per comments in src code:
   "We do not apply this model schedule to the rtx stream.  We simply record
   it in model_schedule.  We also compute the maximum pressure,
   MP, that was seen during this schedule."

@curr_reg_pressure[GR_REGS] is initially setup with df live info.

schedule_block 
  model_start_schedule
   initiate_reg_pressure_info (df_get_live_in (bb))
    mark_regno_birth_or_death (curr_reg_live, curr_reg_pressure, j,
birth_p=true);

model_worklist is seeded with insns with dep=0 which is then iteratively
processed with deps SD_LIST_HARD_BACK insns.

     while (model_worklist)
       model_choose_insn ()

           insn = model_worklist
           for (;;)
           {
                if (model_classify_pressure(insn) < 0)
                    break;
                insn = insn->next
           }
           update_register_pressure(insn)

insn 35 is starting point of investigation, a load insn which creates pseudo
r170 used by the later insns involved in spill.

;;      +--- worklist:
;;      +---   35 [2, 7, 2, 10]
...
;;      |  14   35 |    2    7    2   10 | r170#0=[r242+low(`u')]
GR_REGS:[26,+1]
                                                                          ^^^^
Note that the prints are slightly misleading as it prints prev pressure: +N
shows  the pressure increment due to this insn

  model_record_pressures (insn);           <-- prints curr_reg_pressure[]
  update_register_pressure (insn->insn);   <-- updates curr_reg_pressure[] due
to insn

Looking back at comment 10, the insns we want to really track are

  ;;    |   46 |    7 | r180=zxt(r170,0x10,0x10)  
  ;;    |   54 |    6 | [r230+low(const(`_Z1sv'+0x2))]=r180#0
  ;;    |   55 |    7 | r188=r170 0>>0x20             
  ;;    |   64 |    6 | [r230+low(const(`_Z1sv'+0x4))]=r188#0

(the above is pre-schedule/ideal, but what we see in the end is 46 and 55 are
next to each other, needing seperate hard regs for r180 and r188)

Anyhow, model schedule is recording that we do hit 28 which one more than the
max reg pressure 27 for GR_REGS.

;; |  16   46 | 2 7 3 7 | r180=zxt(r170,0x10,0x10)              
GR_REGS:[27,+1]
;; |  17   54 | 2 7 4 6 | [r230+low(const(`_Z1sv'+0x2))]=r180#0 
GR_REGS:[28,-1]
;; |  18   55 | 2 7 3 7 | r188=r170 0>>0x20                     
GR_REGS:[27,+1]
;; |  19   64 | 2 7 4 6 | [r230+low(const(`_Z1sv'+0x4))]=r188#0 
GR_REGS:[28,-1]
..
;; Pressure summary: GR_REGS:28 FP_REGS:1
                            ^^^^

As a hack I did switch the recording/updating (to record the right pressure
point)

  update_register_pressure (insn->insn);
  model_record_pressures (insn);     

That does move insn stream around, but still doesn't separate insn 46 and 55
enough to not allocate new hard reg for latter.

In summary the model pressure calculation seems fine, need to see why main algo
is not switching things around.

Reply via email to