Skip to content

Commit cff1a2e

Browse files
SANTANU DASKrzysztof Parzyszek
SANTANU DAS
authored and
Krzysztof Parzyszek
committed
[Hexagon] HVX .new store uses different resources
When checking resources in the post RA scheduler, see if a .new vector store should be used instead of a regular vector store. It may not be possible to schedule a regular vector store, but it may be possible to schedule a .new version. If the correct one isn't used, then the post RA scheduler may not generate the best schedule.
1 parent 502e5df commit cff1a2e

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

llvm/lib/Target/Hexagon/HexagonHazardRecognizer.cpp

+16-11
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ HexagonHazardRecognizer::getHazardType(SUnit *SU, int stalls) {
4444
if (!Resources->canReserveResources(*MI)) {
4545
LLVM_DEBUG(dbgs() << "*** Hazard in cycle " << PacketNum << ", " << *MI);
4646
HazardType RetVal = Hazard;
47-
if (TII->mayBeNewStore(*MI)) {
48-
// Make sure the register to be stored is defined by an instruction in the
49-
// packet.
50-
MachineOperand &MO = MI->getOperand(MI->getNumOperands() - 1);
51-
if (!MO.isReg() || RegDefs.count(MO.getReg()) == 0)
52-
return Hazard;
47+
if (isNewStore(*MI)) {
5348
// The .new store version uses different resources so check if it
5449
// causes a hazard.
5550
MachineFunction *MF = MI->getParent()->getParent();
@@ -105,6 +100,15 @@ bool HexagonHazardRecognizer::ShouldPreferAnother(SUnit *SU) {
105100
return UsesDotCur && ((SU == UsesDotCur) ^ (DotCurPNum == (int)PacketNum));
106101
}
107102

103+
/// Return true if the instruction would be converted to a new value store when
104+
/// packetized.
105+
bool HexagonHazardRecognizer::isNewStore(MachineInstr &MI) {
106+
if (!TII->mayBeNewStore(MI))
107+
return false;
108+
MachineOperand &MO = MI.getOperand(MI.getNumOperands() - 1);
109+
return (MO.isReg() && RegDefs.count(MO.getReg()) != 0);
110+
}
111+
108112
void HexagonHazardRecognizer::EmitInstruction(SUnit *SU) {
109113
MachineInstr *MI = SU->getInstr();
110114
if (!MI)
@@ -119,19 +123,20 @@ void HexagonHazardRecognizer::EmitInstruction(SUnit *SU) {
119123
if (TII->isZeroCost(MI->getOpcode()))
120124
return;
121125

122-
if (!Resources->canReserveResources(*MI)) {
126+
if (!Resources->canReserveResources(*MI) || isNewStore(*MI)) {
123127
// It must be a .new store since other instructions must be able to be
124128
// reserved at this point.
125129
assert(TII->mayBeNewStore(*MI) && "Expecting .new store");
126130
MachineFunction *MF = MI->getParent()->getParent();
127131
MachineInstr *NewMI =
128132
MF->CreateMachineInstr(TII->get(TII->getDotNewOp(*MI)),
129133
MI->getDebugLoc());
130-
assert(Resources->canReserveResources(*NewMI));
131-
Resources->reserveResources(*NewMI);
134+
if (Resources->canReserveResources(*NewMI))
135+
Resources->reserveResources(*NewMI);
136+
else
137+
Resources->reserveResources(*MI);
132138
MF->deleteMachineInstr(NewMI);
133-
}
134-
else
139+
} else
135140
Resources->reserveResources(*MI);
136141
LLVM_DEBUG(dbgs() << " Add instruction " << *MI);
137142

llvm/lib/Target/Hexagon/HexagonHazardRecognizer.h

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class HexagonHazardRecognizer : public ScheduleHazardRecognizer {
4040
// The set of registers defined by instructions in the current packet.
4141
SmallSet<unsigned, 8> RegDefs;
4242

43+
// Return true if the instruction is a store that is converted to a new value
44+
// store because its value is defined in the same packet.
45+
bool isNewStore(MachineInstr &MI);
46+
4347
public:
4448
HexagonHazardRecognizer(const InstrItineraryData *II,
4549
const HexagonInstrInfo *HII,

0 commit comments

Comments
 (0)