Skip to content

Commit e553a41

Browse files
committed
[LICM] allow MemoryAccess creation failure
1 parent e6b291a commit e553a41

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

llvm/include/llvm/Analysis/MemorySSAUpdater.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ class MemorySSAUpdater {
190190
/// inaccessible and it *must* have removeMemoryAccess called on it.
191191
MemoryAccess *createMemoryAccessInBB(Instruction *I, MemoryAccess *Definition,
192192
const BasicBlock *BB,
193-
MemorySSA::InsertionPlace Point);
193+
MemorySSA::InsertionPlace Point,
194+
bool CreationMustSucceed = true);
194195

195196
/// Create a MemoryAccess in MemorySSA before an existing MemoryAccess.
196197
///

llvm/lib/Analysis/MemorySSAUpdater.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,9 +1403,11 @@ void MemorySSAUpdater::changeToUnreachable(const Instruction *I) {
14031403

14041404
MemoryAccess *MemorySSAUpdater::createMemoryAccessInBB(
14051405
Instruction *I, MemoryAccess *Definition, const BasicBlock *BB,
1406-
MemorySSA::InsertionPlace Point) {
1407-
MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess(I, Definition);
1408-
MSSA->insertIntoListsForBlock(NewAccess, BB, Point);
1406+
MemorySSA::InsertionPlace Point, bool CreationMustSucceed) {
1407+
MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess(
1408+
I, Definition, /*Template=*/nullptr, CreationMustSucceed);
1409+
if (NewAccess)
1410+
MSSA->insertIntoListsForBlock(NewAccess, BB, Point);
14091411
return NewAccess;
14101412
}
14111413

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1465,8 +1465,11 @@ static Instruction *cloneInstructionInExitBlock(
14651465

14661466
if (MSSAU.getMemorySSA()->getMemoryAccess(&I)) {
14671467
// Create a new MemoryAccess and let MemorySSA set its defining access.
1468+
// After running some passes, MemorySSA might be outdated, and the
1469+
// instruction `I` may have become a non-memory touching instruction.
14681470
MemoryAccess *NewMemAcc = MSSAU.createMemoryAccessInBB(
1469-
New, nullptr, New->getParent(), MemorySSA::Beginning);
1471+
New, nullptr, New->getParent(), MemorySSA::Beginning,
1472+
/*CreationMustSucceed=*/false);
14701473
if (NewMemAcc) {
14711474
if (auto *MemDef = dyn_cast<MemoryDef>(NewMemAcc))
14721475
MSSAU.insertDef(MemDef, /*RenameUses=*/true);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
; RUN: opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>),print<memoryssa>' -verify-memoryssa -disable-output -S < %s 2>&1 | FileCheck %s
2+
; RUN: opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>,licm)' -verify-memoryssa -disable-output -S
3+
4+
; Check that SimpleLoopUnswitch preserves the MemoryDef of `call i32 @bar()`.
5+
; Also, check that running LICM after SimpleLoopUnswitch does not result in a crash.
26

37
; CHECK: preds = %bb2{{$}}
48
; CHECK-NEXT: MemoryDef

0 commit comments

Comments
 (0)