1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -loop-idiom -S %s | FileCheck %s 3 4; Make sure we do not delete instructions not inserted during expansion, e.g. 5; because the expande re-used existing instructions. 6 7define void @test(i64 %init, float* %ptr) { 8; CHECK-LABEL: @test( 9; CHECK-NEXT: entry: 10; CHECK-NEXT: br label [[OUTER_HEADER:%.*]] 11; CHECK: outer.header: 12; CHECK-NEXT: [[J_0:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[OUTER_LATCH:%.*]] ] 13; CHECK-NEXT: [[I_0:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[ADD:%.*]], [[OUTER_LATCH]] ] 14; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds float, float* [[PTR:%.*]], i32 [[I_0]] 15; CHECK-NEXT: br label [[INNER:%.*]] 16; CHECK: inner: 17; CHECK-NEXT: [[INNER_IV:%.*]] = phi i64 [ [[INNER_IV_NEXT:%.*]], [[INNER]] ], [ [[INIT:%.*]], [[OUTER_HEADER]] ] 18; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, float* [[PTR]], i64 [[INNER_IV]] 19; CHECK-NEXT: [[TMP0:%.*]] = bitcast float* [[ARRAYIDX]] to i32* 20; CHECK-NEXT: [[TMP1:%.*]] = load i32, i32* [[TMP0]], align 4 21; CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds float, float* [[ADD_PTR]], i64 [[INNER_IV]] 22; CHECK-NEXT: [[TMP2:%.*]] = bitcast float* [[ARRAYIDX3]] to i32* 23; CHECK-NEXT: store i32 [[TMP1]], i32* [[TMP2]], align 4 24; CHECK-NEXT: [[INNER_IV_NEXT]] = add nsw i64 [[INNER_IV]], 1 25; CHECK-NEXT: [[EC_1:%.*]] = icmp eq i64 [[INNER_IV_NEXT]], 0 26; CHECK-NEXT: br i1 [[EC_1]], label [[OUTER_LATCH]], label [[INNER]] 27; CHECK: outer.latch: 28; CHECK-NEXT: [[INC]] = add nuw nsw i32 [[J_0]], 1 29; CHECK-NEXT: [[ADD]] = add nuw nsw i32 [[I_0]], [[INC]] 30; CHECK-NEXT: [[EC_2:%.*]] = icmp eq i32 [[ADD]], 4000 31; CHECK-NEXT: br i1 [[EC_2]], label [[EXIT:%.*]], label [[OUTER_HEADER]] 32; CHECK: exit: 33; CHECK-NEXT: ret void 34; 35entry: 36 br label %outer.header 37 38outer.header: 39 %j.0 = phi i32 [ 0, %entry ], [ %inc, %outer.latch ] 40 %i.0 = phi i32 [ 0, %entry ], [ %add, %outer.latch ] 41 %add.ptr = getelementptr inbounds float, float* %ptr, i32 %i.0 42 br label %inner 43 44inner: 45 %inner.iv = phi i64 [ %inner.iv.next, %inner ], [ %init, %outer.header ] 46 %arrayidx = getelementptr inbounds float, float* %ptr, i64 %inner.iv 47 %0 = bitcast float* %arrayidx to i32* 48 %1 = load i32, i32* %0, align 4 49 %arrayidx3 = getelementptr inbounds float, float* %add.ptr, i64 %inner.iv 50 %2 = bitcast float* %arrayidx3 to i32* 51 store i32 %1, i32* %2, align 4 52 %inner.iv.next = add nsw i64 %inner.iv, 1 53 %ec.1 = icmp eq i64 %inner.iv.next, 0 54 br i1 %ec.1, label %outer.latch, label %inner 55 56outer.latch: 57 %inc = add nuw nsw i32 %j.0, 1 58 %add = add nuw nsw i32 %i.0, %inc 59 %ec.2 = icmp eq i32 %add, 4000 60 br i1 %ec.2, label %exit, label %outer.header 61 62exit: 63 ret void 64} 65