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

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 21 07:57:24 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:

> No, dead register is a subset of defined register if it's known there is no use of the value.

So does the dead flag mean that a register is not live after an instruction?  It can be set for operands that are only used and not defined by the instruction?

Looking at https://llvm.org/docs/MIRLangRef.html#register-flags, dead is an unused definition, which is different from the "not live after an instruction".



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


More information about the llvm-commits mailing list