1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-idiom -S %s | FileCheck %s
4 define void @phi_insertion(i1 %c, ptr %ptr.start, ptr %ptr.end, i64 %offset) {
5 ; CHECK-LABEL: @phi_insertion(
7 ; CHECK-NEXT: br i1 [[C:%.*]], label [[LOOP_0_PH:%.*]], label [[EXIT:%.*]]
9 ; CHECK-NEXT: br label [[LOOP_0:%.*]]
11 ; CHECK-NEXT: [[IV_0:%.*]] = phi ptr [ [[IV_0_NEXT:%.*]], [[LOOP_0_LATCH:%.*]] ], [ [[PTR_START:%.*]], [[LOOP_0_PH]] ]
12 ; CHECK-NEXT: [[COND:%.*]] = icmp eq ptr [[IV_0]], [[PTR_END:%.*]]
13 ; CHECK-NEXT: br i1 [[COND]], label [[LOOP_1_PREHEADER:%.*]], label [[EXIT_LOOPEXIT:%.*]]
14 ; CHECK: loop.1.preheader:
15 ; CHECK-NEXT: br label [[LOOP_1:%.*]]
17 ; CHECK-NEXT: [[PTR_1:%.*]] = getelementptr inbounds i32, ptr [[IV_0]], i64 0
18 ; CHECK-NEXT: [[LV:%.*]] = load i32, ptr [[PTR_1]], align 8
19 ; CHECK-NEXT: [[PTR_2:%.*]] = getelementptr inbounds i32, ptr [[IV_0]], i64 0
20 ; CHECK-NEXT: store i32 [[LV]], ptr [[PTR_2]], align 8
21 ; CHECK-NEXT: [[IV_1_NEXT:%.*]] = add nuw nsw i64 0, 1
22 ; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_1_NEXT]], 100
23 ; CHECK-NEXT: br i1 [[EC]], label [[LOOP_0_LATCH]], label [[LOOP_1]]
24 ; CHECK: loop.0.latch:
25 ; CHECK-NEXT: [[IV_0_NEXT]] = getelementptr inbounds i32, ptr [[IV_0]], i64 [[OFFSET:%.*]]
26 ; CHECK-NEXT: br label [[LOOP_0]]
27 ; CHECK: exit.loopexit:
28 ; CHECK-NEXT: br label [[EXIT]]
30 ; CHECK-NEXT: ret void
33 br i1 %c, label %loop.0.ph, label %exit
35 loop.0.ph: ; preds = %bb5
38 loop.0: ; preds = %loop.0.latch, %loop.0.ph
39 %iv.0 = phi ptr [ %iv.0.next, %loop.0.latch ], [ %ptr.start, %loop.0.ph ]
40 %cond = icmp eq ptr %iv.0, %ptr.end
41 br i1 %cond, label %loop.1, label %exit
43 loop.1: ; preds = %loop.1, %loop.0
44 %iv.1 = phi i64 [ 0, %loop.0 ], [ %iv.1, %loop.1 ]
45 %ptr.1 = getelementptr inbounds i32, ptr %iv.0, i64 %iv.1
46 %lv = load i32, ptr %ptr.1, align 8
47 %ptr.2 = getelementptr inbounds i32, ptr %iv.0, i64 %iv.1
48 store i32 %lv, ptr %ptr.2, align 8
49 %iv.1.next = add nuw nsw i64 %iv.1, 1
50 %ec = icmp eq i64 %iv.1.next, 100
51 br i1 %ec, label %loop.0.latch, label %loop.1
53 loop.0.latch: ; preds = %loop.1
54 %iv.0.next = getelementptr inbounds i32, ptr %iv.0, i64 %offset
57 exit: ; preds = %loop.0, %bb5