Skip to content

Commit 65e8164

Browse files
committed
revised initial commit
1 parent abb8c4b commit 65e8164

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,27 @@ Register SIInstrInfo::insertNE(MachineBasicBlock *MBB,
13131313
return Reg;
13141314
}
13151315

1316+
MachineInstr *
1317+
SIInstrInfo::pierceThroughRegSequence(const MachineInstr &MI) const {
1318+
const MachineRegisterInfo &MRI = MI.getParent()->getParent()->getRegInfo();
1319+
int64_t SubRegValues[2];
1320+
bool SubRegIsConst[2];
1321+
MachineInstr *RealDefs[2];
1322+
for (unsigned I : {2, 4}) {
1323+
unsigned ArrayIdx = MI.getOperand(I).getImm() == AMDGPU::sub0 ? 0 : 1;
1324+
Register Subreg = MI.getOperand(I - 1).getReg();
1325+
RealDefs[ArrayIdx] = MRI.getUniqueVRegDef(Subreg);
1326+
SubRegIsConst[ArrayIdx] = getConstValDefinedInReg(
1327+
*RealDefs[ArrayIdx], Subreg, SubRegValues[ArrayIdx]);
1328+
}
1329+
1330+
for (unsigned I : {0, 1})
1331+
if (SubRegIsConst[I] && !SubRegValues[I])
1332+
return RealDefs[(I + 1) % 2];
1333+
1334+
return nullptr;
1335+
}
1336+
13161337
bool SIInstrInfo::getConstValDefinedInReg(const MachineInstr &MI,
13171338
const Register Reg,
13181339
int64_t &ImmVal) const {
@@ -10698,6 +10719,9 @@ bool SIInstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
1069810719
if (!Def)
1069910720
return false;
1070010721

10722+
if (MachineInstr *RegSequenceDef = pierceThroughRegSequence(*Def))
10723+
Def = RegSequenceDef;
10724+
1070110725
// For S_OP that set SCC = DST!=0, do the transformation
1070210726
//
1070310727
// s_cmp_lg_* (S_OP ...), 0 => (S_OP ...)

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,8 @@ class SIInstrInfo final : public AMDGPUGenInstrInfo {
711711
}
712712
}
713713

714+
MachineInstr *pierceThroughRegSequence(const MachineInstr &MI) const;
715+
714716
static bool setsSCCifResultIsNonZero(const MachineInstr &MI) {
715717
switch (MI.getOpcode()) {
716718
case AMDGPU::S_ABSDIFF_I32:

0 commit comments

Comments
 (0)