[llvm] [GVN] Drop Clobber dependency if store may overwrite only the same value (PR #68322)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 9 05:59:33 PDT 2023
================
@@ -360,11 +360,43 @@ MemoryDependenceResults::getInvariantGroupPointerDependency(LoadInst *LI,
return MemDepResult::getNonLocal();
}
+// Check if SI that may alias with MemLoc can be safely skipped. This is
+// possible in case if SI can only must alias or no alias with MemLoc (no
+// partial overlapping possible) and it writes the same value that MemLoc
+// contains now (it was loaded before this store and was not modified in
+// between).
+static bool canSkipClobberingStore(const StoreInst *SI,
+ const MemoryLocation &MemLoc,
+ Align MemLocAlign, BatchAAResults &BatchAA,
+ unsigned ScanLimit) {
+ if (!MemLoc.Size.hasValue())
+ return false;
+ if (MemoryLocation::get(SI).Size != MemLoc.Size)
+ return false;
+ if (std::min(MemLocAlign, SI->getAlign()).value() < MemLoc.Size.getValue())
+ return false;
+
+ auto *LI = dyn_cast<LoadInst>(SI->getValueOperand());
+ if (!LI || LI->getParent() != SI->getParent())
+ return false;
+ if (BatchAA.alias(MemoryLocation::get(LI), MemLoc) != AliasResult::MustAlias)
+ return false;
+ unsigned NumVisitedInsts = 0;
+ for (const auto *I = LI->getNextNode(); I != SI; I = I->getNextNode())
+ if (++NumVisitedInsts > ScanLimit ||
----------------
nikic wrote:
We should skip DbgInfoIntrinsics here and not count them towards the limit, to avoid codegen diff with `-g`.
https://github.com/llvm/llvm-project/pull/68322
More information about the llvm-commits
mailing list