Skip to content

Commit 89fa0dd

Browse files
committed
[MemorySSA] Handle queries with empty memory location.
1 parent 0d459b7 commit 89fa0dd

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

llvm/lib/Analysis/MemorySSA.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,6 +2390,10 @@ MemoryAccess *MemorySSA::ClobberWalkerBase::getClobberingMemoryAccessBase(
23902390
BatchAAResults &BAA, unsigned &UpwardWalkLimit) {
23912391
assert(!isa<MemoryUse>(StartingAccess) && "Use cannot be defining access");
23922392

2393+
// If location is undefined, conservatively return starting access.
2394+
if (Loc.Ptr == nullptr)
2395+
return StartingAccess;
2396+
23932397
Instruction *I = nullptr;
23942398
if (auto *StartingUseOrDef = dyn_cast<MemoryUseOrDef>(StartingAccess)) {
23952399
if (MSSA->isLiveOnEntryDef(StartingUseOrDef))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: opt < %s -S -p='newgvn' | FileCheck %s
2+
; MemorySSA should be able to handle a clobber query with an empty MemoryLocation.
3+
4+
; CHECK: @userread
5+
define ptr @userread(ptr %p) {
6+
entry:
7+
br label %loop
8+
9+
loop: ; preds = %loop, %entry
10+
; 2 = MemoryPhi({entry,liveOnEntry},{loop,1})
11+
%pos = phi i64 [ 1, %entry ], [ %diff, %loop ]
12+
%gep = getelementptr inbounds i8, ptr %p, i64 %pos
13+
; MemoryUse(2)
14+
%ld = load ptr, ptr %gep, align 8
15+
; 1 = MemoryDef(2)->2
16+
%readval = call i64 @fread(ptr noundef nonnull %gep, i64 noundef 1, i64 noundef %pos, ptr noundef %ld)
17+
%readvalispos = icmp eq i64 %readval, %pos
18+
call void @llvm.assume(i1 %readvalispos)
19+
%diff = sub i64 0, %pos
20+
br label %loop
21+
}
22+
23+
declare noundef i64 @fread(ptr nocapture noundef %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0
24+
declare void @llvm.assume(i1 %cond)
25+
26+
attributes #0 = { nofree nounwind "frame-pointer"="non-leaf" "no-trapping-math"="true" "prefer-vector-width"="128" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+aes,+cmov,+crc32,+cx16,+cx8,+fxsr,+mmx,+pclmul,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87" "tune-cpu"="generic" }

0 commit comments

Comments
 (0)