[llvm] [DSE] Apply initializes attribute to DSE (PR #107282)
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 22 10:16:53 PDT 2024
================
@@ -2181,6 +2263,75 @@ struct DSEState {
bool eliminateDeadDefs(const MemoryDefWrapper &KillingDefWrapper);
};
+SmallVector<MemoryLocation, 1>
+DSEState::getInitializesArgMemLoc(const Instruction *I) {
+ const CallBase *CB = dyn_cast<CallBase>(I);
+ if (!CB)
+ return {};
+
+ // Collect aliasing arguments and their initializes ranges.
+ SmallMapVector<Value *, SmallVector<ArgumentInitInfo, 2>, 2> Arguments;
+ for (unsigned Idx = 0, Count = CB->arg_size(); Idx < Count; ++Idx) {
+ ConstantRangeList Inits;
+ Attribute InitializesAttr = CB->getParamAttr(Idx, Attribute::Initializes);
+ if (InitializesAttr.isValid())
+ Inits = InitializesAttr.getValueAsConstantRangeList();
+
+ Value *CurArg = CB->getArgOperand(Idx);
+ // We don't perform incorrect DSE on unwind edges in the current function,
+ // and use the "initializes" attribute to kill dead stores if:
+ // - The call does not throw exceptions, "CB->doesNotThrow()".
+ // - Or the callee parameter has "dead_on_unwind" attribute.
+ // - Or the argument is invisible to caller on unwind, and CB isa<CallInst>
+ // which means no unwind edges from this call in the current function.
----------------
aeubanks wrote:
I haven't heard the term "pure function call" refer to a call that doesn't unwind, I prefer something closer to the current version.
```
Or the argument is invisible to caller on unwind, and there are no unwind edges from this call in the current function (e.g. `CallInst`).
```
There are probably (?) more cases than just `CallInst` where we do this optimization so I use `e.g.` instead of `i.e.`.
https://github.com/llvm/llvm-project/pull/107282
More information about the llvm-commits
mailing list