[llvm] d64a0a9 - [ValueTracking] Make `getUnderlyingObjectsForCodegen()` preserve unidentified objects (#224584)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 21 04:50:02 PDT 2026
Author: Nathan Corbyn
Date: 2026-09-21T12:49:57+01:00
New Revision: d64a0a9effc7704962e21ede22eb0f5ba24e4390
URL: https://github.com/llvm/llvm-project/commit/d64a0a9effc7704962e21ede22eb0f5ba24e4390
DIFF: https://github.com/llvm/llvm-project/commit/d64a0a9effc7704962e21ede22eb0f5ba24e4390.diff
LOG: [ValueTracking] Make `getUnderlyingObjectsForCodegen()` preserve unidentified objects (#224584)
In some situations, it is useful to inspect the underlying objects of a
memory operation, even if they may alias with one another. A concrete
example comes from the approach to schedule DAG construction I've been
developing (see #205689) where these objects are used to infer that a
class of control dependencies between memory operations is redundant,
whereby eliminating the compile time cost of recording them. Update
`getUnderlyingObjectsForCodegen()` to return these objects.
Split from https://github.com/llvm/llvm-project/pull/205689
Added:
Modified:
llvm/include/llvm/Analysis/ValueTracking.h
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/CodeGen/StackColoring.cpp
llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h
index 43dd1bbafbc49..965b69cae0db0 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -531,6 +531,10 @@ LLVM_ABI void getUnderlyingObjects(const Value *V,
/// This is a wrapper around getUnderlyingObjects and adds support for basic
/// ptrtoint+arithmetic+inttoptr sequences.
+///
+/// Return true if each of the underlying objects is identified. \p Objects is
+/// never cleared, so may contain unidentified objects when the return value is
+/// false.
LLVM_ABI bool getUnderlyingObjectsForCodeGen(const Value *V,
SmallVectorImpl<Value *> &Objects);
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index fbd57012d1a4f..1286130cf5d94 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -7467,6 +7467,7 @@ bool llvm::getUnderlyingObjectsForCodeGen(const Value *V,
SmallVectorImpl<Value *> &Objects) {
SmallPtrSet<const Value *, 16> Visited;
SmallVector<const Value *, 4> Working(1, V);
+ bool AllObjectsIdentified = true;
do {
V = Working.pop_back_val();
@@ -7484,16 +7485,11 @@ bool llvm::getUnderlyingObjectsForCodeGen(const Value *V,
continue;
}
}
- // If getUnderlyingObjects fails to find an identifiable object,
- // getUnderlyingObjectsForCodeGen also fails for safety.
- if (!isIdentifiedObject(V)) {
- Objects.clear();
- return false;
- }
+ AllObjectsIdentified &= isIdentifiedObject(V);
Objects.push_back(const_cast<Value *>(V));
}
} while (!Working.empty());
- return true;
+ return AllObjectsIdentified;
}
AllocaInst *llvm::findAllocaForValue(Value *V, bool OffsetZero) {
diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp
index 0e4c1526d0d0b..81e4e1bfdefbf 100644
--- a/llvm/lib/CodeGen/StackColoring.cpp
+++ b/llvm/lib/CodeGen/StackColoring.cpp
@@ -1070,9 +1070,8 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
if (MMO->getAAInfo()) {
if (const Value *MMOV = MMO->getValue()) {
SmallVector<Value *, 4> Objs;
- getUnderlyingObjectsForCodeGen(MMOV, Objs);
- if (Objs.empty())
+ if (!getUnderlyingObjectsForCodeGen(MMOV, Objs) || Objs.empty())
MayHaveConflictingAAMD = true;
else
for (Value *V : Objs) {
diff --git a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
index 9664773e2d0f4..13933460dce1e 100644
--- a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
+++ b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
@@ -354,8 +354,11 @@ void MemoryOpRemark::visitVariable(const Value *V,
void MemoryOpRemark::visitPtr(Value *Ptr, bool IsRead, DiagnosticInfoIROptimization &R) {
// Find if Ptr is a known variable we can give more information on.
SmallVector<Value *, 2> Objects;
- getUnderlyingObjectsForCodeGen(Ptr, Objects);
SmallVector<VariableInfo, 2> VIs;
+
+ if (!getUnderlyingObjectsForCodeGen(Ptr, Objects))
+ Objects.clear();
+
for (const Value *V : Objects)
visitVariable(V, VIs);
More information about the llvm-commits
mailing list