Skip to content

Commit 560e694

Browse files
committed
[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 #51333. Differential Revision: https://reviews.llvm.org/D127947
1 parent a322c10 commit 560e694

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

llvm/lib/Analysis/AliasSetTracker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ bool AliasSet::aliasesUnknownInst(const Instruction *Inst,
233233
if (AliasAny)
234234
return true;
235235

236-
assert(Inst->mayReadOrWriteMemory() &&
237-
"Instruction must either read or write memory.");
236+
if (!Inst->mayReadOrWriteMemory())
237+
return false;
238238

239239
for (unsigned i = 0, e = UnknownInsts.size(); i != e; ++i) {
240240
if (auto *UnknownInst = getUnknownInst(i)) {

llvm/test/Transforms/LICM/pr51333.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -S -passes='early-cse<memssa>,loop-mssa(licm)' < %s | FileCheck %s
3+
4+
; This used to assert because was have a MemoryDef for what turns out to be
5+
; a readnone call after EarlyCSE.
6+
7+
@fn_ptr = external global void ()*, align 1
8+
9+
define void @test() {
10+
; CHECK-LABEL: @test(
11+
; CHECK-NEXT: entry:
12+
; CHECK-NEXT: br label [[DO_BODY:%.*]]
13+
; CHECK: do.body:
14+
; CHECK-NEXT: store void ()* @readnone_fn, void ()** @fn_ptr, align 8
15+
; CHECK-NEXT: call void @readnone_fn()
16+
; CHECK-NEXT: call void @foo()
17+
; CHECK-NEXT: br label [[DO_BODY]]
18+
;
19+
entry:
20+
br label %do.body
21+
22+
do.body:
23+
store void ()* @readnone_fn, void ()** @fn_ptr
24+
%fn = load void ()*, void ()** @fn_ptr
25+
call void %fn()
26+
call void @foo()
27+
br label %do.body
28+
}
29+
30+
declare void @foo()
31+
declare void @readnone_fn() readnone

0 commit comments

Comments
 (0)