Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion llvm/include/llvm/Analysis/MemorySSAUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ class MemorySSAUpdater {
/// inaccessible and it *must* have removeMemoryAccess called on it.
MemoryAccess *createMemoryAccessInBB(Instruction *I, MemoryAccess *Definition,
const BasicBlock *BB,
MemorySSA::InsertionPlace Point);
MemorySSA::InsertionPlace Point,
bool CreationMustSucceed = true);

/// Create a MemoryAccess in MemorySSA before an existing MemoryAccess.
///
Expand Down
8 changes: 5 additions & 3 deletions llvm/lib/Analysis/MemorySSAUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,9 +1403,11 @@ void MemorySSAUpdater::changeToUnreachable(const Instruction *I) {

MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB(
Instruction *I, MemoryAccess *Definition, const BasicBlock *BB,
MemorySSA::InsertionPlace Point) {
MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess(I, Definition);
MSSA->insertIntoListsForBlock(NewAccess, BB, Point);
MemorySSA::InsertionPlace Point, bool CreationMustSucceed) {
MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess(
I, Definition, /*Template=*/nullptr, CreationMustSucceed);
if (NewAccess)
MSSA->insertIntoListsForBlock(NewAccess, BB, Point);
return NewAccess;
}

Expand Down
5 changes: 4 additions & 1 deletion llvm/lib/Transforms/Scalar/LICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,8 +1465,11 @@ static Instruction *cloneInstructionInExitBlock(

if (MSSAU.getMemorySSA()->getMemoryAccess(&I)) {
// Create a new MemoryAccess and let MemorySSA set its defining access.
// After running some passes, MemorySSA might be outdated, and the
// instruction `I` may have become a non-memory touching instruction.
MemoryAccess *NewMemAcc = MSSAU.createMemoryAccessInBB(
New, nullptr, New->getParent(), MemorySSA::Beginning);
New, nullptr, New->getParent(), MemorySSA::Beginning,
/*CreationMustSucceed=*/false);
if (NewMemAcc) {
if (auto *MemDef = dyn_cast<MemoryDef>(NewMemAcc))
MSSAU.insertDef(MemDef, /*RenameUses=*/true);
Expand Down
24 changes: 24 additions & 0 deletions llvm/test/Transforms/LICM/PR116813-memoryssa-outdated.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>),print<memoryssa>' -verify-memoryssa -disable-output -S < %s 2>&1 | FileCheck %s
; RUN: opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>,licm)' -verify-memoryssa -disable-output -S

; Check that SimpleLoopUnswitch preserves the MemoryDef of `call i32 @bar()`.
; Also, check that running LICM after SimpleLoopUnswitch does not result in a crash.

; CHECK: preds = %bb2{{$}}
; CHECK-NEXT: MemoryDef
; CHECK-NEXT: call i32 @bar()

define i32 @foo(i1 %arg, ptr %arg1) {
bb:
br label %bb2

bb2: ; preds = %bb2, %bb
%i = select i1 %arg, ptr %arg1, ptr @bar
%i3 = call i32 %i()
br i1 %arg, label %bb2, label %bb4

bb4: ; preds = %bb2
ret i32 %i3
}

declare i32 @bar() nounwind willreturn memory(none)
Loading