[llvm] [DSE] Apply initializes attribute to DSE (PR #107282)

Haopeng Liu via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 23 22:06:22 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()".
----------------
haopliu wrote:

`IsDeadOrInvisibleOnUnwind` is per argument nounwind. 
`getIntersectedInitRangeList` considers  `IsDeadOrInvisibleOnUnwind` per argument and CB->doesNotThrow() together.

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


More information about the llvm-commits mailing list