Skip to content

Commit 81d69e1

Browse files
committed
[DSE] Call isRemovable() after getLocForWriteEx() (NFCI)
The only non-trivial change here is that the isReadClobber() check for redundant stores is now on the DefLoc, not the UpperLoc. This is semantically the right location to use, though in practice it makes no difference (the locations are either the same, or the def inst does not read).
1 parent ea2d4c5 commit 81d69e1

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,12 +1672,12 @@ struct DSEState {
16721672
dbgs()
16731673
<< "Trying to eliminate MemoryDefs at the end of the function\n");
16741674
for (MemoryDef *Def : llvm::reverse(MemDefs)) {
1675-
if (SkipStores.contains(Def) || !isRemovable(Def->getMemoryInst()))
1675+
if (SkipStores.contains(Def))
16761676
continue;
16771677

16781678
Instruction *DefI = Def->getMemoryInst();
16791679
auto DefLoc = getLocForWriteEx(DefI);
1680-
if (!DefLoc)
1680+
if (!DefLoc || !isRemovable(DefI))
16811681
continue;
16821682

16831683
// NOTE: Currently eliminating writes at the end of a function is limited
@@ -1866,9 +1866,14 @@ struct DSEState {
18661866
LLVM_DEBUG(dbgs() << "Trying to eliminate MemoryDefs that write the "
18671867
"already existing value\n");
18681868
for (auto *Def : MemDefs) {
1869-
if (SkipStores.contains(Def) || MSSA.isLiveOnEntryDef(Def) ||
1870-
!isRemovable(Def->getMemoryInst()))
1869+
if (SkipStores.contains(Def) || MSSA.isLiveOnEntryDef(Def))
18711870
continue;
1871+
1872+
Instruction *DefInst = Def->getMemoryInst();
1873+
auto MaybeDefLoc = getLocForWriteEx(DefInst);
1874+
if (!MaybeDefLoc || !isRemovable(DefInst))
1875+
return false;
1876+
18721877
MemoryDef *UpperDef;
18731878
// To conserve compile-time, we avoid walking to the next clobbering def.
18741879
// Instead, we just try to get the optimized access, if it exists. DSE
@@ -1880,17 +1885,14 @@ struct DSEState {
18801885
if (!UpperDef || MSSA.isLiveOnEntryDef(UpperDef))
18811886
continue;
18821887

1883-
Instruction *DefInst = Def->getMemoryInst();
18841888
Instruction *UpperInst = UpperDef->getMemoryInst();
1885-
auto IsRedundantStore = [this, DefInst,
1886-
UpperInst](MemoryLocation UpperLoc) {
1889+
auto IsRedundantStore = [&]() {
18871890
if (DefInst->isIdenticalTo(UpperInst))
18881891
return true;
18891892
if (auto *MemSetI = dyn_cast<MemSetInst>(UpperInst)) {
18901893
if (auto *SI = dyn_cast<StoreInst>(DefInst)) {
1891-
auto MaybeDefLoc = getLocForWriteEx(DefInst);
1892-
if (!MaybeDefLoc)
1893-
return false;
1894+
// MemSetInst must have a write location.
1895+
MemoryLocation UpperLoc = *getLocForWriteEx(UpperInst);
18941896
int64_t InstWriteOffset = 0;
18951897
int64_t DepWriteOffset = 0;
18961898
auto OR = isOverwrite(UpperInst, DefInst, UpperLoc, *MaybeDefLoc,
@@ -1903,9 +1905,7 @@ struct DSEState {
19031905
return false;
19041906
};
19051907

1906-
auto MaybeUpperLoc = getLocForWriteEx(UpperInst);
1907-
if (!MaybeUpperLoc || !IsRedundantStore(*MaybeUpperLoc) ||
1908-
isReadClobber(*MaybeUpperLoc, DefInst))
1908+
if (!IsRedundantStore() || isReadClobber(*MaybeDefLoc, DefInst))
19091909
continue;
19101910
LLVM_DEBUG(dbgs() << "DSE: Remove No-Op Store:\n DEAD: " << *DefInst
19111911
<< '\n');

0 commit comments

Comments
 (0)