[llvm] [DSE] Apply initializes attribute to DSE (PR #107282)
Haopeng Liu via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 23 22:02:18 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.
+ bool IsDeadOrInvisibleOnUnwind =
+ CB->paramHasAttr(Idx, Attribute::DeadOnUnwind) ||
+ (isInvisibleToCallerOnUnwind(CurArg) && isa<CallInst>(CB));
----------------
haopliu wrote:
Done!
https://github.com/llvm/llvm-project/pull/107282
More information about the llvm-commits
mailing list