llvm.org GIT mirror llvm / 3eabf91
[MemorySSA] Don't hoist stores if interfering uses (as calls) exist. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373674 91177308-0d34-0410-b5e6-96231b3b80d8 Alina Sbirlea 1 year, 17 days ago
3 changed file(s) with 46 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
12471247 // FIXME: More precise: no Uses that alias SI.
12481248 if (!Flags->IsSink && !MSSA->dominates(SIMD, MU))
12491249 return false;
1250 } else if (const auto *MD = dyn_cast(&MA))
1250 } else if (const auto *MD = dyn_cast(&MA)) {
12511251 if (auto *LI = dyn_cast(MD->getMemoryInst())) {
12521252 (void)LI; // Silence warning.
12531253 assert(!LI->isUnordered() && "Expected unordered load");
12541254 return false;
12551255 }
1256 // Any call, while it may not be clobbering SI, it may be a use.
1257 if (auto *CI = dyn_cast(MD->getMemoryInst())) {
1258 // Check if the call may read from the memory locattion written
1259 // to by SI. Check CI's attributes and arguments; the number of
1260 // such checks performed is limited above by NoOfMemAccTooLarge.
1261 ModRefInfo MRI = AA->getModRefInfo(CI, MemoryLocation::get(SI));
1262 if (isModOrRefSet(MRI))
1263 return false;
1264 }
1265 }
12561266 }
12571267
12581268 auto *Source = MSSA->getSkipSelfWalker()->getClobberingMemoryAccess(SI);
0 ; RUN: opt -S -licm -enable-mssa-loop-dependency=true %s | FileCheck %s
1 @v_1 = global i8 0, align 1
2 @v_2 = global i8 0, align 1
3
4 ; CHECK-LABEL: @foo()
5 ; CHECK: for.cond:
6 ; CHECK-NOT: store
7 ; CHECK: for.body:
8 ; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
9 ; CHECK: store
10 define void @foo() {
11 entry:
12 br label %for.cond
13
14 for.cond: ; preds = %for.body, %entry
15 %0 = phi i16 [ %inc, %for.body ], [ 0, %entry ]
16 %cmp = icmp slt i16 %0, 1
17 br i1 %cmp, label %for.body, label %for.end
18
19 for.body: ; preds = %for.cond
20 call void @llvm.memcpy.p0i8.p0i8.i64(i8* @v_1, i8 * @v_2, i64 1, i1 false)
21 store i8 1, i8 * @v_2, align 1
22 %inc = add nsw i16 %0, 1
23 br label %for.cond
24
25 for.end: ; preds = %for.cond
26 ret void
27 }
28
29 ; Function Attrs: argmemonly nounwind willreturn
30 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8 * noalias nocapture readonly, i64, i1 immarg) #2
31
32 attributes #2 = { argmemonly nounwind willreturn }
33
8383 }
8484
8585 ; But can hoist if the side effect is hoisted with MSSA
86 define void @test2b_prime(i1 %cond, i32* %ptr) {
86 define void @test2b_prime(i1 %cond, i32* noalias %ptr) {
8787 ; MSSA-LABEL: @test2b_prime(
8888 ; MSSA-NEXT: entry:
8989 ; MSSA-NEXT: [[P2:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 1