Skip to content

Commit 4125afc

Browse files
committed
[MemCpyOpt] Fix handling of readnone byval arguments
If the call is readnone, then there may not be any MemoryAccess associated with the call. Bail out in that case. This fixes the issue reported at https://reviews.llvm.org/D94376#2578312.
1 parent 5616c5b commit 4125afc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,8 @@ bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
15411541
MemCpyInst *MDep = nullptr;
15421542
if (EnableMemorySSA) {
15431543
MemoryUseOrDef *CallAccess = MSSA->getMemoryAccess(&CB);
1544+
if (!CallAccess)
1545+
return false;
15441546
MemoryAccess *Clobber = MSSA->getWalker()->getClobberingMemoryAccess(
15451547
CallAccess->getDefiningAccess(), Loc);
15461548
if (auto *MD = dyn_cast<MemoryDef>(Clobber))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt < %s -memcpyopt -S -enable-memcpyopt-memoryssa=0 | FileCheck %s
3+
; RUN: opt < %s -memcpyopt -S -enable-memcpyopt-memoryssa=1 -verify-memoryssa | FileCheck %s
4+
5+
%struct = type { i16 }
6+
7+
declare i16 @g(%struct*) readnone
8+
9+
define void @f() {
10+
; CHECK-LABEL: @f(
11+
; CHECK-NEXT: entry:
12+
; CHECK-NEXT: [[CALL:%.*]] = call i16 @g(%struct* byval(%struct) align 1 undef)
13+
; CHECK-NEXT: ret void
14+
;
15+
entry:
16+
%call = call i16 @g(%struct* byval(%struct) align 1 undef)
17+
ret void
18+
}

0 commit comments

Comments
 (0)