[PATCH] D127947: [AST] Don't assert instruction reads/writes memory (PR51333)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 16 01:24:23 PDT 2022


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

This function is well-defined for an instruction that doesn't access memory (and thus trivially doesn't alias anything in the AST), so drop the assert. We can end up with a readnone call here if we originally created a MemoryDef for an indirect call, which was later replaced with a direct readnone call.

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


https://reviews.llvm.org/D127947

Files:
  llvm/lib/Analysis/AliasSetTracker.cpp
  llvm/test/Transforms/LICM/pr51333.ll


Index: llvm/test/Transforms/LICM/pr51333.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LICM/pr51333.ll
@@ -0,0 +1,31 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -passes='early-cse<memssa>,loop-mssa(licm)' < %s | FileCheck %s
+
+; This used to assert because was have a MemoryDef for what turns out to be
+; a readnone call after EarlyCSE.
+
+ at fn_ptr = external global void ()*, align 1
+
+define void @test() {
+; CHECK-LABEL: @test(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[DO_BODY:%.*]]
+; CHECK:       do.body:
+; CHECK-NEXT:    store void ()* @readnone_fn, void ()** @fn_ptr, align 8
+; CHECK-NEXT:    call void @readnone_fn()
+; CHECK-NEXT:    call void @foo()
+; CHECK-NEXT:    br label [[DO_BODY]]
+;
+entry:
+  br label %do.body
+
+do.body:
+  store void ()* @readnone_fn, void ()** @fn_ptr
+  %fn = load void ()*, void ()** @fn_ptr
+  call void %fn()
+  call void @foo()
+  br label %do.body
+}
+
+declare void @foo()
+declare void @readnone_fn() readnone
Index: llvm/lib/Analysis/AliasSetTracker.cpp
===================================================================
--- llvm/lib/Analysis/AliasSetTracker.cpp
+++ llvm/lib/Analysis/AliasSetTracker.cpp
@@ -233,8 +233,8 @@
   if (AliasAny)
     return true;
 
-  assert(Inst->mayReadOrWriteMemory() &&
-         "Instruction must either read or write memory.");
+  if (!Inst->mayReadOrWriteMemory())
+    return false;
 
   for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
     if (auto *UnknownInst = getUnknownInst(i)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127947.437470.patch
Type: text/x-patch
Size: 1618 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220616/b6e256c9/attachment.bin>


More information about the llvm-commits mailing list