[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
================
@@ -1016,11 +1017,18 @@ struct DSEState {
// Treat byval, inalloca or dead on return arguments the same as Allocas,
// stores to them are dead at the end of the function.
- for (Argument &AI : F.args())
+ for (Argument &AI : F.args()) {
if (AI.hasPassPointeeByValueCopyAttr() ||
(AI.getType()->isPointerTy() &&
AI.getDeadOnReturnInfo().coversAllReachableMemory()))
InvisibleToCallerAfterRet.insert({&AI, true});
+ if (AI.getType()->isPointerTy() &&
+ !AI.getDeadOnReturnInfo().coversAllReachableMemory()) {
+ if (uint64_t DeadOnReturnBytes =
+ AI.getDeadOnReturnInfo().getNumberOfDeadBytes())
+ InvisibleToCallerAfterRetBounded.insert({&AI, DeadOnReturnBytes});
+ }
+ }
----------------
antoniofrighetto wrote:
Perhaps the code could be reordered a bit here, I'd favour readability:
```cpp
for (Argument &AI : F.args()) {
if (AI.hasPassPointeeByValueCopyAttr()) {
InvisibleToCallerAfterRet.insert({&AI, true});
continue;
}
if (!AI.getType()->isPointerTy())
continue;
const auto &Info = AI.getDeadOnReturnInfo();
if (Info.coversAllReachableMemory())
InvisibleToCallerAfterRet.insert({&AI, true});
else if (uint64_t DeadBytes = Info.getNumberOfDeadBytes())
InvisibleToCallerAfterRetBounded.insert({&AI, DeadBytes});
}
```
https://github.com/llvm/llvm-project/pull/173694
More information about the llvm-branch-commits
mailing list