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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 8 10:52:38 PST 2026


================
@@ -10766,12 +10766,69 @@ bool SIInstrInfo::analyzeCompare(const MachineInstr &MI, Register &SrcReg,
   return false;
 }
 
+static bool isSCCDeadOnExit(MachineBasicBlock *MBB) {
+  for (MachineBasicBlock *S : MBB->successors()) {
+    if (S->isLiveIn(AMDGPU::SCC))
+      return false;
+  }
+  return true;
+}
+
+// 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())) {
----------------
arsenm wrote:

The natural direction for liveness is actually backwards. You don't need kill flags with reverse uses 

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


More information about the llvm-commits mailing list