@@ -1672,12 +1672,12 @@ struct DSEState {
1672
1672
dbgs ()
1673
1673
<< " Trying to eliminate MemoryDefs at the end of the function\n " );
1674
1674
for (MemoryDef *Def : llvm::reverse (MemDefs)) {
1675
- if (SkipStores.contains (Def) || ! isRemovable (Def-> getMemoryInst ()) )
1675
+ if (SkipStores.contains (Def))
1676
1676
continue ;
1677
1677
1678
1678
Instruction *DefI = Def->getMemoryInst ();
1679
1679
auto DefLoc = getLocForWriteEx (DefI);
1680
- if (!DefLoc)
1680
+ if (!DefLoc || ! isRemovable (DefI) )
1681
1681
continue ;
1682
1682
1683
1683
// NOTE: Currently eliminating writes at the end of a function is limited
@@ -1866,9 +1866,14 @@ struct DSEState {
1866
1866
LLVM_DEBUG (dbgs () << " Trying to eliminate MemoryDefs that write the "
1867
1867
" already existing value\n " );
1868
1868
for (auto *Def : MemDefs) {
1869
- if (SkipStores.contains (Def) || MSSA.isLiveOnEntryDef (Def) ||
1870
- !isRemovable (Def->getMemoryInst ()))
1869
+ if (SkipStores.contains (Def) || MSSA.isLiveOnEntryDef (Def))
1871
1870
continue ;
1871
+
1872
+ Instruction *DefInst = Def->getMemoryInst ();
1873
+ auto MaybeDefLoc = getLocForWriteEx (DefInst);
1874
+ if (!MaybeDefLoc || !isRemovable (DefInst))
1875
+ return false ;
1876
+
1872
1877
MemoryDef *UpperDef;
1873
1878
// To conserve compile-time, we avoid walking to the next clobbering def.
1874
1879
// Instead, we just try to get the optimized access, if it exists. DSE
@@ -1880,17 +1885,14 @@ struct DSEState {
1880
1885
if (!UpperDef || MSSA.isLiveOnEntryDef (UpperDef))
1881
1886
continue ;
1882
1887
1883
- Instruction *DefInst = Def->getMemoryInst ();
1884
1888
Instruction *UpperInst = UpperDef->getMemoryInst ();
1885
- auto IsRedundantStore = [this , DefInst,
1886
- UpperInst](MemoryLocation UpperLoc) {
1889
+ auto IsRedundantStore = [&]() {
1887
1890
if (DefInst->isIdenticalTo (UpperInst))
1888
1891
return true ;
1889
1892
if (auto *MemSetI = dyn_cast<MemSetInst>(UpperInst)) {
1890
1893
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);
1894
1896
int64_t InstWriteOffset = 0 ;
1895
1897
int64_t DepWriteOffset = 0 ;
1896
1898
auto OR = isOverwrite (UpperInst, DefInst, UpperLoc, *MaybeDefLoc,
@@ -1903,9 +1905,7 @@ struct DSEState {
1903
1905
return false ;
1904
1906
};
1905
1907
1906
- auto MaybeUpperLoc = getLocForWriteEx (UpperInst);
1907
- if (!MaybeUpperLoc || !IsRedundantStore (*MaybeUpperLoc) ||
1908
- isReadClobber (*MaybeUpperLoc, DefInst))
1908
+ if (!IsRedundantStore () || isReadClobber (*MaybeDefLoc, DefInst))
1909
1909
continue ;
1910
1910
LLVM_DEBUG (dbgs () << " DSE: Remove No-Op Store:\n DEAD: " << *DefInst
1911
1911
<< ' \n ' );
0 commit comments