Skip to content

Commit c3868a5

Browse files
committed
[AMDGPU] SIPeepholeSDWA: Stop using CombineSelections in convertToSDWA
The flag is not necessary since the relevant instructions can be detected by looking at the SrcSel->getImm().
1 parent b05facb commit c3868a5

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

llvm/lib/Target/AMDGPU/SIPeepholeSDWA.cpp

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ class SDWAOperand {
105105
virtual MachineInstr *potentialToConvert(const SIInstrInfo *TII,
106106
const GCNSubtarget &ST,
107107
SDWAOperandsMap *PotentialMatches = nullptr) = 0;
108-
virtual bool convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
109-
bool CombineSelections = false) = 0;
108+
virtual bool convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII) = 0;
110109

111110
MachineOperand *getTargetOperand() const { return Target; }
112111
MachineOperand *getReplacedOperand() const { return Replaced; }
@@ -170,11 +169,10 @@ class SDWASrcOperand : public SDWAOperand {
170169
: SDWAOperand(TargetOp, ReplacedOp),
171170
SrcSel(SrcSel_), Abs(Abs_), Neg(Neg_), Sext(Sext_) {}
172171

173-
MachineInstr *potentialToConvert(const SIInstrInfo *TII,
174-
const GCNSubtarget &ST,
175-
SDWAOperandsMap *PotentialMatches = nullptr) override;
176-
bool convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
177-
bool CombineSelections = false) override;
172+
MachineInstr *
173+
potentialToConvert(const SIInstrInfo *TII, const GCNSubtarget &ST,
174+
SDWAOperandsMap *PotentialMatches = nullptr) override;
175+
bool convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII) override;
178176

179177
SdwaSel getSrcSel() const { return SrcSel; }
180178
bool getAbs() const { return Abs; }
@@ -200,11 +198,10 @@ class SDWADstOperand : public SDWAOperand {
200198
SdwaSel DstSel_ = DWORD, DstUnused DstUn_ = UNUSED_PAD)
201199
: SDWAOperand(TargetOp, ReplacedOp), DstSel(DstSel_), DstUn(DstUn_) {}
202200

203-
MachineInstr *potentialToConvert(const SIInstrInfo *TII,
204-
const GCNSubtarget &ST,
205-
SDWAOperandsMap *PotentialMatches = nullptr) override;
206-
bool convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
207-
bool CombineSelections = false) override;
201+
MachineInstr *
202+
potentialToConvert(const SIInstrInfo *TII, const GCNSubtarget &ST,
203+
SDWAOperandsMap *PotentialMatches = nullptr) override;
204+
bool convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII) override;
208205

209206
SdwaSel getDstSel() const { return DstSel; }
210207
DstUnused getDstUnused() const { return DstUn; }
@@ -224,8 +221,7 @@ class SDWADstPreserveOperand : public SDWADstOperand {
224221
: SDWADstOperand(TargetOp, ReplacedOp, DstSel_, UNUSED_PRESERVE),
225222
Preserve(PreserveOp) {}
226223

227-
bool convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
228-
bool CombineSelections = false) override;
224+
bool convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII) override;
229225

230226
MachineOperand *getPreservedOperand() const { return Preserve; }
231227

@@ -414,8 +410,7 @@ MachineInstr *SDWASrcOperand::potentialToConvert(const SIInstrInfo *TII,
414410
return PotentialMO->getParent();
415411
}
416412

417-
bool SDWASrcOperand::convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
418-
bool CombineSelections) {
413+
bool SDWASrcOperand::convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII) {
419414
switch (MI.getOpcode()) {
420415
case AMDGPU::V_CVT_F32_FP8_sdwa:
421416
case AMDGPU::V_CVT_F32_BF8_sdwa:
@@ -491,14 +486,21 @@ bool SDWASrcOperand::convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
491486
}
492487
copyRegOperand(*Src, *getTargetOperand());
493488
if (!IsPreserveSrc) {
494-
if (CombineSelections) {
489+
if (SrcSel->getImm() == AMDGPU::SDWA::DWORD) {
490+
// An SDWA instruction with a trivial src_sel, i.e.
491+
// it has either not been adjusted before or it has
492+
// just been created at the call site of this function.
493+
// Use the operand's src_sel.
494+
SrcSel->setImm(getSrcSel());
495+
}
496+
else {
497+
// A preexisting SDWA instruction with a non-trivial src_sel.
498+
// Combine with the operand src_sel.
495499
std::optional<SdwaSel> NewOp =
496500
combineSdwaSel((SdwaSel)SrcSel->getImm(), getSrcSel());
497501
if (!NewOp.has_value())
498502
return false;
499503
SrcSel->setImm(NewOp.value());
500-
} else {
501-
SrcSel->setImm(getSrcSel());
502504
}
503505
SrcMods->setImm(getSrcMods(TII, Src));
504506
}
@@ -527,8 +529,7 @@ MachineInstr *SDWADstOperand::potentialToConvert(const SIInstrInfo *TII,
527529
return PotentialMO->getParent();
528530
}
529531

530-
bool SDWADstOperand::convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
531-
bool CombineSelections) {
532+
bool SDWADstOperand::convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII) {
532533
// Replace vdst operand in MI with target operand. Set dst_sel and dst_unused
533534

534535
if ((MI.getOpcode() == AMDGPU::V_FMAC_F16_sdwa ||
@@ -547,7 +548,7 @@ bool SDWADstOperand::convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
547548
copyRegOperand(*Operand, *getTargetOperand());
548549
MachineOperand *DstSel= TII->getNamedOperand(MI, AMDGPU::OpName::dst_sel);
549550
assert(DstSel);
550-
if (CombineSelections) {
551+
if (DstSel->getImm() != AMDGPU::SDWA::DWORD) {
551552
std::optional<SdwaSel> NewOp =
552553
combineSdwaSel((SdwaSel)DstSel->getImm(), getDstSel());
553554
if (!NewOp.has_value())
@@ -567,8 +568,7 @@ bool SDWADstOperand::convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
567568
}
568569

569570
bool SDWADstPreserveOperand::convertToSDWA(MachineInstr &MI,
570-
const SIInstrInfo *TII,
571-
bool CombineSelections) {
571+
const SIInstrInfo *TII) {
572572
// MI should be moved right before v_or_b32.
573573
// For this we should clear all kill flags on uses of MI src-operands or else
574574
// we can encounter problem with use of killed operand.
@@ -593,7 +593,7 @@ bool SDWADstPreserveOperand::convertToSDWA(MachineInstr &MI,
593593
MI.getNumOperands() - 1);
594594

595595
// Convert MI as any other SDWADstOperand and remove v_or_b32
596-
return SDWADstOperand::convertToSDWA(MI, TII, CombineSelections);
596+
return SDWADstOperand::convertToSDWA(MI, TII);
597597
}
598598

599599
std::optional<int64_t>
@@ -1227,18 +1227,15 @@ bool SIPeepholeSDWA::convertToSDWA(MachineInstr &MI,
12271227
LLVM_DEBUG(dbgs() << "Convert instruction:" << MI);
12281228

12291229
MachineInstr *SDWAInst;
1230-
bool CombineSelections;
12311230
if (TII->isSDWA(MI.getOpcode())) {
12321231
// No conversion necessary, since MI is an SDWA instruction. But
12331232
// tell convertToSDWA below to combine selections of this instruction
12341233
// and its SDWA operands.
12351234
SDWAInst = MI.getParent()->getParent()->CloneMachineInstr(&MI);
12361235
MI.getParent()->insert(MI.getIterator(), SDWAInst);
1237-
CombineSelections = true;
12381236
} else {
12391237
// Convert to sdwa
12401238
SDWAInst = createSDWAVersion(MI);
1241-
CombineSelections = false;
12421239
}
12431240

12441241
// Apply all sdwa operand patterns.
@@ -1256,7 +1253,7 @@ bool SIPeepholeSDWA::convertToSDWA(MachineInstr &MI,
12561253
// was already destroyed). So if SDWAOperand is also a potential MI then do
12571254
// not apply it.
12581255
if (PotentialMatches.count(Operand->getParentInst()) == 0)
1259-
Converted |= Operand->convertToSDWA(*SDWAInst, TII, CombineSelections);
1256+
Converted |= Operand->convertToSDWA(*SDWAInst, TII);
12601257
}
12611258

12621259
if (!Converted) {

0 commit comments

Comments
 (0)