1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -loop-unroll -unroll-count=2 -S | FileCheck %s
4 ; LoopUnroll should unroll this loop into one big basic block.
5 define void @latch_exit(double* nocapture %p, i64 %n) nounwind {
6 ; CHECK-LABEL: @latch_exit(
8 ; CHECK-NEXT: [[MUL10:%.*]] = shl i64 [[N:%.*]], 1
9 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
11 ; CHECK-NEXT: [[I_013:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[TMP16_1:%.*]], [[FOR_BODY]] ]
12 ; CHECK-NEXT: [[ARRAYIDX7:%.*]] = getelementptr double, double* [[P:%.*]], i64 [[I_013]]
13 ; CHECK-NEXT: [[TMP16:%.*]] = add nuw nsw i64 [[I_013]], 1
14 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr double, double* [[P]], i64 [[TMP16]]
15 ; CHECK-NEXT: [[TMP4:%.*]] = load double, double* [[ARRAYIDX]], align 8
16 ; CHECK-NEXT: [[TMP8:%.*]] = load double, double* [[ARRAYIDX7]], align 8
17 ; CHECK-NEXT: [[MUL9:%.*]] = fmul double [[TMP8]], [[TMP4]]
18 ; CHECK-NEXT: store double [[MUL9]], double* [[ARRAYIDX7]], align 8
19 ; CHECK-NEXT: [[ARRAYIDX7_1:%.*]] = getelementptr double, double* [[P]], i64 [[TMP16]]
20 ; CHECK-NEXT: [[TMP16_1]] = add i64 [[TMP16]], 1
21 ; CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr double, double* [[P]], i64 [[TMP16_1]]
22 ; CHECK-NEXT: [[TMP4_1:%.*]] = load double, double* [[ARRAYIDX_1]], align 8
23 ; CHECK-NEXT: [[TMP8_1:%.*]] = load double, double* [[ARRAYIDX7_1]], align 8
24 ; CHECK-NEXT: [[MUL9_1:%.*]] = fmul double [[TMP8_1]], [[TMP4_1]]
25 ; CHECK-NEXT: store double [[MUL9_1]], double* [[ARRAYIDX7_1]], align 8
26 ; CHECK-NEXT: [[EXITCOND_1:%.*]] = icmp eq i64 [[TMP16_1]], [[MUL10]]
27 ; CHECK-NEXT: br i1 [[EXITCOND_1]], label [[FOR_END:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
29 ; CHECK-NEXT: ret void
32 %mul10 = shl i64 %n, 1
36 %i.013 = phi i64 [ %tmp16, %for.body ], [ 0, %entry ]
37 %arrayidx7 = getelementptr double, double* %p, i64 %i.013
38 %tmp16 = add i64 %i.013, 1
39 %arrayidx = getelementptr double, double* %p, i64 %tmp16
40 %tmp4 = load double, double* %arrayidx
41 %tmp8 = load double, double* %arrayidx7
42 %mul9 = fmul double %tmp8, %tmp4
43 store double %mul9, double* %arrayidx7
44 %exitcond = icmp eq i64 %tmp16, %mul10
45 br i1 %exitcond, label %for.end, label %for.body
51 ; Same as previous test case, but with a non-latch exit. There shouldn't
52 ; be a conditional branch after the first block.
53 define void @non_latch_exit(double* nocapture %p, i64 %n) nounwind {
54 ; CHECK-LABEL: @non_latch_exit(
56 ; CHECK-NEXT: [[MUL10:%.*]] = shl i64 [[N:%.*]], 1
57 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
59 ; CHECK-NEXT: [[I_013:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[TMP16_1:%.*]], [[LATCH_1:%.*]] ]
60 ; CHECK-NEXT: [[ARRAYIDX7:%.*]] = getelementptr double, double* [[P:%.*]], i64 [[I_013]]
61 ; CHECK-NEXT: [[TMP16:%.*]] = add nuw nsw i64 [[I_013]], 1
62 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr double, double* [[P]], i64 [[TMP16]]
63 ; CHECK-NEXT: [[TMP4:%.*]] = load double, double* [[ARRAYIDX]], align 8
64 ; CHECK-NEXT: [[TMP8:%.*]] = load double, double* [[ARRAYIDX7]], align 8
65 ; CHECK-NEXT: [[MUL9:%.*]] = fmul double [[TMP8]], [[TMP4]]
66 ; CHECK-NEXT: store double [[MUL9]], double* [[ARRAYIDX7]], align 8
67 ; CHECK-NEXT: br label [[LATCH:%.*]]
69 ; CHECK-NEXT: [[ARRAYIDX7_1:%.*]] = getelementptr double, double* [[P]], i64 [[TMP16]]
70 ; CHECK-NEXT: [[TMP16_1]] = add i64 [[TMP16]], 1
71 ; CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr double, double* [[P]], i64 [[TMP16_1]]
72 ; CHECK-NEXT: [[TMP4_1:%.*]] = load double, double* [[ARRAYIDX_1]], align 8
73 ; CHECK-NEXT: [[TMP8_1:%.*]] = load double, double* [[ARRAYIDX7_1]], align 8
74 ; CHECK-NEXT: [[MUL9_1:%.*]] = fmul double [[TMP8_1]], [[TMP4_1]]
75 ; CHECK-NEXT: store double [[MUL9_1]], double* [[ARRAYIDX7_1]], align 8
76 ; CHECK-NEXT: [[EXITCOND_1:%.*]] = icmp eq i64 [[TMP16_1]], [[MUL10]]
77 ; CHECK-NEXT: br i1 [[EXITCOND_1]], label [[FOR_END:%.*]], label [[LATCH_1]]
79 ; CHECK-NEXT: ret void
81 ; CHECK-NEXT: br label [[FOR_BODY]], !llvm.loop [[LOOP2:![0-9]+]]
84 %mul10 = shl i64 %n, 1
88 %i.013 = phi i64 [ %tmp16, %latch ], [ 0, %entry ]
89 %arrayidx7 = getelementptr double, double* %p, i64 %i.013
90 %tmp16 = add i64 %i.013, 1
91 %arrayidx = getelementptr double, double* %p, i64 %tmp16
92 %tmp4 = load double, double* %arrayidx
93 %tmp8 = load double, double* %arrayidx7
94 %mul9 = fmul double %tmp8, %tmp4
95 store double %mul9, double* %arrayidx7
96 %exitcond = icmp eq i64 %tmp16, %mul10
97 br i1 %exitcond, label %for.end, label %latch