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

Tomer Shafir via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 00:46:20 PDT 2026


================
@@ -120,57 +120,52 @@ 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,
                                          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;
+  bool AllObjectsIdentified = true;
 
-      if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) {
+  for (const MachineMemOperand *MMO : MI->memoperands()) {
+    // TODO: Figure out whether isAtomic is really necessary (see D57601).
+    if (MMO->isVolatile() || MMO->isAtomic()) {
+      AllObjectsIdentified = false;
+      continue;
+    }
+
+    if (const PseudoSourceValue *PSV = MMO->getPseudoValue()) {
+      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.
-        if (MFI.hasTailCall())
-          return false;
-
+        AllObjectsIdentified = false;
+      } 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.
-        if (PSV->isAliased(&MFI))
-          return false;
-
-        Objects.push_back(PSV);
-      } else if (const Value *V = MMO->getValue()) {
-        SmallVector<Value *, 4> Objs;
-        if (!getUnderlyingObjectsForCodeGen(V, Objs))
-          return false;
+        // because the code that uses this function has no way to cope with such
+        // aliases.
+        AllObjectsIdentified = false;
+      }
 
-        for (Value *V : Objs) {
-          assert(isIdentifiedObject(V));
-          Objects.push_back(V);
-        }
-      } else
-        return false;
-    }
-    return true;
-  };
+      Objects.push_back(PSV);
+    } else if (const Value *V = MMO->getValue()) {
+      SmallVector<Value *, 4> Objs;
+      AllObjectsIdentified &= getUnderlyingObjectsForCodeGen(V, Objs);
 
-  if (!AllMMOsOkay()) {
-    Objects.clear();
-    return false;
+      for (Value *V : Objs) {
+        assert(!AllObjectsIdentified || isIdentifiedObject(V));
+        Objects.push_back(V);
+      }
+    } else
----------------
tomershafir wrote:

Add missing braces to be consistent with the parent if

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


More information about the llvm-commits mailing list