[PATCH] D89154: [MemCpyOpt] Don't hoist store that's not guaranteed to execute

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 10 01:28:21 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG5e855f1e8056: [MemCpyOpt] Don't hoist store that's not guaranteed to execute (authored by nikic).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89154/new/

https://reviews.llvm.org/D89154

Files:
  llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
  llvm/test/Transforms/MemCpyOpt/fca2memcpy.ll


Index: llvm/test/Transforms/MemCpyOpt/fca2memcpy.ll
===================================================================
--- llvm/test/Transforms/MemCpyOpt/fca2memcpy.ll
+++ llvm/test/Transforms/MemCpyOpt/fca2memcpy.ll
@@ -147,12 +147,11 @@
 
 define void @throwing_call(%S* noalias %src, %S* %dst) {
 ; CHECK-LABEL: @throwing_call(
-; CHECK-NEXT:    [[TMP1:%.*]] = bitcast %S* [[SRC:%.*]] to i8*
-; CHECK-NEXT:    [[TMP2:%.*]] = bitcast %S* [[DST:%.*]] to i8*
-; CHECK-NEXT:    [[TMP3:%.*]] = bitcast %S* [[SRC]] to i8*
-; CHECK-NEXT:    call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[TMP2]], i8* align 8 [[TMP3]], i64 16, i1 false)
-; CHECK-NEXT:    call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP1]], i8 0, i64 16, i1 false)
+; CHECK-NEXT:    [[TMP1:%.*]] = load [[S:%.*]], %S* [[SRC:%.*]], align 8
+; CHECK-NEXT:    [[TMP2:%.*]] = bitcast %S* [[SRC]] to i8*
+; CHECK-NEXT:    call void @llvm.memset.p0i8.i64(i8* align 8 [[TMP2]], i8 0, i64 16, i1 false)
 ; CHECK-NEXT:    call void @call() [[ATTR2:#.*]]
+; CHECK-NEXT:    store [[S]] [[TMP1]], %S* [[DST:%.*]], align 8
 ; CHECK-NEXT:    ret void
 ;
   %1 = load %S, %S* %src
Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -491,6 +491,11 @@
   for (auto I = --SI->getIterator(), E = P->getIterator(); I != E; --I) {
     auto *C = &*I;
 
+    // Make sure hoisting does not perform a store that was not guaranteed to
+    // happen.
+    if (!isGuaranteedToTransferExecutionToSuccessor(C))
+      return false;
+
     bool MayAlias = isModOrRefSet(AA->getModRefInfo(C, None));
 
     bool NeedLift = false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89154.297397.patch
Type: text/x-patch
Size: 1745 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201010/7b2cb5af/attachment.bin>


More information about the llvm-commits mailing list