[llvm] [ReachingDefAnalysis][NFC] Use named constants. (PR #175075)

Mikhail Gudim via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 8 14:15:00 PST 2026


https://github.com/mgudim updated https://github.com/llvm/llvm-project/pull/175075

>From f01073d7c3f13fd84456c6934eff25166cab3fa7 Mon Sep 17 00:00:00 2001
From: Mikhail Gudim <mgudim at qti.qualcomm.com>
Date: Thu, 8 Jan 2026 13:30:12 -0800
Subject: [PATCH 1/2] [CodeGen][NFC] Improve readability of
 getLocalLiveOutMIDef

Reorder some code to make it less confusing.
---
 llvm/lib/CodeGen/ReachingDefAnalysis.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
index b12a5bc64ca0b..b8b35210413ff 100644
--- a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
+++ b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
@@ -663,18 +663,18 @@ MachineInstr *ReachingDefInfo::getLocalLiveOutMIDef(MachineBasicBlock *MBB,
   if (Last == MBB->end())
     return nullptr;
 
+  // Check if Last is the definition
   if (Reg.isStack()) {
     int FrameIndex = Reg.stackSlotIndex();
     if (isFIDef(*Last, FrameIndex, TII))
       return &*Last;
+  } else {
+    for (auto &MO : Last->operands())
+      if (isValidRegDefOf(MO, Reg, TRI))
+        return &*Last;
   }
 
   int Def = getReachingDef(&*Last, Reg);
-
-  for (auto &MO : Last->operands())
-    if (isValidRegDefOf(MO, Reg, TRI))
-      return &*Last;
-
   return Def < 0 ? nullptr : getInstFromId(MBB, Def);
 }
 

>From 28ea750f0cb3afe51b13f369208d8b57ee4041eb Mon Sep 17 00:00:00 2001
From: Mikhail Gudim <mgudim at qti.qualcomm.com>
Date: Thu, 8 Jan 2026 13:47:21 -0800
Subject: [PATCH 2/2] [ReachingDefAnalysis][NFC] Use named constants.

---
 llvm/include/llvm/CodeGen/ReachingDefAnalysis.h | 2 ++
 llvm/lib/CodeGen/ReachingDefAnalysis.cpp        | 6 +++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h b/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
index 863c3b39229b9..03505efdebfd9 100644
--- a/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
+++ b/llvm/include/llvm/CodeGen/ReachingDefAnalysis.h
@@ -152,6 +152,8 @@ class ReachingDefInfo {
 
   /// Default values are 'nothing happened a long time ago'.
   const int ReachingDefDefaultVal = -(1 << 21);
+  /// Special values for function live-ins.
+  const int FunctionLiveInMarker = -1;
 
   using InstSet = SmallPtrSetImpl<MachineInstr*>;
   using BlockSet = SmallPtrSetImpl<MachineBasicBlock*>;
diff --git a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
index b8b35210413ff..78ee5ce77cf81 100644
--- a/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
+++ b/llvm/lib/CodeGen/ReachingDefAnalysis.cpp
@@ -134,9 +134,9 @@ void ReachingDefInfo::enterBasicBlock(MachineBasicBlock *MBB) {
         // Treat function live-ins as if they were defined just before the first
         // instruction.  Usually, function arguments are set up immediately
         // before the call.
-        if (LiveRegs[static_cast<unsigned>(Unit)] != -1) {
-          LiveRegs[static_cast<unsigned>(Unit)] = -1;
-          MBBReachingDefs.append(MBBNumber, Unit, -1);
+        if (LiveRegs[static_cast<unsigned>(Unit)] != FunctionLiveInMarker) {
+          LiveRegs[static_cast<unsigned>(Unit)] = FunctionLiveInMarker;
+          MBBReachingDefs.append(MBBNumber, Unit, FunctionLiveInMarker);
         }
       }
     }



More information about the llvm-commits mailing list