[llvm] [AMDGPU] Invert scc uses to delete s_cmp_eq* (PR #167382)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 15 23:34:10 PST 2025
================
@@ -10715,12 +10715,61 @@ bool SIInstrInfo::analyzeCompare(const MachineInstr &MI, Register &SrcReg,
return false;
}
+// Invert all uses of SCC following SCCDef because SCCDef may be deleted and
+// (incoming SCC) = !(SCC defined by SCCDef).
+// Return true if all uses can be re-written, false otherwise.
+bool SIInstrInfo::invertSCCUse(MachineInstr *SCCDef) const {
+ MachineBasicBlock *MBB = SCCDef->getParent();
+ SmallVector<MachineInstr *> InvertInstr;
+ bool SCCIsDead = false;
+
+ // Scan instructions for SCC uses that need to be inverted until SCC is dead.
+ for (MachineInstr &MI :
+ make_range(std::next(MachineBasicBlock::iterator(SCCDef)), MBB->end())) {
+ if (MI.readsRegister(AMDGPU::SCC, &RI)) {
+ if (MI.getOpcode() == AMDGPU::S_CSELECT_B32 ||
+ MI.getOpcode() == AMDGPU::S_CSELECT_B64 ||
+ MI.getOpcode() == AMDGPU::S_CBRANCH_SCC0 ||
+ MI.getOpcode() == AMDGPU::S_CBRANCH_SCC1)
+ InvertInstr.push_back(&MI);
+ else
+ return false;
+ }
+ if (MI.definesRegister(AMDGPU::SCC, &RI) ||
+ MI.killsRegister(AMDGPU::SCC, &RI)) {
+ SCCIsDead = true;
+ break;
+ }
+ }
+
+ // If SCC is still live, verify that it is not live past the end of this
+ // block.
+ if (!SCCIsDead && MBB->isLiveOut(AMDGPU::SCC))
----------------
LU-JOHN wrote:
Removed isLiveOut. Will rely on kill flags and subsequent scc defines. Will try to improve kill flags coming out of isel in a future PR. shl32_eq test in s_cmp_0.ll needs improved kill flags.
https://github.com/llvm/llvm-project/pull/167382
More information about the llvm-commits
mailing list