Skip to content

Commit 0ebdba4

Browse files
committed
Fix issue where HasStreamingModeChanges may be set to 'false' incorrectly
1 parent b577d4d commit 0ebdba4

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

llvm/lib/Target/AArch64/SMEPeepholeOpt.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct SMEPeepholeOpt : public MachineFunctionPass {
4545
}
4646

4747
bool optimizeStartStopPairs(MachineBasicBlock &MBB,
48-
bool &HasRemainingSMChange) const;
48+
bool &HasRemovedAllSMChanges) const;
4949
};
5050

5151
char SMEPeepholeOpt::ID = 0;
@@ -128,21 +128,18 @@ static bool isSVERegOp(const TargetRegisterInfo &TRI,
128128
TRI.getCommonSubClass(&AArch64::PPRRegClass, RC);
129129
}
130130

131-
bool SMEPeepholeOpt::optimizeStartStopPairs(MachineBasicBlock &MBB,
132-
bool &HasRemainingSMChange) const {
131+
bool SMEPeepholeOpt::optimizeStartStopPairs(
132+
MachineBasicBlock &MBB, bool &HasRemovedAllSMChanges) const {
133133
const MachineRegisterInfo &MRI = MBB.getParent()->getRegInfo();
134134
const TargetRegisterInfo &TRI =
135135
*MBB.getParent()->getSubtarget().getRegisterInfo();
136136

137-
SmallVector<MachineInstr *, 4> ToBeRemoved;
138-
139137
bool Changed = false;
140138
MachineInstr *Prev = nullptr;
141-
HasRemainingSMChange = false;
139+
SmallVector<MachineInstr *, 4> ToBeRemoved;
142140

141+
// Convenience function to reset the matching of a sequence.
143142
auto Reset = [&]() {
144-
if (Prev && ChangesStreamingMode(Prev))
145-
HasRemainingSMChange = true;
146143
Prev = nullptr;
147144
ToBeRemoved.clear();
148145
};
@@ -151,10 +148,15 @@ bool SMEPeepholeOpt::optimizeStartStopPairs(MachineBasicBlock &MBB,
151148
// and smstop nodes that cancel each other out. We only permit a limited
152149
// set of instructions to appear between them, otherwise we reset our
153150
// tracking.
151+
unsigned NumSMChanges = 0;
152+
unsigned NumSMChangesRemoved = 0;
154153
for (MachineInstr &MI : make_early_inc_range(MBB)) {
155154
switch (MI.getOpcode()) {
156155
case AArch64::MSRpstatesvcrImm1:
157156
case AArch64::MSRpstatePseudo: {
157+
if (ChangesStreamingMode(&MI))
158+
NumSMChanges++;
159+
158160
if (!Prev)
159161
Prev = &MI;
160162
else if (isMatchingStartStopPair(Prev, &MI)) {
@@ -167,6 +169,7 @@ bool SMEPeepholeOpt::optimizeStartStopPairs(MachineBasicBlock &MBB,
167169
ToBeRemoved.clear();
168170
Prev = nullptr;
169171
Changed = true;
172+
NumSMChangesRemoved += 2;
170173
} else {
171174
Reset();
172175
Prev = &MI;
@@ -218,6 +221,8 @@ bool SMEPeepholeOpt::optimizeStartStopPairs(MachineBasicBlock &MBB,
218221
}
219222
}
220223

224+
HasRemovedAllSMChanges =
225+
NumSMChanges && (NumSMChanges == NumSMChangesRemoved);
221226
return Changed;
222227
}
223228

@@ -234,20 +239,20 @@ bool SMEPeepholeOpt::runOnMachineFunction(MachineFunction &MF) {
234239
assert(MF.getRegInfo().isSSA() && "Expected to be run on SSA form!");
235240

236241
bool Changed = false;
237-
bool FunctionHasRemainingSMChange = false;
242+
bool FunctionHasAllSMChangesRemoved = false;
238243

239244
// Even if the block lives in a function with no SME attributes attached we
240245
// still have to analyze all the blocks because we may call a streaming
241246
// function that requires smstart/smstop pairs.
242247
for (MachineBasicBlock &MBB : MF) {
243-
bool BlockHasRemainingSMChange;
244-
Changed |= optimizeStartStopPairs(MBB, BlockHasRemainingSMChange);
245-
FunctionHasRemainingSMChange |= BlockHasRemainingSMChange;
248+
bool BlockHasAllSMChangesRemoved;
249+
Changed |= optimizeStartStopPairs(MBB, BlockHasAllSMChangesRemoved);
250+
FunctionHasAllSMChangesRemoved |= BlockHasAllSMChangesRemoved;
246251
}
247252

248253
AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
249-
if (Changed && AFI->hasStreamingModeChanges())
250-
AFI->setHasStreamingModeChanges(FunctionHasRemainingSMChange);
254+
if (FunctionHasAllSMChangesRemoved)
255+
AFI->setHasStreamingModeChanges(false);
251256

252257
return Changed;
253258
}

0 commit comments

Comments
 (0)