[llvm] [GVN] Look through select/phi when determining underlying object (PR #99509)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 22 01:43:15 PDT 2024
================
@@ -6609,6 +6609,46 @@ void llvm::getUnderlyingObjects(const Value *V,
} while (!Worklist.empty());
}
+const Value *llvm::getUnderlyingObjectAggressive(const Value *V) {
+ const unsigned MaxVisited = 8;
+
+ SmallPtrSet<const Value *, 8> Visited;
+ SmallVector<const Value *, 8> Worklist;
+ Worklist.push_back(V);
+ const Value *Object = nullptr, *FirstObject = nullptr;
+ do {
+ const Value *P = Worklist.pop_back_val();
+ P = getUnderlyingObject(P);
+
+ if (!FirstObject)
+ FirstObject = P;
----------------
fhahn wrote:
Should we pull this out of the loop if possible?
This would make it clear that we shouldn't end up in a situation where e.g. getUnderlyingObject returns nullptr for the initial pointer, and then we initialize FirstObject with the underlying object for one of the arms of a select and may end up returning an underlying object that just matches one side of the select.
https://github.com/llvm/llvm-project/pull/99509
More information about the llvm-commits
mailing list