[llvm] 3053a32 - [MemorySSA] Relax assert condition in createDefinedAccess

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 17 07:43:33 PST 2022


Author: luxufan
Date: 2022-11-17T23:43:20+08:00
New Revision: 3053a323c734fa229ba47090b1fb59633ab1e7c6

URL: https://github.com/llvm/llvm-project/commit/3053a323c734fa229ba47090b1fb59633ab1e7c6
DIFF: https://github.com/llvm/llvm-project/commit/3053a323c734fa229ba47090b1fb59633ab1e7c6.diff

LOG: [MemorySSA] Relax assert condition in createDefinedAccess

If globals-aa is enabled, because of the deletion of memory instructions, there
may be call instruction that is not in ModOrRefSet but is a MemoryUseOrDef.
This causes the crash in the process of cloning uses and defs.

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

Reviewed By: asbirlea

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

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

Modified: 
    llvm/lib/Analysis/MemorySSA.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/MemorySSA.cpp b/llvm/lib/Analysis/MemorySSA.cpp
index 1660321990bf2..32589155706b3 100644
--- a/llvm/lib/Analysis/MemorySSA.cpp
+++ b/llvm/lib/Analysis/MemorySSA.cpp
@@ -1764,7 +1764,14 @@ MemoryUseOrDef *MemorySSA::createNewAccess(Instruction *I,
     bool DefCheck, UseCheck;
     DefCheck = isModSet(ModRef) || isOrdered(I);
     UseCheck = isRefSet(ModRef);
-    assert(Def == DefCheck && (Def || Use == UseCheck) && "Invalid template");
+    // 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");
+    if (!Def && Use != UseCheck) {
+      // New Access should not have more power than template access
+      assert(!UseCheck && "Invalid template");
+    }
 #endif
   } else {
     // Find out what affect this instruction has on memory.

diff  --git a/llvm/test/Transforms/SimpleLoopUnswitch/pr58719.ll b/llvm/test/Transforms/SimpleLoopUnswitch/pr58719.ll
new file mode 100644
index 0000000000000..49d6768e2d57c
--- /dev/null
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/pr58719.ll
@@ -0,0 +1,21 @@
+; RUN: opt -passes="require<globals-aa>,cgscc(instcombine),function(loop-mssa(loop-simplifycfg)),recompute-globalsaa,function(loop-mssa(simple-loop-unswitch<nontrivial>),print<memoryssa>)" -disable-output < %s
+
+; Check that don't crash if the Alias Analysis returns better results than
+; before when cloning loop's memoryssa.
+define void @f(ptr %p) {
+entry:
+  %0 = load i16, ptr %p, align 1
+  ret void
+}
+
+define void @g(i1 %tobool.not) {
+entry:
+  br label %for.cond
+
+for.cond:                                         ; preds = %if.then, %for.cond, %entry
+  br i1 %tobool.not, label %if.then, label %for.cond
+
+if.then:                                          ; preds = %for.cond
+  call void @f()
+  br label %for.cond
+}


        


More information about the llvm-commits mailing list