Skip to content

Commit f160e9c

Browse files
committed
Refactor FirstObject logic
1 parent 25857e8 commit f160e9c

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6615,19 +6615,18 @@ const Value *llvm::getUnderlyingObjectAggressive(const Value *V) {
66156615
SmallPtrSet<const Value *, 8> Visited;
66166616
SmallVector<const Value *, 8> Worklist;
66176617
Worklist.push_back(V);
6618-
const Value *Object = nullptr, *FirstObject = nullptr;
6618+
const Value *Object = nullptr;
66196619
do {
66206620
const Value *P = Worklist.pop_back_val();
66216621
P = getUnderlyingObject(P);
66226622

6623-
if (!FirstObject)
6624-
FirstObject = P;
6625-
66266623
if (!Visited.insert(P).second)
66276624
continue;
66286625

6629-
if (Visited.size() == MaxVisited)
6630-
return FirstObject;
6626+
if (Visited.size() == MaxVisited) {
6627+
Object = nullptr;
6628+
break;
6629+
}
66316630

66326631
if (auto *SI = dyn_cast<SelectInst>(P)) {
66336632
Worklist.push_back(SI->getTrueValue());
@@ -6642,10 +6641,16 @@ const Value *llvm::getUnderlyingObjectAggressive(const Value *V) {
66426641

66436642
if (!Object)
66446643
Object = P;
6645-
else if (Object != P)
6646-
return FirstObject;
6644+
else if (Object != P) {
6645+
Object = nullptr;
6646+
break;
6647+
}
66476648
} while (!Worklist.empty());
66486649

6650+
// If we tried looking through phi/select but did not end up with a single
6651+
// underlying object, fall back to the non-recursive underlying object of V.
6652+
if (!Object)
6653+
return getUnderlyingObject(V);
66496654
return Object;
66506655
}
66516656

0 commit comments

Comments
 (0)