@@ -127,6 +127,7 @@ class SIFixSGPRCopies {
127
127
unsigned NextVGPRToSGPRCopyID = 0 ;
128
128
MapVector<unsigned , V2SCopyInfo> V2SCopies;
129
129
DenseMap<MachineInstr *, SetVector<unsigned >> SiblingPenalty;
130
+ DenseSet<MachineInstr *> PHISources;
130
131
131
132
public:
132
133
MachineRegisterInfo *MRI;
@@ -691,10 +692,8 @@ bool SIFixSGPRCopies::run(MachineFunction &MF) {
691
692
TII->get (AMDGPU::COPY), NewDst)
692
693
.addReg (MO.getReg ());
693
694
MO.setReg (NewDst);
694
-
695
- // FIXME: We are transitively revisiting users of this
696
- // instruction for every input.
697
695
analyzeVGPRToSGPRCopy (NewCopy);
696
+ PHISources.insert (NewCopy);
698
697
}
699
698
}
700
699
}
@@ -801,6 +800,7 @@ bool SIFixSGPRCopies::run(MachineFunction &MF) {
801
800
RegSequences.clear ();
802
801
PHINodes.clear ();
803
802
S2VCopies.clear ();
803
+ PHISources.clear ();
804
804
805
805
return true ;
806
806
}
@@ -926,13 +926,13 @@ bool SIFixSGPRCopies::lowerSpecialCase(MachineInstr &MI,
926
926
}
927
927
928
928
void SIFixSGPRCopies::analyzeVGPRToSGPRCopy (MachineInstr* MI) {
929
+ if (PHISources.contains (MI))
930
+ return ;
929
931
Register DstReg = MI->getOperand (0 ).getReg ();
930
932
const TargetRegisterClass *DstRC = MRI->getRegClass (DstReg);
931
933
932
934
V2SCopyInfo Info (getNextVGPRToSGPRCopyId (), MI,
933
935
TRI->getRegSizeInBits (*DstRC));
934
- V2SCopies[Info.ID ] = Info;
935
-
936
936
SmallVector<MachineInstr *, 8 > AnalysisWorklist;
937
937
// Needed because the SSA is not a tree but a graph and may have
938
938
// forks and joins. We should not then go same way twice.
@@ -971,16 +971,18 @@ void SIFixSGPRCopies::analyzeVGPRToSGPRCopy(MachineInstr* MI) {
971
971
}
972
972
} else if (Inst->getNumExplicitDefs () != 0 ) {
973
973
Register Reg = Inst->getOperand (0 ).getReg ();
974
- if (TRI->isSGPRReg (*MRI, Reg) && !TII->isVALU (*Inst))
974
+ if (Reg. isVirtual () && TRI->isSGPRReg (*MRI, Reg) && !TII->isVALU (*Inst)) {
975
975
for (auto &U : MRI->use_instructions (Reg))
976
976
Users.push_back (&U);
977
+ }
977
978
}
978
979
for (auto *U : Users) {
979
980
if (TII->isSALU (*U))
980
981
Info.SChain .insert (U);
981
982
AnalysisWorklist.push_back (U);
982
983
}
983
984
}
985
+ V2SCopies[Info.ID ] = Info;
984
986
}
985
987
986
988
// The main function that computes the VGPR to SGPR copy score
0 commit comments