Skip to content

Commit 37ab639

Browse files
committed
follow up patch
1 parent 48db3fd commit 37ab639

File tree

3 files changed

+20
-38
lines changed

3 files changed

+20
-38
lines changed

llvm/lib/Target/AMDGPU/SIFoldOperands.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,8 @@ static MachineOperand *lookUpCopyChain(const SIInstrInfo &TII,
932932
for (MachineInstr *SubDef = MRI.getVRegDef(SrcReg);
933933
SubDef && TII.isFoldableCopy(*SubDef);
934934
SubDef = MRI.getVRegDef(Sub->getReg())) {
935-
unsigned SrcIdx = TII.getFoldableCopySrcIdx(*SubDef);
935+
const int SrcIdx =
936+
(SubDef->getOpcode()) == AMDGPU::V_MOV_B16_t16_e64 ? 2 : 1;
936937
MachineOperand &SrcOp = SubDef->getOperand(SrcIdx);
937938

938939
if (SrcOp.isImm())

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3408,10 +3408,9 @@ void SIInstrInfo::insertSelect(MachineBasicBlock &MBB,
34083408
}
34093409
}
34103410

3411-
bool SIInstrInfo::isFoldableCopy(const MachineInstr &MI) {
3411+
bool SIInstrInfo::isFoldableCopy(const MachineInstr &MI) const {
34123412
switch (MI.getOpcode()) {
34133413
case AMDGPU::V_MOV_B16_t16_e32:
3414-
case AMDGPU::V_MOV_B16_t16_e64:
34153414
case AMDGPU::V_MOV_B32_e32:
34163415
case AMDGPU::V_MOV_B32_e64:
34173416
case AMDGPU::V_MOV_B64_PSEUDO:
@@ -3428,34 +3427,10 @@ bool SIInstrInfo::isFoldableCopy(const MachineInstr &MI) {
34283427
case AMDGPU::AV_MOV_B32_IMM_PSEUDO:
34293428
case AMDGPU::AV_MOV_B64_IMM_PSEUDO:
34303429
return true;
3431-
default:
3432-
return false;
3433-
}
3434-
}
3435-
3436-
unsigned SIInstrInfo::getFoldableCopySrcIdx(const MachineInstr &MI) {
3437-
switch (MI.getOpcode()) {
3438-
case AMDGPU::V_MOV_B16_t16_e32:
34393430
case AMDGPU::V_MOV_B16_t16_e64:
3440-
return 2;
3441-
case AMDGPU::V_MOV_B32_e32:
3442-
case AMDGPU::V_MOV_B32_e64:
3443-
case AMDGPU::V_MOV_B64_PSEUDO:
3444-
case AMDGPU::V_MOV_B64_e32:
3445-
case AMDGPU::V_MOV_B64_e64:
3446-
case AMDGPU::S_MOV_B32:
3447-
case AMDGPU::S_MOV_B64:
3448-
case AMDGPU::S_MOV_B64_IMM_PSEUDO:
3449-
case AMDGPU::COPY:
3450-
case AMDGPU::WWM_COPY:
3451-
case AMDGPU::V_ACCVGPR_WRITE_B32_e64:
3452-
case AMDGPU::V_ACCVGPR_READ_B32_e64:
3453-
case AMDGPU::V_ACCVGPR_MOV_B32:
3454-
case AMDGPU::AV_MOV_B32_IMM_PSEUDO:
3455-
case AMDGPU::AV_MOV_B64_IMM_PSEUDO:
3456-
return 1;
3431+
return !hasAnyModifiersSet(MI);
34573432
default:
3458-
llvm_unreachable("MI is not a foldable copy");
3433+
return false;
34593434
}
34603435
}
34613436

@@ -3976,12 +3951,13 @@ bool SIInstrInfo::areMemAccessesTriviallyDisjoint(const MachineInstr &MIa,
39763951
return false;
39773952
}
39783953

3979-
static bool getFoldableImm(Register Reg, const MachineRegisterInfo &MRI,
3980-
int64_t &Imm, MachineInstr **DefMI = nullptr) {
3954+
bool SIInstrInfo::getFoldableImm(Register Reg, const MachineRegisterInfo &MRI,
3955+
int64_t &Imm,
3956+
MachineInstr **DefMI = nullptr) const {
39813957
if (Reg.isPhysical())
39823958
return false;
39833959
auto *Def = MRI.getUniqueVRegDef(Reg);
3984-
if (Def && SIInstrInfo::isFoldableCopy(*Def) && Def->getOperand(1).isImm()) {
3960+
if (Def && isFoldableCopy(*Def) && Def->getOperand(1).isImm()) {
39853961
Imm = Def->getOperand(1).getImm();
39863962
if (DefMI)
39873963
*DefMI = Def;
@@ -3990,8 +3966,8 @@ static bool getFoldableImm(Register Reg, const MachineRegisterInfo &MRI,
39903966
return false;
39913967
}
39923968

3993-
static bool getFoldableImm(const MachineOperand *MO, int64_t &Imm,
3994-
MachineInstr **DefMI = nullptr) {
3969+
bool SIInstrInfo::getFoldableImm(const MachineOperand *MO, int64_t &Imm,
3970+
MachineInstr **DefMI = nullptr) const {
39953971
if (!MO->isReg())
39963972
return false;
39973973
const MachineFunction *MF = MO->getParent()->getParent()->getParent();
@@ -10643,10 +10619,11 @@ bool SIInstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
1064310619
return false;
1064410620

1064510621
int64_t Mask;
10646-
const auto isMask = [&Mask, SrcSize](const MachineOperand *MO) -> bool {
10622+
const auto isMask = [&Mask, SrcSize,
10623+
this](const MachineOperand *MO) -> bool {
1064710624
if (MO->isImm())
1064810625
Mask = MO->getImm();
10649-
else if (!getFoldableImm(MO, Mask))
10626+
else if (!this->getFoldableImm(MO, Mask))
1065010627
return false;
1065110628
Mask &= maxUIntN(SrcSize);
1065210629
return isPowerOf2_64(Mask);

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,12 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
416416
areMemAccessesTriviallyDisjoint(const MachineInstr &MIa,
417417
const MachineInstr &MIb) const override;
418418

419-
static bool isFoldableCopy(const MachineInstr &MI);
420-
static unsigned getFoldableCopySrcIdx(const MachineInstr &MI);
419+
bool isFoldableCopy(const MachineInstr &MI) const;
420+
421+
bool getFoldableImm(Register Reg, const MachineRegisterInfo &MRI,
422+
int64_t &Imm, MachineInstr **DefMI) const;
423+
bool getFoldableImm(const MachineOperand *MO, int64_t &Imm,
424+
MachineInstr **DefMI) const;
421425

422426
void removeModOperands(MachineInstr &MI) const;
423427

0 commit comments

Comments
 (0)