[llvm] [GVN] Look through select/phi when determining underlying object (PR #99509)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 22 02:10:34 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;
----------------
nikic wrote:

I feel like that's harder to follow than the current logic :(

I pushed a possible variant at https://github.com/llvm/llvm-project/pull/99509/commits/f160e9ca0887ac18e60890848a9909b62e54ffa2, which does repeat the getUnderlyingObject() call, but only in the case where FirstObject is actually needed. Maybe this is fine?

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


More information about the llvm-commits mailing list