[llvm] [AMDGPU] Invert scc uses to delete s_cmp_eq* (PR #167382)

via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 1 11:14:22 PST 2025


================
@@ -10737,12 +10737,62 @@ 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)) {
----------------
LU-JOHN wrote:

@arsenm @jayfoad  I need to determine if SCC is not live after a s_cbranch_scc* instruction.  Currently, I'm adding a kill flag when the machine instruction is inserted, but kill is soft deprecated.  The dead flag is also not suitable because the dead flag only applies to defs.   What is the best way to determine that SCC is not live after a s_cbranch_scc*?

https://github.com/llvm/llvm-project/pull/167382


More information about the llvm-commits mailing list