[llvm] 98ffc7b - [MemorySSA] Don't check def set when cloning memoryaccesses

via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 12 05:54:48 PST 2023


Author: luxufan
Date: 2023-01-12T21:48:30+08:00
New Revision: 98ffc7b1a88e6e9053333bff83b8ecef25f63b6c

URL: https://github.com/llvm/llvm-project/commit/98ffc7b1a88e6e9053333bff83b8ecef25f63b6c
DIFF: https://github.com/llvm/llvm-project/commit/98ffc7b1a88e6e9053333bff83b8ecef25f63b6c.diff

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

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

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D141185

Added: 
    llvm/test/Transforms/SimpleLoopUnswitch/pr59546.ll

Modified: 
    llvm/lib/Analysis/MemorySSA.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/MemorySSA.cpp b/llvm/lib/Analysis/MemorySSA.cpp
index fec7a0fd35795..aefb66863b8f0 100644
--- a/llvm/lib/Analysis/MemorySSA.cpp
+++ b/llvm/lib/Analysis/MemorySSA.cpp
@@ -1758,10 +1758,10 @@ MemoryUseOrDef *MemorySSA::createNewAccess(Instruction *I,
     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
-    // other transforms.
-    // FIXME: Would Def value always be consistent after transforms?
-    assert(Def == DefCheck && "Invalid template");
+    // Memory accesses should only be reduced and can not be increased since AA
+    // just might return better results as a result of some transformations.
+    assert((Def == DefCheck || !DefCheck) &&
+           "Memory accesses should only be reduced");
     if (!Def && Use != UseCheck) {
       // New Access should not have more power than template access
       assert(!UseCheck && "Invalid template");

diff  --git a/llvm/test/Transforms/SimpleLoopUnswitch/pr59546.ll b/llvm/test/Transforms/SimpleLoopUnswitch/pr59546.ll
new file mode 100644
index 0000000000000..a9b160375c01b
--- /dev/null
+++ b/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() #0 {
+  store i16 0, ptr @a, align 1
+  ret void
+}
+
+attributes #0 = { noinline }


        


More information about the llvm-commits mailing list