[llvm] [AMDGPU] Delete redundant s_or_b32 (PR #165261)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 4 18:50:57 PST 2025
================
@@ -10689,6 +10689,32 @@ bool SIInstrInfo::optimizeCompareInstr(MachineInstr &CmpInstr, Register SrcReg,
if (!optimizeSCC(Def, &CmpInstr, RI))
return false;
+ // If s_or_b32 result, sY, is unused (i.e. it is effectively a 64-bit
+ // s_cmp_lg of a register pair) and the inputs are the hi and lo-halves of a
+ // 64-bit foldableSelect then delete s_or_b32 in the sequence:
+ // sX = s_cselect_b64 (non-zero imm), 0
+ // sLo = copy sX.sub0
+ // sHi = copy sX.sub1
+ // sY = s_or_b32 sLo, sHi
+ if (Def->getOpcode() == AMDGPU::S_OR_B32 &&
+ MRI->use_nodbg_empty(Def->getOperand(0).getReg())) {
+ const MachineOperand &OrOpnd1 = Def->getOperand(1);
+ const MachineOperand &OrOpnd2 = Def->getOperand(2);
+ if (OrOpnd1.isReg() && OrOpnd2.isReg()) {
+ MachineInstr *Def1 = MRI->getUniqueVRegDef(OrOpnd1.getReg());
+ MachineInstr *Def2 = MRI->getUniqueVRegDef(OrOpnd2.getReg());
----------------
arsenm wrote:
Need to check if there failed, this will crash on undef operands. Probably should also use getVRegDef, this doesn't run on post-SSA
https://github.com/llvm/llvm-project/pull/165261
More information about the llvm-commits
mailing list