[llvm] 89fa0dd - [MemorySSA] Handle queries with empty memory location.

Alina Sbirlea via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 10 09:58:52 PDT 2023


Author: Alina Sbirlea
Date: 2023-08-10T09:57:32-07:00
New Revision: 89fa0dd1fb25698270e9382a94929d2f5747e802

URL: https://github.com/llvm/llvm-project/commit/89fa0dd1fb25698270e9382a94929d2f5747e802
DIFF: https://github.com/llvm/llvm-project/commit/89fa0dd1fb25698270e9382a94929d2f5747e802.diff

LOG: [MemorySSA] Handle queries with empty memory location.

Added: 
    llvm/test/Transforms/NewGVN/nomemlocation.ll

Modified: 
    llvm/lib/Analysis/MemorySSA.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/MemorySSA.cpp b/llvm/lib/Analysis/MemorySSA.cpp
index d1665802826683..2cf92ceba01032 100644
--- a/llvm/lib/Analysis/MemorySSA.cpp
+++ b/llvm/lib/Analysis/MemorySSA.cpp
@@ -2390,6 +2390,10 @@ MemoryAccess *MemorySSA::ClobberWalkerBase::getClobberingMemoryAccessBase(
     BatchAAResults &BAA, unsigned &UpwardWalkLimit) {
   assert(!isa<MemoryUse>(StartingAccess) && "Use cannot be defining access");
 
+  // If location is undefined, conservatively return starting access.
+  if (Loc.Ptr == nullptr)
+    return StartingAccess;
+
   Instruction *I = nullptr;
   if (auto *StartingUseOrDef = dyn_cast<MemoryUseOrDef>(StartingAccess)) {
     if (MSSA->isLiveOnEntryDef(StartingUseOrDef))

diff  --git a/llvm/test/Transforms/NewGVN/nomemlocation.ll b/llvm/test/Transforms/NewGVN/nomemlocation.ll
new file mode 100644
index 00000000000000..0f716b30801b25
--- /dev/null
+++ b/llvm/test/Transforms/NewGVN/nomemlocation.ll
@@ -0,0 +1,26 @@
+; RUN: opt < %s -S -p='newgvn' | FileCheck %s
+; MemorySSA should be able to handle a clobber query with an empty MemoryLocation.
+
+; CHECK: @userread
+define ptr @userread(ptr %p) {
+entry:
+  br label %loop
+
+loop:                                             ; preds = %loop, %entry
+; 2 = MemoryPhi({entry,liveOnEntry},{loop,1})
+  %pos = phi i64 [ 1, %entry ], [ %
diff , %loop ]
+  %gep = getelementptr inbounds i8, ptr %p, i64 %pos
+; MemoryUse(2)
+  %ld = load ptr, ptr %gep, align 8
+; 1 = MemoryDef(2)->2
+  %readval = call i64 @fread(ptr noundef nonnull %gep, i64 noundef 1, i64 noundef %pos, ptr noundef %ld)
+  %readvalispos = icmp eq i64 %readval, %pos
+  call void @llvm.assume(i1 %readvalispos)
+  %
diff  = sub i64 0, %pos
+  br label %loop
+}
+
+declare noundef i64 @fread(ptr nocapture noundef %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0
+declare void @llvm.assume(i1 %cond)
+
+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" }


        


More information about the llvm-commits mailing list