llvm.org GIT mirror llvm / 9f6d8ac
[LoopUnroll] Remap references in peeled iteration References in cloned blocks must be remapped prior to dominator calculation. Differential Revision: https://reviews.llvm.org/D31281 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298811 91177308-0d34-0410-b5e6-96231b3b80d8 Serge Pavlov 3 years ago
2 changed file(s) with 66 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
414414
415415 cloneLoopBlocks(L, Iter, InsertTop, InsertBot, Exit,
416416 NewBlocks, LoopBlocks, VMap, LVMap, DT, LI);
417
418 // Remap to use values from the current iteration instead of the
419 // previous one.
420 remapInstructionsInBlocks(NewBlocks, VMap);
421
417422 if (DT) {
418423 // Latches of the cloned loops dominate over the loop exit, so idom of the
419424 // latter is the first cloned loop body, as original PreHeader dominates
436441 F->getBasicBlockList().splice(InsertTop->getIterator(),
437442 F->getBasicBlockList(),
438443 NewBlocks[0]->getIterator(), F->end());
439
440 // Remap to use values from the current iteration instead of the
441 // previous one.
442 remapInstructionsInBlocks(NewBlocks, VMap);
443444 }
444445
445446 // Now adjust the phi nodes in the loop header to get their initial values
0 ; RUN: opt -S -loop-unroll -unroll-force-peel-count=1 -verify-dom-info <%s
1
2 ; Check if loop composed of several BBs is peeled correctly.
3
4 declare void @funcb()
5 @Comma = external global i8
6 define void @funca(i8* readnone %b, i8* readnone %e) {
7 entry:
8 %cmp2 = icmp eq i8* %b, %e
9 br i1 %cmp2, label %for.end, label %for.body.preheader
10
11 for.body.preheader:
12 br label %for.body
13
14 for.body:
15 %b.addr.03 = phi i8* [ %incdec.ptr, %for.inc ], [ %b, %for.body.preheader ]
16 %0 = load i8, i8* @Comma
17 %tobool = icmp eq i8 %0, 0
18 br i1 %tobool, label %for.inc, label %if.then
19
20 if.then:
21 tail call void @funcb()
22 store i8 1, i8* @Comma
23 br label %for.inc
24
25 for.inc:
26 %incdec.ptr = getelementptr inbounds i8, i8* %b.addr.03, i64 1
27 %cmp = icmp eq i8* %incdec.ptr, %e
28 br i1 %cmp, label %for.end, label %for.body
29
30 for.end:
31 ret void
32 }
33
34 ; CHECK_LABEL: @funca
35
36 ; Peeled iteration
37 ; CHECK: %[[REG1:[0-9]+]] = load i8, i8* @Comma
38 ; CHECK: %[[REG2:.*]] = icmp eq i8 %[[REG1]], 0
39 ; CHECK: br i1 %[[REG2]], label %{{.*}}, label %[[IFTHEN:.*]]
40 ; CHECK: [[IFTHEN]]:
41 ; CHECK: call void @funcb()
42 ; CHECK: store i8 1, i8* @Comma
43 ; CHECK: br label %[[FORINC]]
44 ; CHECK: [[FORINC]]:
45 ; CHECK: %[[REG3:.*]] = getelementptr inbounds i8, i8* %b, i64 1
46 ; CHECK: %[[REG4:.*]] = icmp eq i8* %[[REG3]], %e
47 ; CHECK: br i1 %[[REG4]]
48
49 ; main body
50 ; CHECK: %[[REG1b:.*]] = load i8, i8* @Comma
51 ; CHECK: %[[REG2b:.*]] = icmp eq i8 %[[REG1b]], 0
52 ; CHECK: br i1 %[[REG2b]], label %{{.*}}, label %[[IFTHENb:.*]]
53 ; CHECK: [[IFTHENb]]:
54 ; CHECK: call void @funcb()
55 ; CHECK: store i8 1, i8* @Comma
56 ; CHECK: br label %[[FORINCb]]
57 ; CHECK: [[FORINCb]]:
58 ; CHECK: %[[REG3b:.*]] = getelementptr inbounds i8, i8* %b, i64 1
59 ; CHECK: %[[REG4b:.*]] = icmp eq i8* %[[REG3b]], %e
60 ; CHECK: br i1 %[[REG4b]]