[llvm] 4125afc - [MemCpyOpt] Fix handling of readnone byval arguments
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 22 09:48:41 PST 2021
Author: Nikita Popov
Date: 2021-02-22T18:48:31+01:00
New Revision: 4125afc35723b490556f7a38f7835f0914f70292
URL: https://github.com/llvm/llvm-project/commit/4125afc35723b490556f7a38f7835f0914f70292
DIFF: https://github.com/llvm/llvm-project/commit/4125afc35723b490556f7a38f7835f0914f70292.diff
LOG: [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.
Added:
llvm/test/Transforms/MemCpyOpt/byval-readnone.ll
Modified:
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 259e656091ad..da4513535542 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -1541,6 +1541,8 @@ bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
MemCpyInst *MDep = nullptr;
if (EnableMemorySSA) {
MemoryUseOrDef *CallAccess = MSSA->getMemoryAccess(&CB);
+ if (!CallAccess)
+ return false;
MemoryAccess *Clobber = MSSA->getWalker()->getClobberingMemoryAccess(
CallAccess->getDefiningAccess(), Loc);
if (auto *MD = dyn_cast<MemoryDef>(Clobber))
diff --git a/llvm/test/Transforms/MemCpyOpt/byval-readnone.ll b/llvm/test/Transforms/MemCpyOpt/byval-readnone.ll
new file mode 100644
index 000000000000..cb62ff27f4be
--- /dev/null
+++ b/llvm/test/Transforms/MemCpyOpt/byval-readnone.ll
@@ -0,0 +1,18 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -memcpyopt -S -enable-memcpyopt-memoryssa=0 | FileCheck %s
+; RUN: opt < %s -memcpyopt -S -enable-memcpyopt-memoryssa=1 -verify-memoryssa | FileCheck %s
+
+%struct = type { i16 }
+
+declare i16 @g(%struct*) readnone
+
+define void @f() {
+; CHECK-LABEL: @f(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[CALL:%.*]] = call i16 @g(%struct* byval(%struct) align 1 undef)
+; CHECK-NEXT: ret void
+;
+entry:
+ %call = call i16 @g(%struct* byval(%struct) align 1 undef)
+ ret void
+}
More information about the llvm-commits
mailing list