[PATCH] D141185: [MemorySSA] Don't check def set when cloning memoryaccesses

luxufan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 7 00:17:05 PST 2023


StephenFan created this revision.
StephenFan added reviewers: nikic, asbirlea.
Herald added subscribers: kmitropoulou, hiraditya.
Herald added a project: All.
StephenFan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

For internal functions, globals-aa returns different ModRefInfo
results if they are inlined and are no longer called by external
functions. This causes an assertion failure when cloning memoryssa
accesses.

Fixes: https://github.com/llvm/llvm-project/issues/59546


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141185

Files:
  llvm/lib/Analysis/MemorySSA.cpp
  llvm/test/Transforms/SimpleLoopUnswitch/pr59546.ll


Index: llvm/test/Transforms/SimpleLoopUnswitch/pr59546.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/SimpleLoopUnswitch/pr59546.ll
@@ -0,0 +1,41 @@
+; RUN: opt -passes="scc-oz-module-inliner,function(loop-mssa(no-op-loop)),recompute-globalsaa,function(loop-mssa(simple-loop-unswitch<nontrivial>))" -disable-output < %s
+; Check that don't crash if the Alias Analysis returns better results than
+; before when cloning loop's memoryssa.
+
+ at a = internal global i16 0
+
+define void @h() {
+entry:
+  br label %end
+
+body:                                       ; No predecessors!
+  call void @g(ptr null)
+  br label %end
+
+end:                                        ; preds = %while.body, %entry
+  ret void
+}
+
+define internal void @g(ptr %a) #0 {
+entry:
+  br label %while.cond
+
+while.cond:                                       ; preds = %while.body, %entry
+  %0 = load i16, ptr %a, align 1
+  %tobool.not = icmp eq i16 %0, 0
+  br i1 %tobool.not, label %while.end, label %while.body
+
+while.body:                                       ; preds = %while.cond
+  call void @f()
+  br label %while.cond
+
+while.end:                                        ; preds = %while.cond
+  ret void
+}
+
+define internal void @f() {
+  store i16 0, ptr @a, align 1
+  ret void
+}
+
+attributes #0 = { "target-cpu"="foobar" }
Index: llvm/lib/Analysis/MemorySSA.cpp
===================================================================
--- llvm/lib/Analysis/MemorySSA.cpp
+++ llvm/lib/Analysis/MemorySSA.cpp
@@ -1755,13 +1755,9 @@
     Use = isa<MemoryUse>(Template);
 #if !defined(NDEBUG)
     ModRefInfo ModRef = AAP->getModRefInfo(I, std::nullopt);
-    bool DefCheck, UseCheck;
-    DefCheck = isModSet(ModRef) || isOrdered(I);
-    UseCheck = isRefSet(ModRef);
-    // Use set is not checked since AA may return better results as a result of
+    bool UseCheck = isRefSet(ModRef);
+    // Use and Def set are not checked since AA may return better results as a result of
     // other transforms.
-    // FIXME: Would Def value always be consistent after transforms?
-    assert(Def == DefCheck && "Invalid template");
     if (!Def && Use != UseCheck) {
       // New Access should not have more power than template access
       assert(!UseCheck && "Invalid template");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141185.487060.patch
Type: text/x-patch
Size: 2338 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230107/695f8897/attachment.bin>


More information about the llvm-commits mailing list