Skip to content

Commit 559ef0a

Browse files
committed
Delete redundant s_or_b32
Signed-off-by: John Lu <John.Lu@amd.com>
1 parent 10f5d95 commit 559ef0a

File tree

11 files changed

+1058
-1205
lines changed

11 files changed

+1058
-1205
lines changed

llvm/lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10160,7 +10160,7 @@ static bool followSubRegDef(MachineInstr &MI,
1016010160
}
1016110161

1016210162
MachineInstr *llvm::getVRegSubRegDef(const TargetInstrInfo::RegSubRegPair &P,
10163-
MachineRegisterInfo &MRI) {
10163+
const MachineRegisterInfo &MRI) {
1016410164
assert(MRI.isSSA());
1016510165
if (!P.Reg.isVirtual())
1016610166
return nullptr;
@@ -10690,6 +10690,25 @@ bool SIInstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
1069010690
if (!optimizeSCC(Def, &CmpInstr))
1069110691
return false;
1069210692

10693+
// If s_or_32 result is unused (i.e. it is effectively a 64-bit s_cmp_lg of
10694+
// a register pair) and the input is a 64-bit foldableSelect then transform:
10695+
//
10696+
// (s_or_b32 (S_CSELECT_B64 (non-zero imm), 0), 0 => (S_CSELECT_B64
10697+
// (non-zero
10698+
// imm), 0)
10699+
if (Def->getOpcode() == AMDGPU::S_OR_B32 &&
10700+
MRI->use_nodbg_empty(Def->getOperand(0).getReg())) {
10701+
MachineOperand OrOpnd1 = Def->getOperand(1);
10702+
MachineOperand OrOpnd2 = Def->getOperand(2);
10703+
10704+
if (OrOpnd1.isReg() && OrOpnd2.isReg() &&
10705+
OrOpnd1.getReg() != OrOpnd2.getReg()) {
10706+
auto *Def1 = getVRegSubRegDef(getRegSubRegPair(OrOpnd1), *MRI);
10707+
auto *Def2 = getVRegSubRegDef(getRegSubRegPair(OrOpnd2), *MRI);
10708+
if (Def1 == Def2 && foldableSelect(Def1))
10709+
optimizeSCC(Def1, Def);
10710+
}
10711+
}
1069310712
return true;
1069410713
};
1069510714

llvm/lib/Target/AMDGPU/SIInstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ TargetInstrInfo::RegSubRegPair getRegSequenceSubReg(MachineInstr &MI,
16871687
/// skipping copy like instructions and subreg-manipulation pseudos.
16881688
/// Following another subreg of a reg:subreg isn't supported.
16891689
MachineInstr *getVRegSubRegDef(const TargetInstrInfo::RegSubRegPair &P,
1690-
MachineRegisterInfo &MRI);
1690+
const MachineRegisterInfo &MRI);
16911691

16921692
/// \brief Return false if EXEC is not changed between the def of \p VReg at \p
16931693
/// DefMI and the use at \p UseMI. Should be run on SSA. Currently does not

0 commit comments

Comments
 (0)