LoopExtractor.ll
2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
; RUN: opt < %s -loop-extract -S | FileCheck %s
; This function has 2 simple loops and they should be extracted into 2 new functions.
define void @test3() {
; CHECK-LABEL: @test3(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label %codeRepl1
; CHECK: codeRepl1:
; CHECK-NEXT: call void @test3.loop.0()
; CHECK-NEXT: br label %loop.0.loop.1_crit_edge
; CHECK: loop.0.loop.1_crit_edge:
; CHECK-NEXT: br label %codeRepl
; CHECK: codeRepl:
; CHECK-NEXT: call void @test3.loop.1()
; CHECK-NEXT: br label %exit
; CHECK: exit:
; CHECK-NEXT: ret void
entry:
br label %loop.0
loop.0: ; preds = %loop.0, %entry
%index.0 = phi i32 [ 10, %entry ], [ %next.0, %loop.0 ]
tail call void @foo()
%next.0 = add nsw i32 %index.0, -1
%repeat.0 = icmp sgt i32 %index.0, 1
br i1 %repeat.0, label %loop.0, label %loop.1
loop.1: ; preds = %loop.0, %loop.1
%index.1 = phi i32 [ %next.1, %loop.1 ], [ 10, %loop.0 ]
tail call void @foo()
%next.1 = add nsw i32 %index.1, -1
%repeat.1 = icmp sgt i32 %index.1, 1
br i1 %repeat.1, label %loop.1, label %exit
exit: ; preds = %loop.1
ret void
}
declare void @foo()
; CHECK-LABEL: define internal void @test3.loop.1()
; CHECK-NEXT: newFuncRoot:
; CHECK-NEXT: br label %loop.1
; CHECK: exit.exitStub:
; CHECK-NEXT: ret void
; CHECK: loop.1:
; CHECK-NEXT: %index.1 = phi i32 [ %next.1, %loop.1.loop.1_crit_edge ], [ 10, %newFuncRoot ]
; CHECK-NEXT: tail call void @foo()
; CHECK-NEXT: %next.1 = add nsw i32 %index.1, -1
; CHECK-NEXT: %repeat.1 = icmp sgt i32 %index.1, 1
; CHECK-NEXT: br i1 %repeat.1, label %loop.1.loop.1_crit_edge, label %exit.exitStub
; CHECK: loop.1.loop.1_crit_edge:
; CHECK-NEXT: br label %loop.1
; CHECK-LABEL: define internal void @test3.loop.0()
; CHECK-NEXT: newFuncRoot:
; CHECK-NEXT: br label %loop.0
; CHECK: loop.0.loop.1_crit_edge.exitStub:
; CHECK-NEXT: ret void
; CHECK: loop.0:
; CHECK-NEXT: %index.0 = phi i32 [ 10, %newFuncRoot ], [ %next.0, %loop.0.loop.0_crit_edge ]
; CHECK-NEXT: tail call void @foo()
; CHECK-NEXT: %next.0 = add nsw i32 %index.0, -1
; CHECK-NEXT: %repeat.0 = icmp sgt i32 %index.0, 1
; CHECK-NEXT: br i1 %repeat.0, label %loop.0.loop.0_crit_edge, label %loop.0.loop.1_crit_edge.exitStub
; CHECK: loop.0.loop.0_crit_edge:
; CHECK-NEXT: br label %loop.0