[llvm] Improvements to RS4GC BDV Algorithm (PR #69795)

via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 24 07:37:38 PDT 2023


================
@@ -1012,8 +1012,44 @@ static Value *findBasePointer(Value *I, DefiningValueMapTy &Cache,
   }
 #endif
 
-  // Handle all instructions that have a vector BDV, but the instruction itself
-  // is of scalar type.
+  // Even though we have identified a concrete base (or a conflict) for all live
+  // pointers at this point, there are cases where the base is of an
+  // incompatible type compared to the original instruction. We conservatively
+  // mark those as conflicts to ensure that corresponding BDVs will be generated
+  // in the next steps
+
+  // this is a rather explicit check for all cases where we should mark the
+  // state as a conflict to force the latter stages of the algorithm to emit
+  // the BDVs. Note that the IE and EE instruction check is not fully subsumed
+  // by the vector<->scalar check at the end, this is due to the BDV algorithm
+  // being ignorant of BDV types at this junction
+  // TODO: in many cases the instructions emited for the conflicting states
+  // will be identical to the I itself (if the I's operate on their BDVs
+  // themselves). We should expoit this, but can't do it here since it would
+  // break the invariant about the BDVs not being known to be a base.
+  // TODO: the code also does not handle constants at all - the algithm relies
+  // on all constants having the same BDV and therefore constant-only insns
+  // will never be in conflict, but this check is ignored here. If the
+  // constant conflicts will be to BDVs themselves, they will be identical
+  // instructions and will get optimized away (as in the above TODO)
+  auto MarkConflict = [&](Instruction *I, Value *BaseValue) {
+    // II mixes vector & scalar so is always a conflict
+    if (isa<InsertElementInst>(I))
+      return true;
+    // EE mixes vector and scalar so is always conflict
+    if (isa<ExtractElementInst>(I))
+      return true;
+    // shuffle vector is always conflict as it creates new vector from existing
----------------
annamthomas wrote:

```suggestion
    // Shuffle vector is always a conflict as it creates new vector from existing
```

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


More information about the llvm-commits mailing list