1 ; RUN: llc < %s -mtriple=armv7-apple-darwin | FileCheck %s
2 ; PHI elimination shouldn't break backedge.
5 %struct.list_data_s = type { i16, i16 }
6 %struct.list_head = type { %struct.list_head*, %struct.list_data_s* }
8 define arm_apcscc %struct.list_head* @t1(%struct.list_head* %list) nounwind {
11 %0 = icmp eq %struct.list_head* %list, null
12 br i1 %0, label %bb2, label %bb
15 ; CHECK: LBB0_[[LABEL:[0-9]]]:
16 ; CHECK: bne LBB0_[[LABEL]]
17 ; CHECK-NOT: b LBB0_[[LABEL]]
19 %list_addr.05 = phi %struct.list_head* [ %2, %bb ], [ %list, %entry ]
20 %next.04 = phi %struct.list_head* [ %list_addr.05, %bb ], [ null, %entry ]
21 %1 = getelementptr inbounds %struct.list_head, %struct.list_head* %list_addr.05, i32 0, i32 0
22 %2 = load %struct.list_head*, %struct.list_head** %1, align 4
23 store %struct.list_head* %next.04, %struct.list_head** %1, align 4
24 %3 = icmp eq %struct.list_head* %2, null
25 br i1 %3, label %bb2, label %bb
28 %next.0.lcssa = phi %struct.list_head* [ null, %entry ], [ %list_addr.05, %bb ]
29 ret %struct.list_head* %next.0.lcssa
32 ; Optimize loop entry, eliminate intra loop branches
34 define i32 @t2(i32 %passes, i32* nocapture %src, i32 %size) nounwind readonly {
37 %0 = icmp eq i32 %passes, 0 ; <i1> [#uses=1]
38 br i1 %0, label %bb5, label %bb.nph15
40 bb1: ; preds = %bb2.preheader, %bb1
41 ; CHECK: LBB1_[[BB3:.]]: @ %bb3
42 ; CHECK: LBB1_[[PREHDR:.]]: @ %bb2.preheader
43 ; CHECK: bmi LBB1_[[BB3]]
44 %indvar = phi i32 [ %indvar.next, %bb1 ], [ 0, %bb2.preheader ] ; <i32> [#uses=2]
45 %sum.08 = phi i32 [ %2, %bb1 ], [ %sum.110, %bb2.preheader ] ; <i32> [#uses=1]
46 %tmp17 = sub i32 %i.07, %indvar ; <i32> [#uses=1]
47 %scevgep = getelementptr i32, i32* %src, i32 %tmp17 ; <i32*> [#uses=1]
48 %1 = load i32, i32* %scevgep, align 4 ; <i32> [#uses=1]
49 %2 = add nsw i32 %1, %sum.08 ; <i32> [#uses=2]
50 %indvar.next = add i32 %indvar, 1 ; <i32> [#uses=2]
51 %exitcond = icmp eq i32 %indvar.next, %size ; <i1> [#uses=1]
52 br i1 %exitcond, label %bb3, label %bb1
54 bb3: ; preds = %bb1, %bb2.preheader
55 ; CHECK: LBB1_[[BB1:.]]: @ %bb1
56 ; CHECK: bne LBB1_[[BB1]]
57 %sum.0.lcssa = phi i32 [ %sum.110, %bb2.preheader ], [ %2, %bb1 ] ; <i32> [#uses=2]
58 %3 = add i32 %pass.011, 1 ; <i32> [#uses=2]
59 %exitcond18 = icmp eq i32 %3, %passes ; <i1> [#uses=1]
60 br i1 %exitcond18, label %bb5, label %bb2.preheader
62 bb.nph15: ; preds = %entry
63 %i.07 = add i32 %size, -1 ; <i32> [#uses=2]
64 %4 = icmp sgt i32 %i.07, -1 ; <i1> [#uses=1]
65 br label %bb2.preheader
67 bb2.preheader: ; preds = %bb3, %bb.nph15
68 %pass.011 = phi i32 [ 0, %bb.nph15 ], [ %3, %bb3 ] ; <i32> [#uses=1]
69 %sum.110 = phi i32 [ 0, %bb.nph15 ], [ %sum.0.lcssa, %bb3 ] ; <i32> [#uses=2]
70 br i1 %4, label %bb1, label %bb3
72 bb5: ; preds = %bb3, %entry
73 %sum.1.lcssa = phi i32 [ 0, %entry ], [ %sum.0.lcssa, %bb3 ] ; <i32> [#uses=1]