1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -loop-idiom -S %s | FileCheck %s 3 4define void @phi_insertion(i1 %c, i32* %ptr.start, i32* %ptr.end, i64 %offset) { 5; CHECK-LABEL: @phi_insertion( 6; CHECK-NEXT: bb5: 7; CHECK-NEXT: br i1 [[C:%.*]], label [[LOOP_0_PH:%.*]], label [[EXIT:%.*]] 8; CHECK: loop.0.ph: 9; CHECK-NEXT: br label [[LOOP_0:%.*]] 10; CHECK: loop.0: 11; CHECK-NEXT: [[IV_0:%.*]] = phi i32* [ [[IV_0_NEXT:%.*]], [[LOOP_0_LATCH:%.*]] ], [ [[PTR_START:%.*]], [[LOOP_0_PH]] ] 12; CHECK-NEXT: [[COND:%.*]] = icmp eq i32* [[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:%.*]] 16; CHECK: loop.1: 17; CHECK-NEXT: [[PTR_1:%.*]] = getelementptr inbounds i32, i32* [[IV_0]], i64 0 18; CHECK-NEXT: [[LV:%.*]] = load i32, i32* [[PTR_1]], align 8 19; CHECK-NEXT: [[PTR_2:%.*]] = getelementptr inbounds i32, i32* [[IV_0]], i64 0 20; CHECK-NEXT: store i32 [[LV]], i32* [[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, i32* [[IV_0]], i64 [[OFFSET:%.*]] 26; CHECK-NEXT: br label [[LOOP_0]] 27; CHECK: exit.loopexit: 28; CHECK-NEXT: br label [[EXIT]] 29; CHECK: exit: 30; CHECK-NEXT: ret void 31; 32bb5: 33 br i1 %c, label %loop.0.ph, label %exit 34 35loop.0.ph: ; preds = %bb5 36 br label %loop.0 37 38loop.0: ; preds = %loop.0.latch, %loop.0.ph 39 %iv.0 = phi i32* [ %iv.0.next, %loop.0.latch ], [ %ptr.start, %loop.0.ph ] 40 %cond = icmp eq i32* %iv.0, %ptr.end 41 br i1 %cond, label %loop.1, label %exit 42 43loop.1: ; preds = %loop.1, %loop.0 44 %iv.1 = phi i64 [ 0, %loop.0 ], [ %iv.1, %loop.1 ] 45 %ptr.1 = getelementptr inbounds i32, i32* %iv.0, i64 %iv.1 46 %lv = load i32, i32* %ptr.1, align 8 47 %ptr.2 = getelementptr inbounds i32, i32* %iv.0, i64 %iv.1 48 store i32 %lv, i32* %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 52 53loop.0.latch: ; preds = %loop.1 54 %iv.0.next = getelementptr inbounds i32, i32* %iv.0, i64 %offset 55 br label %loop.0 56 57exit: ; preds = %loop.0, %bb5 58 ret void 59} 60