[llvm] [AMDGPU] Invert scc uses to delete s_cmp_eq* (PR #167382)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 07:16:34 PST 2025
================
@@ -10737,12 +10737,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) || MI.isReturn()) {
----------------
jayfoad wrote:
Why do you need to check isReturn here? If it is needed, it's probably cleaner to move it outside the loop and check `MBB->succ_empty()` instead.
https://github.com/llvm/llvm-project/pull/167382
More information about the llvm-commits
mailing list