[llvm] 560e694 - [AST] Don't assert instruction reads/writes memory (PR51333)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 1 08:04:56 PDT 2022
Author: Nikita Popov
Date: 2022-07-01T17:04:48+02:00
New Revision: 560e694d48a6020f613281c29ffd17184f56dfb0
URL: https://github.com/llvm/llvm-project/commit/560e694d48a6020f613281c29ffd17184f56dfb0
DIFF: https://github.com/llvm/llvm-project/commit/560e694d48a6020f613281c29ffd17184f56dfb0.diff
LOG: [AST] Don't assert instruction reads/writes memory (PR51333)
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.
Differential Revision: https://reviews.llvm.org/D127947
Added:
llvm/test/Transforms/LICM/pr51333.ll
Modified:
llvm/lib/Analysis/AliasSetTracker.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/AliasSetTracker.cpp b/llvm/lib/Analysis/AliasSetTracker.cpp
index 7f40a875da4b0..234a73bff6a8d 100644
--- a/llvm/lib/Analysis/AliasSetTracker.cpp
+++ b/llvm/lib/Analysis/AliasSetTracker.cpp
@@ -233,8 +233,8 @@ bool AliasSet::aliasesUnknownInst(const Instruction *Inst,
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)) {
diff --git a/llvm/test/Transforms/LICM/pr51333.ll b/llvm/test/Transforms/LICM/pr51333.ll
new file mode 100644
index 0000000000000..8832959e6c5a7
--- /dev/null
+++ b/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
More information about the llvm-commits
mailing list