1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes='loop-mssa(licm)' < %s | FileCheck %s
4 declare i1 @cond(i32 %v) readnone
5 declare void @capture(i32* %p) readnone
7 define void @test_captured_after_loop(i32 %len) {
8 ; CHECK-LABEL: @test_captured_after_loop(
10 ; CHECK-NEXT: [[COUNT:%.*]] = alloca i32, align 4
11 ; CHECK-NEXT: store i32 0, i32* [[COUNT]], align 4
12 ; CHECK-NEXT: [[COUNT_PROMOTED:%.*]] = load i32, i32* [[COUNT]], align 4
13 ; CHECK-NEXT: br label [[LOOP:%.*]]
15 ; CHECK-NEXT: [[C_INC2:%.*]] = phi i32 [ [[COUNT_PROMOTED]], [[ENTRY:%.*]] ], [ [[C_INC1:%.*]], [[LATCH:%.*]] ]
16 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[I_NEXT:%.*]], [[LATCH]] ]
17 ; CHECK-NEXT: [[COND:%.*]] = call i1 @cond(i32 [[I]])
18 ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[LATCH]]
20 ; CHECK-NEXT: [[C_INC:%.*]] = add i32 [[C_INC2]], 1
21 ; CHECK-NEXT: br label [[LATCH]]
23 ; CHECK-NEXT: [[C_INC1]] = phi i32 [ [[C_INC]], [[IF]] ], [ [[C_INC2]], [[LOOP]] ]
24 ; CHECK-NEXT: [[I_NEXT]] = add nuw i32 [[I]], 1
25 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I_NEXT]], [[LEN:%.*]]
26 ; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[LOOP]]
28 ; CHECK-NEXT: [[C_INC1_LCSSA:%.*]] = phi i32 [ [[C_INC1]], [[LATCH]] ]
29 ; CHECK-NEXT: store i32 [[C_INC1_LCSSA]], i32* [[COUNT]], align 4
30 ; CHECK-NEXT: call void @capture(i32* [[COUNT]])
31 ; CHECK-NEXT: ret void
35 store i32 0, i32* %count
39 %i = phi i32 [ 0, %entry ], [ %i.next, %latch ]
40 %cond = call i1 @cond(i32 %i)
41 br i1 %cond, label %if, label %latch
44 %c = load i32, i32* %count
45 %c.inc = add i32 %c, 1
46 store i32 %c.inc, i32* %count
50 %i.next = add nuw i32 %i, 1
51 %cmp = icmp eq i32 %i.next, %len
52 br i1 %cmp, label %exit, label %loop
55 call void @capture(i32* %count)
59 define void @test_captured_in_loop(i32 %len) {
60 ; CHECK-LABEL: @test_captured_in_loop(
62 ; CHECK-NEXT: [[COUNT:%.*]] = alloca i32, align 4
63 ; CHECK-NEXT: store i32 0, i32* [[COUNT]], align 4
64 ; CHECK-NEXT: br label [[LOOP:%.*]]
66 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LATCH:%.*]] ]
67 ; CHECK-NEXT: [[COND:%.*]] = call i1 @cond(i32 [[I]])
68 ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[LATCH]]
70 ; CHECK-NEXT: [[C:%.*]] = load i32, i32* [[COUNT]], align 4
71 ; CHECK-NEXT: [[C_INC:%.*]] = add i32 [[C]], 1
72 ; CHECK-NEXT: store i32 [[C_INC]], i32* [[COUNT]], align 4
73 ; CHECK-NEXT: call void @capture(i32* [[COUNT]])
74 ; CHECK-NEXT: br label [[LATCH]]
76 ; CHECK-NEXT: [[I_NEXT]] = add nuw i32 [[I]], 1
77 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I_NEXT]], [[LEN:%.*]]
78 ; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[LOOP]]
80 ; CHECK-NEXT: ret void
84 store i32 0, i32* %count
88 %i = phi i32 [ 0, %entry ], [ %i.next, %latch ]
89 %cond = call i1 @cond(i32 %i)
90 br i1 %cond, label %if, label %latch
93 %c = load i32, i32* %count
94 %c.inc = add i32 %c, 1
95 store i32 %c.inc, i32* %count
96 call void @capture(i32* %count)
100 %i.next = add nuw i32 %i, 1
101 %cmp = icmp eq i32 %i.next, %len
102 br i1 %cmp, label %exit, label %loop
108 define void @test_captured_before_loop(i32 %len) {
109 ; CHECK-LABEL: @test_captured_before_loop(
111 ; CHECK-NEXT: [[COUNT:%.*]] = alloca i32, align 4
112 ; CHECK-NEXT: store i32 0, i32* [[COUNT]], align 4
113 ; CHECK-NEXT: call void @capture(i32* [[COUNT]])
114 ; CHECK-NEXT: br label [[LOOP:%.*]]
116 ; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[I_NEXT:%.*]], [[LATCH:%.*]] ]
117 ; CHECK-NEXT: [[COND:%.*]] = call i1 @cond(i32 [[I]])
118 ; CHECK-NEXT: br i1 [[COND]], label [[IF:%.*]], label [[LATCH]]
120 ; CHECK-NEXT: [[C:%.*]] = load i32, i32* [[COUNT]], align 4
121 ; CHECK-NEXT: [[C_INC:%.*]] = add i32 [[C]], 1
122 ; CHECK-NEXT: store i32 [[C_INC]], i32* [[COUNT]], align 4
123 ; CHECK-NEXT: br label [[LATCH]]
125 ; CHECK-NEXT: [[I_NEXT]] = add nuw i32 [[I]], 1
126 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[I_NEXT]], [[LEN:%.*]]
127 ; CHECK-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[LOOP]]
129 ; CHECK-NEXT: ret void
133 store i32 0, i32* %count
134 call void @capture(i32* %count)
138 %i = phi i32 [ 0, %entry ], [ %i.next, %latch ]
139 %cond = call i1 @cond(i32 %i)
140 br i1 %cond, label %if, label %latch
143 %c = load i32, i32* %count
144 %c.inc = add i32 %c, 1
145 store i32 %c.inc, i32* %count
149 %i.next = add nuw i32 %i, 1
150 %cmp = icmp eq i32 %i.next, %len
151 br i1 %cmp, label %exit, label %loop