@@ -4758,30 +4758,47 @@ MachineInstr *SIInstrInfo::buildShrunkInst(MachineInstr &MI,
4758
4758
return Inst32;
4759
4759
}
4760
4760
4761
+ bool SIInstrInfo::physRegUsesConstantBus (const MachineOperand &RegOp) const {
4762
+ // Null is free
4763
+ Register Reg = RegOp.getReg ();
4764
+ if (Reg == AMDGPU::SGPR_NULL || Reg == AMDGPU::SGPR_NULL64)
4765
+ return false ;
4766
+
4767
+ // SGPRs use the constant bus
4768
+
4769
+ // FIXME: implicit registers that are not part of the MCInstrDesc's implicit
4770
+ // physical register operands should also count.
4771
+ if (RegOp.isImplicit ())
4772
+ return Reg == AMDGPU::VCC || Reg == AMDGPU::VCC_LO || Reg == AMDGPU::M0;
4773
+
4774
+ // Normal exec read does not count.
4775
+ if ((Reg == AMDGPU::EXEC || Reg == AMDGPU::EXEC_LO) && RegOp.isImplicit ())
4776
+ return false ;
4777
+
4778
+ // SGPRs use the constant bus
4779
+ return AMDGPU::SReg_32RegClass.contains (Reg) ||
4780
+ AMDGPU::SReg_64RegClass.contains (Reg);
4781
+ }
4782
+
4783
+ bool SIInstrInfo::regUsesConstantBus (const MachineOperand &RegOp,
4784
+ const MachineRegisterInfo &MRI) const {
4785
+ Register Reg = RegOp.getReg ();
4786
+ if (Reg.isVirtual ())
4787
+ return RI.isSGPRClass (MRI.getRegClass (Reg));
4788
+ return physRegUsesConstantBus (RegOp);
4789
+ }
4790
+
4761
4791
bool SIInstrInfo::usesConstantBus (const MachineRegisterInfo &MRI,
4762
4792
const MachineOperand &MO,
4763
4793
const MCOperandInfo &OpInfo) const {
4764
4794
// Literal constants use the constant bus.
4765
4795
if (!MO.isReg ())
4766
4796
return !isInlineConstant (MO, OpInfo);
4767
4797
4768
- if (!MO.isUse ())
4769
- return false ;
4770
-
4771
- if (MO.getReg ().isVirtual ())
4772
- return RI.isSGPRClass (MRI.getRegClass (MO.getReg ()));
4773
-
4774
- // Null is free
4775
- if (MO.getReg () == AMDGPU::SGPR_NULL || MO.getReg () == AMDGPU::SGPR_NULL64)
4776
- return false ;
4777
-
4778
- // SGPRs use the constant bus
4779
- if (MO.isImplicit ()) {
4780
- return MO.getReg () == AMDGPU::M0 || MO.getReg () == AMDGPU::VCC ||
4781
- MO.getReg () == AMDGPU::VCC_LO;
4782
- }
4783
- return AMDGPU::SReg_32RegClass.contains (MO.getReg ()) ||
4784
- AMDGPU::SReg_64RegClass.contains (MO.getReg ());
4798
+ Register Reg = MO.getReg ();
4799
+ if (Reg.isVirtual ())
4800
+ return RI.isSGPRClass (MRI.getRegClass (Reg));
4801
+ return physRegUsesConstantBus (MO);
4785
4802
}
4786
4803
4787
4804
static Register findImplicitSGPRRead (const MachineInstr &MI) {
@@ -6250,13 +6267,12 @@ bool SIInstrInfo::isOperandLegal(const MachineInstr &MI, unsigned OpIdx,
6250
6267
continue ;
6251
6268
const MachineOperand &Op = MI.getOperand (i);
6252
6269
if (Op.isReg ()) {
6253
- RegSubRegPair SGPR (Op.getReg (), Op.getSubReg ());
6254
- if (!SGPRsUsed.count (SGPR) &&
6255
- // FIXME: This can access off the end of the operands() array.
6256
- usesConstantBus (MRI, Op, InstDesc.operands ().begin ()[i])) {
6257
- if (--ConstantBusLimit <= 0 )
6258
- return false ;
6259
- SGPRsUsed.insert (SGPR);
6270
+ if (Op.isUse ()) {
6271
+ RegSubRegPair SGPR (Op.getReg (), Op.getSubReg ());
6272
+ if (regUsesConstantBus (Op, MRI) && SGPRsUsed.insert (SGPR).second ) {
6273
+ if (--ConstantBusLimit <= 0 )
6274
+ return false ;
6275
+ }
6260
6276
}
6261
6277
} else if (AMDGPU::isSISrcOperand (InstDesc, i) &&
6262
6278
!isInlineConstant (Op, InstDesc.operands ()[i])) {
0 commit comments