[PATCH] D112321: [DSE] Support redundant stores eliminated by memset.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 29 14:21:04 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG274a9b0f0b4e: [DSE] Support redundant stores eliminated by memset. (authored by fhahn).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D112321/new/
https://reviews.llvm.org/D112321
Files:
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll
Index: llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll
===================================================================
--- llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll
+++ llvm/test/Transforms/DeadStoreElimination/stores-of-existing-values.ll
@@ -403,8 +403,6 @@
define void @test12_memset_simple(i8* %ptr) {
; CHECK-LABEL: @test12_memset_simple(
; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* [[PTR:%.*]], i8 0, i64 10, i1 false)
-; CHECK-NEXT: [[PTR_5:%.*]] = getelementptr i8, i8* [[PTR]], i64 4
-; CHECK-NEXT: store i8 0, i8* [[PTR_5]], align 1
; CHECK-NEXT: ret void
;
call void @llvm.memset.p0i8.i64(i8* %ptr, i8 0, i64 10, i1 false)
Index: llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -1955,10 +1955,32 @@
auto *UpperDef = dyn_cast<MemoryDef>(Def->getDefiningAccess());
if (!UpperDef || MSSA.isLiveOnEntryDef(UpperDef))
continue;
- auto *DefInst = Def->getMemoryInst();
- auto *UpperInst = UpperDef->getMemoryInst();
+
+ Instruction *DefInst = Def->getMemoryInst();
+ Instruction *UpperInst = UpperDef->getMemoryInst();
+ auto IsRedundantStore = [this, DefInst,
+ UpperInst](MemoryLocation UpperLoc) {
+ if (DefInst->isIdenticalTo(UpperInst))
+ return true;
+ if (auto *MemSetI = dyn_cast<MemSetInst>(UpperInst)) {
+ if (auto *SI = dyn_cast<StoreInst>(DefInst)) {
+ auto MaybeDefLoc = getLocForWriteEx(DefInst);
+ if (!MaybeDefLoc)
+ return false;
+ int64_t InstWriteOffset = 0;
+ int64_t DepWriteOffset = 0;
+ auto OR = isOverwrite(UpperInst, DefInst, UpperLoc, *MaybeDefLoc,
+ InstWriteOffset, DepWriteOffset);
+ Value *StoredByte = isBytewiseValue(SI->getValueOperand(), DL);
+ return StoredByte && StoredByte == MemSetI->getOperand(1) &&
+ OR == OW_Complete;
+ }
+ }
+ return false;
+ };
+
auto MaybeUpperLoc = getLocForWriteEx(UpperInst);
- if (!MaybeUpperLoc || !DefInst->isIdenticalTo(UpperInst) ||
+ if (!MaybeUpperLoc || !IsRedundantStore(*MaybeUpperLoc) ||
isReadClobber(*MaybeUpperLoc, DefInst))
continue;
LLVM_DEBUG(dbgs() << "DSE: Remove No-Op Store:\n DEAD: " << *DefInst
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112321.383498.patch
Type: text/x-patch
Size: 2583 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211029/15a0844a/attachment.bin>
More information about the llvm-commits
mailing list