@@ -105,8 +105,7 @@ class SDWAOperand {
105
105
virtual MachineInstr *potentialToConvert (const SIInstrInfo *TII,
106
106
const GCNSubtarget &ST,
107
107
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;
110
109
111
110
MachineOperand *getTargetOperand () const { return Target; }
112
111
MachineOperand *getReplacedOperand () const { return Replaced; }
@@ -170,11 +169,10 @@ class SDWASrcOperand : public SDWAOperand {
170
169
: SDWAOperand(TargetOp, ReplacedOp),
171
170
SrcSel (SrcSel_), Abs(Abs_), Neg(Neg_), Sext(Sext_) {}
172
171
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 ;
178
176
179
177
SdwaSel getSrcSel () const { return SrcSel; }
180
178
bool getAbs () const { return Abs; }
@@ -200,11 +198,10 @@ class SDWADstOperand : public SDWAOperand {
200
198
SdwaSel DstSel_ = DWORD, DstUnused DstUn_ = UNUSED_PAD)
201
199
: SDWAOperand(TargetOp, ReplacedOp), DstSel(DstSel_), DstUn(DstUn_) {}
202
200
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 ;
208
205
209
206
SdwaSel getDstSel () const { return DstSel; }
210
207
DstUnused getDstUnused () const { return DstUn; }
@@ -224,8 +221,7 @@ class SDWADstPreserveOperand : public SDWADstOperand {
224
221
: SDWADstOperand(TargetOp, ReplacedOp, DstSel_, UNUSED_PRESERVE),
225
222
Preserve (PreserveOp) {}
226
223
227
- bool convertToSDWA (MachineInstr &MI, const SIInstrInfo *TII,
228
- bool CombineSelections = false ) override ;
224
+ bool convertToSDWA (MachineInstr &MI, const SIInstrInfo *TII) override ;
229
225
230
226
MachineOperand *getPreservedOperand () const { return Preserve; }
231
227
@@ -414,8 +410,7 @@ MachineInstr *SDWASrcOperand::potentialToConvert(const SIInstrInfo *TII,
414
410
return PotentialMO->getParent ();
415
411
}
416
412
417
- bool SDWASrcOperand::convertToSDWA (MachineInstr &MI, const SIInstrInfo *TII,
418
- bool CombineSelections) {
413
+ bool SDWASrcOperand::convertToSDWA (MachineInstr &MI, const SIInstrInfo *TII) {
419
414
switch (MI.getOpcode ()) {
420
415
case AMDGPU::V_CVT_F32_FP8_sdwa:
421
416
case AMDGPU::V_CVT_F32_BF8_sdwa:
@@ -491,14 +486,21 @@ bool SDWASrcOperand::convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
491
486
}
492
487
copyRegOperand (*Src, *getTargetOperand ());
493
488
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.
495
499
std::optional<SdwaSel> NewOp =
496
500
combineSdwaSel ((SdwaSel)SrcSel->getImm (), getSrcSel ());
497
501
if (!NewOp.has_value ())
498
502
return false ;
499
503
SrcSel->setImm (NewOp.value ());
500
- } else {
501
- SrcSel->setImm (getSrcSel ());
502
504
}
503
505
SrcMods->setImm (getSrcMods (TII, Src));
504
506
}
@@ -527,8 +529,7 @@ MachineInstr *SDWADstOperand::potentialToConvert(const SIInstrInfo *TII,
527
529
return PotentialMO->getParent ();
528
530
}
529
531
530
- bool SDWADstOperand::convertToSDWA (MachineInstr &MI, const SIInstrInfo *TII,
531
- bool CombineSelections) {
532
+ bool SDWADstOperand::convertToSDWA (MachineInstr &MI, const SIInstrInfo *TII) {
532
533
// Replace vdst operand in MI with target operand. Set dst_sel and dst_unused
533
534
534
535
if ((MI.getOpcode () == AMDGPU::V_FMAC_F16_sdwa ||
@@ -547,7 +548,7 @@ bool SDWADstOperand::convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
547
548
copyRegOperand (*Operand, *getTargetOperand ());
548
549
MachineOperand *DstSel= TII->getNamedOperand (MI, AMDGPU::OpName::dst_sel);
549
550
assert (DstSel);
550
- if (CombineSelections ) {
551
+ if (DstSel-> getImm () != AMDGPU::SDWA::DWORD ) {
551
552
std::optional<SdwaSel> NewOp =
552
553
combineSdwaSel ((SdwaSel)DstSel->getImm (), getDstSel ());
553
554
if (!NewOp.has_value ())
@@ -567,8 +568,7 @@ bool SDWADstOperand::convertToSDWA(MachineInstr &MI, const SIInstrInfo *TII,
567
568
}
568
569
569
570
bool SDWADstPreserveOperand::convertToSDWA (MachineInstr &MI,
570
- const SIInstrInfo *TII,
571
- bool CombineSelections) {
571
+ const SIInstrInfo *TII) {
572
572
// MI should be moved right before v_or_b32.
573
573
// For this we should clear all kill flags on uses of MI src-operands or else
574
574
// we can encounter problem with use of killed operand.
@@ -593,7 +593,7 @@ bool SDWADstPreserveOperand::convertToSDWA(MachineInstr &MI,
593
593
MI.getNumOperands () - 1 );
594
594
595
595
// Convert MI as any other SDWADstOperand and remove v_or_b32
596
- return SDWADstOperand::convertToSDWA (MI, TII, CombineSelections );
596
+ return SDWADstOperand::convertToSDWA (MI, TII);
597
597
}
598
598
599
599
std::optional<int64_t >
@@ -1227,18 +1227,15 @@ bool SIPeepholeSDWA::convertToSDWA(MachineInstr &MI,
1227
1227
LLVM_DEBUG (dbgs () << " Convert instruction:" << MI);
1228
1228
1229
1229
MachineInstr *SDWAInst;
1230
- bool CombineSelections;
1231
1230
if (TII->isSDWA (MI.getOpcode ())) {
1232
1231
// No conversion necessary, since MI is an SDWA instruction. But
1233
1232
// tell convertToSDWA below to combine selections of this instruction
1234
1233
// and its SDWA operands.
1235
1234
SDWAInst = MI.getParent ()->getParent ()->CloneMachineInstr (&MI);
1236
1235
MI.getParent ()->insert (MI.getIterator (), SDWAInst);
1237
- CombineSelections = true ;
1238
1236
} else {
1239
1237
// Convert to sdwa
1240
1238
SDWAInst = createSDWAVersion (MI);
1241
- CombineSelections = false ;
1242
1239
}
1243
1240
1244
1241
// Apply all sdwa operand patterns.
@@ -1256,7 +1253,7 @@ bool SIPeepholeSDWA::convertToSDWA(MachineInstr &MI,
1256
1253
// was already destroyed). So if SDWAOperand is also a potential MI then do
1257
1254
// not apply it.
1258
1255
if (PotentialMatches.count (Operand->getParentInst ()) == 0 )
1259
- Converted |= Operand->convertToSDWA (*SDWAInst, TII, CombineSelections );
1256
+ Converted |= Operand->convertToSDWA (*SDWAInst, TII);
1260
1257
}
1261
1258
1262
1259
if (!Converted) {
0 commit comments