[llvm-branch-commits] [llvm] [DSE] Make DSE eliminate stores to objects with a sized dead_on_return (PR #173694)

Antonio Frighetto via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 14 08:05:56 PST 2026


================
@@ -1206,11 +1214,21 @@ struct DSEState {
     return OW_None;
   }
 
-  bool isInvisibleToCallerAfterRet(const Value *V) {
+  bool isInvisibleToCallerAfterRet(const Value *V, const Value *Ptr,
+                                   const LocationSize StoreSize) {
     if (isa<AllocaInst>(V))
       return true;
 
     auto I = InvisibleToCallerAfterRet.insert({V, false});
+    if (I.second && InvisibleToCallerAfterRetBounded.contains(V)) {
+      int64_t ValueOffset;
+      const Value *BaseValue =
+          GetPointerBaseWithConstantOffset(Ptr, ValueOffset, DL);
+      assert(BaseValue == V);
+      if (ValueOffset + StoreSize.toRaw() <
+          InvisibleToCallerAfterRetBounded[BaseValue])
----------------
antoniofrighetto wrote:

Should use getValue() instead (don't think it's necessary to check isPrecise() here though).

Also, the store may still be eliminated with `<=`, right? (E.g., a store at offset 0 with size 8 and dead_on_return(8)).

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


More information about the llvm-branch-commits mailing list