[llvm] cb2cb2d - [InstCombine] Avoid deleting volatile memcpys.
Patrick Walton via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 30 02:40:47 PDT 2022
Author: Patrick Walton
Date: 2022-10-30T02:40:16-07:00
New Revision: cb2cb2d201811d95d4f35337817faea05654d8f0
URL: https://github.com/llvm/llvm-project/commit/cb2cb2d201811d95d4f35337817faea05654d8f0
DIFF: https://github.com/llvm/llvm-project/commit/cb2cb2d201811d95d4f35337817faea05654d8f0.diff
LOG: [InstCombine] Avoid deleting volatile memcpys.
InstCombine can replace memcpy to an alloca with a pointer directly to the
source in certain cases. Unfortunately, it also did so for volatile memcpys.
This patch makes it stop doing that.
This was discovered in D136822.
Differential Revision: https://reviews.llvm.org/D137031
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/test/Transforms/InstCombine/memcpy-from-global.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index a1f29cb69efc0..23f6207a6b584 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -111,12 +111,14 @@ isOnlyCopiedFromConstantMemory(AAResults *AA,
if (!MI)
return false;
+ // If the transfer is volatile, reject it.
+ if (MI->isVolatile())
+ return false;
+
// If the transfer is using the alloca as a source of the transfer, then
// ignore it since it is a load (unless the transfer is volatile).
- if (U.getOperandNo() == 1) {
- if (MI->isVolatile()) return false;
+ if (U.getOperandNo() == 1)
continue;
- }
// If we already have seen a copy, reject the second one.
if (TheCopy) return false;
diff --git a/llvm/test/Transforms/InstCombine/memcpy-from-global.ll b/llvm/test/Transforms/InstCombine/memcpy-from-global.ll
index 67fb0596e1a9e..a0cd39b233eed 100644
--- a/llvm/test/Transforms/InstCombine/memcpy-from-global.ll
+++ b/llvm/test/Transforms/InstCombine/memcpy-from-global.ll
@@ -366,10 +366,12 @@ define void @memcpy_from_just_readonly(ptr readonly align 8 dereferenceable(124)
ret void
}
-; FIXME: Test that we incorrectly elide a volatile memcpy.
+; Test that we don't elide a volatile memcpy.
define void @volatile_memcpy() {
; CHECK-LABEL: @volatile_memcpy(
-; CHECK-NEXT: call void @bar(ptr nonnull @H) #[[ATTR3]]
+; CHECK-NEXT: [[A:%.*]] = alloca [[U:%.*]], align 16
+; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 [[A]], ptr align 4 @H, i64 20, i1 true)
+; CHECK-NEXT: call void @bar(ptr nonnull [[A]]) #[[ATTR3]]
; CHECK-NEXT: ret void
;
%A = alloca %U, align 16
More information about the llvm-commits
mailing list