llvm.org GIT mirror llvm / 2739f4e
[LoopSink] Add preheader to alias set This patch fixes PR39695. The original LoopSink only considers memory alias in loop body. But PR39695 shows that instructions following sink candidate in preheader should also be checked. This is a conservative patch, it simply adds whole preheader block to alias set. It may lose some optimization opportunity, but I think that is very rare because: 1 in the most common case st/ld to the same address, the load should already be optimized away. 2 usually preheader is not very large. Differential Revision: https://reviews.llvm.org/D54659 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347325 91177308-0d34-0410-b5e6-96231b3b80d8 Guozhi Wei 9 months ago
2 changed file(s) with 38 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
279279 // Compute alias set.
280280 for (BasicBlock *BB : L.blocks())
281281 CurAST.add(*BB);
282 CurAST.add(*Preheader);
282283
283284 // Sort loop's basic blocks by frequency
284285 SmallVector ColdLoopBBs;
0 ; RUN: opt -S -loop-sink < %s | FileCheck %s
1
2 ; The load instruction should not be sunk into following loop.
3 ; CHECK: @foo
4 ; CHECK-NEXT: entry
5 ; CHECK-NEXT: %ptr = load i8*, i8** %pp, align 8
6 ; CHECK-NEXT: store i8* null, i8** %pp, align 8
7
8 define i32 @foo(i32 %n, i8** %pp) !prof !0 {
9 entry:
10 %ptr = load i8*, i8** %pp, align 8
11 store i8* null, i8** %pp, align 8
12 br label %for.cond
13
14 for.cond: ; preds = %for.body, %entry
15 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
16 %cmp = icmp ult i32 %i.0, %n
17 br i1 %cmp, label %for.body, label %for.end, !prof !1
18
19 for.body: ; preds = %for.cond
20 %0 = sext i32 %i.0 to i64
21 %arrayidx = getelementptr inbounds i8, i8* %ptr, i64 %0
22 %1 = load i8, i8* %arrayidx, align 1
23 %or19 = call i8 @llvm.bitreverse.i8(i8 %1)
24 %v = sext i8 %or19 to i32
25 %inc = add i32 %i.0, %v
26 br label %for.cond
27
28 for.end: ; preds = %for.cond
29 ret i32 %i.0
30 }
31
32 declare i8 @llvm.bitreverse.i8(i8) #0
33 attributes #0 = { nounwind readnone speculatable }
34
35 !0 = !{!"function_entry_count", i64 1}
36 !1 = !{!"branch_weights", i32 1, i32 2000}