forked from OSchip/llvm-project
[MemorySSA] Rename uses in blocks with Phis.
Renaming should include blocks with existing Phis. Resolves PR45927. Differential Revision: https://reviews.llvm.org/D87661
This commit is contained in:
parent
e30371d99d
commit
344a3d0bc0
|
@ -342,6 +342,8 @@ void MemorySSAUpdater::insertDef(MemoryDef *MD, bool RenameUses) {
|
|||
|
||||
SmallVector<WeakVH, 8> FixupList(InsertedPHIs.begin(), InsertedPHIs.end());
|
||||
|
||||
SmallSet<WeakVH, 8> ExistingPhis;
|
||||
|
||||
// Remember the index where we may insert new phis.
|
||||
unsigned NewPhiIndex = InsertedPHIs.size();
|
||||
if (!DefBeforeSameBlock) {
|
||||
|
@ -382,6 +384,8 @@ void MemorySSAUpdater::insertDef(MemoryDef *MD, bool RenameUses) {
|
|||
if (!MPhi) {
|
||||
MPhi = MSSA->createMemoryPhi(BBIDF);
|
||||
NewInsertedPHIs.push_back(MPhi);
|
||||
} else {
|
||||
ExistingPhis.insert(MPhi);
|
||||
}
|
||||
// Add the phis created into the IDF blocks to NonOptPhis, so they are not
|
||||
// optimized out as trivial by the call to getPreviousDefFromEnd below.
|
||||
|
@ -447,6 +451,13 @@ void MemorySSAUpdater::insertDef(MemoryDef *MD, bool RenameUses) {
|
|||
if (Phi)
|
||||
MSSA->renamePass(Phi->getBlock(), nullptr, Visited);
|
||||
}
|
||||
// Existing Phi blocks may need renaming too, if an access was previously
|
||||
// optimized and the inserted Defs "covers" the Optimized value.
|
||||
for (auto &MP : ExistingPhis) {
|
||||
MemoryPhi *Phi = dyn_cast_or_null<MemoryPhi>(MP);
|
||||
if (Phi)
|
||||
MSSA->renamePass(Phi->getBlock(), nullptr, Visited);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1322,6 +1333,7 @@ void MemorySSAUpdater::removeMemoryAccess(MemoryAccess *MA, bool OptimizePhis) {
|
|||
// Note: We assume MemorySSA is not used in metadata since it's not really
|
||||
// part of the IR.
|
||||
|
||||
assert(NewDefTarget != MA && "Going into an infinite loop");
|
||||
while (!MA->use_empty()) {
|
||||
Use &U = *MA->use_begin();
|
||||
if (auto *MUD = dyn_cast<MemoryUseOrDef>(U.getUser()))
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
; RUN: opt -disable-output -loop-simplify -lcssa -licm -print-memoryssa < %s 2>&1 | FileCheck %s
|
||||
; RUN: opt -disable-output -aa-pipeline=basic-aa -passes='loop-mssa(licm),print<memoryssa>' < %s 2>&1 | FileCheck %s
|
||||
|
||||
|
||||
@a = external dso_local global i16, align 1
|
||||
@c = external dso_local global i16, align 1
|
||||
|
||||
; CHECK-LABEL: @main()
|
||||
|
||||
; CHECK: entry:
|
||||
; CHECK-NEXT: %res.addr.i = alloca i16
|
||||
; CHECK-NEXT: ; MemoryUse(liveOnEntry)
|
||||
; CHECK-NEXT: %c.promoted = load i16, i16* @c
|
||||
; CHECK-NEXT: br label %for.cond.i
|
||||
|
||||
; CHECK: for.cond.i:
|
||||
; CHECK-NEXT: ; [[NO5:.*]] = MemoryPhi({entry,liveOnEntry},{f.exit.i,[[NO5]]})
|
||||
; CHECK-NEXT: %inc.i1 = phi i16 [ %inc.i, %f.exit.i ], [ %c.promoted, %entry ]
|
||||
; CHECK-NEXT: %inc.i = add nsw i16 %inc.i1, 1
|
||||
; CHECK-NEXT: br i1 false, label %f.exit.thread.i, label %f.exit.i
|
||||
|
||||
; CHECK: f.exit.thread.i:
|
||||
; CHECK-NEXT: %inc.i.lcssa = phi i16 [ %inc.i, %for.cond.i ]
|
||||
; CHECK-NEXT: ; [[NO6:.*]] = MemoryDef([[NO5]])
|
||||
; CHECK-NEXT: store i16 %inc.i.lcssa, i16* @c, align 1
|
||||
; CHECK-NEXT: ; [[NO2:.*]] = MemoryDef([[NO6]])
|
||||
; CHECK-NEXT: store i16 1, i16* @a, align 1
|
||||
; CHECK-NEXT: ; MemoryUse([[NO2]])
|
||||
; CHECK-NEXT: %tmp2 = load i16, i16* @c, align 1
|
||||
; CHECK-NEXT: br label %g.exit
|
||||
|
||||
; CHECK: f.exit.i
|
||||
; CHECK-NEXT: br i1 false, label %g.exit.loopexit, label %for.cond.i
|
||||
|
||||
; CHECK: g.exit.loopexit:
|
||||
; CHECK-NEXT: %inc.i.lcssa2 = phi i16 [ %inc.i, %f.exit.i ]
|
||||
; CHECK-NEXT: ; [[NO7:.*]] = MemoryDef([[NO5]])
|
||||
; CHECK-NEXT: store i16 %inc.i.lcssa2, i16* @c, align 1
|
||||
; CHECK-NEXT: br label %g.exit
|
||||
|
||||
; CHECK: g.exit
|
||||
; CHECK-NEXT: ; [[NO4:.*]] = MemoryPhi({f.exit.thread.i,[[NO2]]},{g.exit.loopexit,[[NO7]]})
|
||||
; CHECK-NEXT: ; MemoryUse([[NO4]])
|
||||
; CHECK-NEXT: %tmp1 = load i16, i16* @c, align 1
|
||||
; CHECK-NEXT: ; [[NO3:.*]] = MemoryDef([[NO4]])
|
||||
; CHECK-NEXT: store i16 %tmp1, i16* %res.addr.i, align 1
|
||||
; CHECK-NEXT: ret void
|
||||
|
||||
define dso_local void @main() {
|
||||
entry:
|
||||
%res.addr.i = alloca i16, align 1
|
||||
br label %for.cond.i
|
||||
|
||||
for.cond.i: ; preds = %f.exit.i, %entry
|
||||
%tmp0 = load i16, i16* @c, align 1
|
||||
%inc.i = add nsw i16 %tmp0, 1
|
||||
store i16 %inc.i, i16* @c, align 1
|
||||
br i1 false, label %f.exit.thread.i, label %f.exit.i
|
||||
|
||||
f.exit.thread.i: ; preds = %for.cond.i
|
||||
store i16 1, i16* @a, align 1
|
||||
%tmp2 = load i16, i16* @c, align 1
|
||||
br label %g.exit
|
||||
|
||||
f.exit.i: ; preds = %for.cond.i
|
||||
br i1 false, label %g.exit, label %for.cond.i
|
||||
|
||||
g.exit: ; preds = %f.exit.i, %f.exit.thread.i
|
||||
%tmp1 = load i16, i16* @c, align 1
|
||||
store i16 %tmp1, i16* %res.addr.i, align 1
|
||||
ret void
|
||||
}
|
||||
|
Loading…
Reference in New Issue