[llvm] r373674 - [MemorySSA] Don't hoist stores if interfering uses (as calls) exist.
Alina Sbirlea via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 3 15:20:05 PDT 2019
Author: asbirlea
Date: Thu Oct 3 15:20:04 2019
New Revision: 373674
URL: http://llvm.org/viewvc/llvm-project?rev=373674&view=rev
Log:
[MemorySSA] Don't hoist stores if interfering uses (as calls) exist.
Added:
llvm/trunk/test/Analysis/MemorySSA/pr43540.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/LICM.cpp
llvm/trunk/test/Transforms/LICM/guards.ll
Modified: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LICM.cpp?rev=373674&r1=373673&r2=373674&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LICM.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp Thu Oct 3 15:20:04 2019
@@ -1248,12 +1248,22 @@ bool llvm::canSinkOrHoistInst(Instructio
// FIXME: More precise: no Uses that alias SI.
if (!Flags->IsSink && !MSSA->dominates(SIMD, MU))
return false;
- } else if (const auto *MD = dyn_cast<MemoryDef>(&MA))
+ } else if (const auto *MD = dyn_cast<MemoryDef>(&MA)) {
if (auto *LI = dyn_cast<LoadInst>(MD->getMemoryInst())) {
(void)LI; // Silence warning.
assert(!LI->isUnordered() && "Expected unordered load");
return false;
}
+ // Any call, while it may not be clobbering SI, it may be a use.
+ if (auto *CI = dyn_cast<CallInst>(MD->getMemoryInst())) {
+ // Check if the call may read from the memory locattion written
+ // to by SI. Check CI's attributes and arguments; the number of
+ // such checks performed is limited above by NoOfMemAccTooLarge.
+ ModRefInfo MRI = AA->getModRefInfo(CI, MemoryLocation::get(SI));
+ if (isModOrRefSet(MRI))
+ return false;
+ }
+ }
}
auto *Source = MSSA->getSkipSelfWalker()->getClobberingMemoryAccess(SI);
Added: llvm/trunk/test/Analysis/MemorySSA/pr43540.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/MemorySSA/pr43540.ll?rev=373674&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/MemorySSA/pr43540.ll (added)
+++ llvm/trunk/test/Analysis/MemorySSA/pr43540.ll Thu Oct 3 15:20:04 2019
@@ -0,0 +1,34 @@
+; RUN: opt -S -licm -enable-mssa-loop-dependency=true %s | FileCheck %s
+ at v_1 = global i8 0, align 1
+ at v_2 = global i8 0, align 1
+
+; CHECK-LABEL: @foo()
+; CHECK: for.cond:
+; CHECK-NOT: store
+; CHECK: for.body:
+; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
+; CHECK: store
+define void @foo() {
+entry:
+ br label %for.cond
+
+for.cond: ; preds = %for.body, %entry
+ %0 = phi i16 [ %inc, %for.body ], [ 0, %entry ]
+ %cmp = icmp slt i16 %0, 1
+ br i1 %cmp, label %for.body, label %for.end
+
+for.body: ; preds = %for.cond
+ call void @llvm.memcpy.p0i8.p0i8.i64(i8* @v_1, i8 * @v_2, i64 1, i1 false)
+ store i8 1, i8 * @v_2, align 1
+ %inc = add nsw i16 %0, 1
+ br label %for.cond
+
+for.end: ; preds = %for.cond
+ ret void
+}
+
+; Function Attrs: argmemonly nounwind willreturn
+declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8 * noalias nocapture readonly, i64, i1 immarg) #2
+
+attributes #2 = { argmemonly nounwind willreturn }
+
Modified: llvm/trunk/test/Transforms/LICM/guards.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LICM/guards.ll?rev=373674&r1=373673&r2=373674&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LICM/guards.ll (original)
+++ llvm/trunk/test/Transforms/LICM/guards.ll Thu Oct 3 15:20:04 2019
@@ -84,7 +84,7 @@ loop:
}
; But can hoist if the side effect is hoisted with MSSA
-define void @test2b_prime(i1 %cond, i32* %ptr) {
+define void @test2b_prime(i1 %cond, i32* noalias %ptr) {
; MSSA-LABEL: @test2b_prime(
; MSSA-NEXT: entry:
; MSSA-NEXT: [[P2:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 1
More information about the llvm-commits
mailing list