1 ; RUN: opt < %s -passes='function(break-crit-edges,loop-simplify),loop-extract' -S | FileCheck %s
3 ; This function has 2 simple loops and they should be extracted into 2 new functions.
7 ; CHECK-NEXT: br label %codeRepl1
9 ; CHECK-NEXT: call void @test3.loop.0()
10 ; CHECK-NEXT: br label %loop.0.loop.1_crit_edge
11 ; CHECK: loop.0.loop.1_crit_edge:
12 ; CHECK-NEXT: br label %codeRepl
14 ; CHECK-NEXT: call void @test3.loop.1()
15 ; CHECK-NEXT: br label %exit
17 ; CHECK-NEXT: ret void
22 loop.0: ; preds = %loop.0, %entry
23 %index.0 = phi i32 [ 10, %entry ], [ %next.0, %loop.0 ]
25 %next.0 = add nsw i32 %index.0, -1
26 %repeat.0 = icmp sgt i32 %index.0, 1
27 br i1 %repeat.0, label %loop.0, label %loop.1
29 loop.1: ; preds = %loop.0, %loop.1
30 %index.1 = phi i32 [ %next.1, %loop.1 ], [ 10, %loop.0 ]
32 %next.1 = add nsw i32 %index.1, -1
33 %repeat.1 = icmp sgt i32 %index.1, 1
34 br i1 %repeat.1, label %loop.1, label %exit
36 exit: ; preds = %loop.1
42 ; CHECK-LABEL: define internal void @test3.loop.1()
43 ; CHECK-NEXT: newFuncRoot:
44 ; CHECK-NEXT: br label %loop.1
46 ; CHECK-NEXT: %index.1 = phi i32 [ %next.1, %loop.1.loop.1_crit_edge ], [ 10, %newFuncRoot ]
47 ; CHECK-NEXT: tail call void @foo()
48 ; CHECK-NEXT: %next.1 = add nsw i32 %index.1, -1
49 ; CHECK-NEXT: %repeat.1 = icmp sgt i32 %index.1, 1
50 ; CHECK-NEXT: br i1 %repeat.1, label %loop.1.loop.1_crit_edge, label %exit.exitStub
51 ; CHECK: loop.1.loop.1_crit_edge:
52 ; CHECK-NEXT: br label %loop.1
53 ; CHECK: exit.exitStub:
54 ; CHECK-NEXT: ret void
56 ; CHECK-LABEL: define internal void @test3.loop.0()
57 ; CHECK-NEXT: newFuncRoot:
58 ; CHECK-NEXT: br label %loop.0
60 ; CHECK-NEXT: %index.0 = phi i32 [ 10, %newFuncRoot ], [ %next.0, %loop.0.loop.0_crit_edge ]
61 ; CHECK-NEXT: tail call void @foo()
62 ; CHECK-NEXT: %next.0 = add nsw i32 %index.0, -1
63 ; CHECK-NEXT: %repeat.0 = icmp sgt i32 %index.0, 1
64 ; CHECK-NEXT: br i1 %repeat.0, label %loop.0.loop.0_crit_edge, label %loop.0.loop.1_crit_edge.exitStub
65 ; CHECK: loop.0.loop.0_crit_edge:
66 ; CHECK-NEXT: br label %loop.0
67 ; CHECK: loop.0.loop.1_crit_edge.exitStub:
68 ; CHECK-NEXT: ret void