[llvm] [MISched] Make `getUnderlyingObjectsForInstr()` preserve unidentified objects (PR #225085)

Nathan Corbyn via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 24 04:09:59 PDT 2026


https://github.com/cofibrant updated https://github.com/llvm/llvm-project/pull/225085

>From 0718e7c1b9bf93bac06c8fe63734a398b0f0954b Mon Sep 17 00:00:00 2001
From: Nathan Corbyn <n_corbyn at apple.com>
Date: Mon, 21 Sep 2026 14:33:56 +0100
Subject: [PATCH 1/4] [MISched] Make `getUnderlyingObjectsForInstr()` preserve
 unidentified objects

---
 llvm/lib/CodeGen/ScheduleDAGInstrs.cpp | 79 ++++++++++++--------------
 1 file changed, 37 insertions(+), 42 deletions(-)

diff --git a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
index c929276b219f7..6bd6c733ddc8f 100644
--- a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
+++ b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
@@ -128,49 +128,44 @@ static bool getUnderlyingObjectsForInstr(const MachineInstr *MI,
                                          const MachineFrameInfo &MFI,
                                          UnderlyingObjectsVector &Objects,
                                          const DataLayout &DL) {
-  auto AllMMOsOkay = [&]() {
-    for (const MachineMemOperand *MMO : MI->memoperands()) {
-      // TODO: Figure out whether isAtomic is really necessary (see D57601).
-      if (MMO->isVolatile() || MMO->isAtomic())
-        return false;
-
-      if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) {
-        // Function that contain tail calls don't have unique PseudoSourceValue
-        // objects. Two PseudoSourceValues might refer to the same or
-        // overlapping locations. The client code calling this function assumes
-        // this is not the case. So return a conservative answer of no known
-        // object.
-        if (MFI.hasTailCall())
-          return false;
-
-        // For now, ignore PseudoSourceValues which may alias LLVM IR values
-        // because the code that uses this function has no way to cope with
-        // such aliases.
-        if (PSV->isAliased(&MFI))
-          return false;
+  bool AllObjectsIdentified = true;
 
-        Objects.push_back(PSV);
-      } else if (const Value *V = MMO->getValue()) {
-        SmallVector<Value *, 4> Objs;
-        if (!getUnderlyingObjectsForCodeGen(V, Objs))
-          return false;
-
-        for (Value *V : Objs) {
-          assert(isIdentifiedObject(V));
-          Objects.push_back(V);
-        }
-      } else
-        return false;
+  for (const MachineMemOperand *MMO : MI->memoperands()) {
+    // TODO: Figure out whether isAtomic is really necessary (see D57601).
+    if (MMO->isVolatile() || MMO->isAtomic()) {
+      AllObjectsIdentified = false;
+      continue;
     }
-    return true;
-  };
 
-  if (!AllMMOsOkay()) {
-    Objects.clear();
-    return false;
+    if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) {
+      // Function that contain tail calls don't have unique PseudoSourceValue
+      // objects. Two PseudoSourceValues might refer to the same or
+      // overlapping locations. The client code calling this function assumes
+      // this is not the case. So return a conservative answer of no known
+      // object.
+      if (MFI.hasTailCall())
+        AllObjectsIdentified = false;
+
+      // For now, ignore PseudoSourceValues which may alias LLVM IR values
+      // because the code that uses this function has no way to cope with
+      // such aliases.
+      if (PSV->isAliased(&MFI))
+        AllObjectsIdentified = false;
+
+      Objects.push_back(PSV);
+    } else if (const Value *V = MMO->getValue()) {
+      SmallVector<Value *, 4> Objs;
+      AllObjectsIdentified &= getUnderlyingObjectsForCodeGen(V, Objs);
+
+      for (Value *V : Objs) {
+        assert(!AllObjectsIdentified || isIdentifiedObject(V));
+        Objects.push_back(V);
+      }
+    } else
+      AllObjectsIdentified = false;
   }
 
-  return true;
+  return AllObjectsIdentified;
 }
 
 void ScheduleDAGInstrs::startBlock(MachineBasicBlock *bb) {
@@ -926,11 +921,11 @@ void ScheduleDAGInstrs::buildSchedGraph(AAResults *AA,
     // empty, or filled with the Values of memory locations which this
     // SU depends on.
     UnderlyingObjectsVector Objs;
-    bool ObjsFound = getUnderlyingObjectsForInstr(&MI, MFI, Objs,
-                                                  MF.getDataLayout());
+    bool ObjsIdentified =
+        getUnderlyingObjectsForInstr(&MI, MFI, Objs, MF.getDataLayout());
 
     if (MI.mayStore()) {
-      if (!ObjsFound) {
+      if (!ObjsIdentified) {
         // An unknown store depends on all stores and loads.
         addChainDependencies(SU, Stores);
         addChainDependencies(SU, Loads);
@@ -956,7 +951,7 @@ void ScheduleDAGInstrs::buildSchedGraph(AAResults *AA,
         addChainDependencies(SU, Stores, UnknownValue);
       }
     } else { // SU is a load.
-      if (!ObjsFound) {
+      if (!ObjsIdentified) {
         // An unknown load depends on all stores.
         addChainDependencies(SU, Stores);
 

>From 52186e3b521767581b93e5604e537c4dea61e0e4 Mon Sep 17 00:00:00 2001
From: Nathan Corbyn <n_corbyn at apple.com>
Date: Tue, 22 Sep 2026 10:24:39 +0100
Subject: [PATCH 2/4] Fixups

---
 llvm/lib/CodeGen/ScheduleDAGInstrs.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
index 6bd6c733ddc8f..f5672bf26e2df 100644
--- a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
+++ b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
@@ -120,10 +120,10 @@ ScheduleDAGInstrs::ScheduleDAGInstrs(MachineFunction &mf,
   SchedModel.init(&ST, EnableSchedModel, EnableSchedItins);
 }
 
-/// If this machine instr has memory reference information and it can be
-/// tracked to a normal reference to a known object, return the Value
-/// for that object. This function returns false the memory location is
-/// unknown or may alias anything.
+/// If this machine instruction has memory reference information, collect the
+/// list of underlying objects in \p Objects. If any of these objects are
+/// unknown or may alias anything, return false. Atomic and volatile memory
+/// operands are skipped.
 static bool getUnderlyingObjectsForInstr(const MachineInstr *MI,
                                          const MachineFrameInfo &MFI,
                                          UnderlyingObjectsVector &Objects,
@@ -149,7 +149,7 @@ static bool getUnderlyingObjectsForInstr(const MachineInstr *MI,
       // For now, ignore PseudoSourceValues which may alias LLVM IR values
       // because the code that uses this function has no way to cope with
       // such aliases.
-      if (PSV->isAliased(&MFI))
+      else if (PSV->isAliased(&MFI))
         AllObjectsIdentified = false;
 
       Objects.push_back(PSV);

>From 0bca8b4d80527af6adce35cad81f146c4cee772d Mon Sep 17 00:00:00 2001
From: Nathan Corbyn <n_corbyn at apple.com>
Date: Tue, 22 Sep 2026 14:11:08 +0100
Subject: [PATCH 3/4] Reformat

---
 llvm/lib/CodeGen/ScheduleDAGInstrs.cpp | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
index f5672bf26e2df..fc943e437251d 100644
--- a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
+++ b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
@@ -138,19 +138,19 @@ static bool getUnderlyingObjectsForInstr(const MachineInstr *MI,
     }
 
     if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) {
-      // Function that contain tail calls don't have unique PseudoSourceValue
-      // objects. Two PseudoSourceValues might refer to the same or
-      // overlapping locations. The client code calling this function assumes
-      // this is not the case. So return a conservative answer of no known
-      // object.
-      if (MFI.hasTailCall())
+      if (MFI.hasTailCall()) {
+        // Function that contain tail calls don't have unique PseudoSourceValue
+        // objects. Two PseudoSourceValues might refer to the same or
+        // overlapping locations. The client code calling this function assumes
+        // this is not the case. So return a conservative answer of no known
+        // object.
         AllObjectsIdentified = false;
-
-      // For now, ignore PseudoSourceValues which may alias LLVM IR values
-      // because the code that uses this function has no way to cope with
-      // such aliases.
-      else if (PSV->isAliased(&MFI))
+      } else if (PSV->isAliased(&MFI)) {
+        // For now, ignore PseudoSourceValues which may alias LLVM IR values
+        // because the code that uses this function has no way to cope with such
+        // aliases.
         AllObjectsIdentified = false;
+      }
 
       Objects.push_back(PSV);
     } else if (const Value *V = MMO->getValue()) {

>From 8920e38fd7bbf9e4bde237d6845c4ba8134a1dfc Mon Sep 17 00:00:00 2001
From: Nathan Corbyn <n_corbyn at apple.com>
Date: Wed, 23 Sep 2026 11:20:51 +0100
Subject: [PATCH 4/4] Fixups

---
 llvm/lib/CodeGen/ScheduleDAGInstrs.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
index fc943e437251d..506887734c749 100644
--- a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
+++ b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
@@ -155,14 +155,16 @@ static bool getUnderlyingObjectsForInstr(const MachineInstr *MI,
       Objects.push_back(PSV);
     } else if (const Value *V = MMO->getValue()) {
       SmallVector<Value *, 4> Objs;
-      AllObjectsIdentified &= getUnderlyingObjectsForCodeGen(V, Objs);
+      bool ObjectsIdentified = getUnderlyingObjectsForCodeGen(V, Objs);
+      AllObjectsIdentified &= ObjectsIdentified;
 
       for (Value *V : Objs) {
-        assert(!AllObjectsIdentified || isIdentifiedObject(V));
+        assert(!ObjectsIdentified || isIdentifiedObject(V));
         Objects.push_back(V);
       }
-    } else
+    } else {
       AllObjectsIdentified = false;
+    }
   }
 
   return AllObjectsIdentified;



More information about the llvm-commits mailing list