1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -force-vector-width=4 -force-vector-interleave=1 -passes='loop-vectorize,loop-load-elim' -S %s | FileCheck %s
4 @glob.1 = external global [100 x double]
5 @glob.2 = external global [100 x double]
7 define void @g(ptr %dst.1, ptr %start, i64 %N) {
9 ; CHECK-NEXT: loop.1.lver.check:
10 ; CHECK-NEXT: [[TMP0:%.*]] = shl i64 [[N:%.*]], 3
11 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[TMP0]], 16
12 ; CHECK-NEXT: [[UGLYGEP:%.*]] = getelementptr i8, ptr @glob.2, i64 [[TMP1]]
13 ; CHECK-NEXT: [[UGLYGEP2:%.*]] = getelementptr i8, ptr [[DST_1:%.*]], i64 8
14 ; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult ptr @glob.2, [[UGLYGEP2]]
15 ; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult ptr [[DST_1]], [[UGLYGEP]]
16 ; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
17 ; CHECK-NEXT: br i1 [[FOUND_CONFLICT]], label [[LOOP_1_PH_LVER_ORIG:%.*]], label [[LOOP_1_PH:%.*]]
18 ; CHECK: loop.1.ph.lver.orig:
19 ; CHECK-NEXT: br label [[LOOP_1_LVER_ORIG:%.*]]
20 ; CHECK: loop.1.lver.orig:
21 ; CHECK-NEXT: [[IV_LVER_ORIG:%.*]] = phi i64 [ 0, [[LOOP_1_PH_LVER_ORIG]] ], [ [[IV_NEXT_LVER_ORIG:%.*]], [[LOOP_1_LVER_ORIG]] ]
22 ; CHECK-NEXT: [[PTR_IV_1_LVER_ORIG:%.*]] = phi ptr [ @glob.1, [[LOOP_1_PH_LVER_ORIG]] ], [ [[PTR_IV_1_NEXT_LVER_ORIG:%.*]], [[LOOP_1_LVER_ORIG]] ]
23 ; CHECK-NEXT: [[GEP_IV_LVER_ORIG:%.*]] = getelementptr inbounds double, ptr @glob.2, i64 [[IV_LVER_ORIG]]
24 ; CHECK-NEXT: [[L_1_LVER_ORIG:%.*]] = load double, ptr [[GEP_IV_LVER_ORIG]], align 8
25 ; CHECK-NEXT: [[GEP_IV_1_LVER_ORIG:%.*]] = getelementptr inbounds double, ptr getelementptr inbounds (double, ptr @glob.2, i64 1), i64 [[IV_LVER_ORIG]]
26 ; CHECK-NEXT: store double 0.000000e+00, ptr [[GEP_IV_1_LVER_ORIG]], align 8
27 ; CHECK-NEXT: store double 0.000000e+00, ptr [[DST_1]], align 8
28 ; CHECK-NEXT: [[PTR_IV_1_NEXT_LVER_ORIG]] = getelementptr inbounds double, ptr [[PTR_IV_1_LVER_ORIG]], i64 1
29 ; CHECK-NEXT: [[IV_NEXT_LVER_ORIG]] = add nuw nsw i64 [[IV_LVER_ORIG]], 1
30 ; CHECK-NEXT: [[EXITCOND_NOT_LVER_ORIG:%.*]] = icmp eq i64 [[IV_LVER_ORIG]], [[N]]
31 ; CHECK-NEXT: br i1 [[EXITCOND_NOT_LVER_ORIG]], label [[LOOP_2_PH_LOOPEXIT:%.*]], label [[LOOP_1_LVER_ORIG]]
33 ; CHECK-NEXT: [[LOAD_INITIAL:%.*]] = load double, ptr @glob.2, align 8
34 ; CHECK-NEXT: br label [[LOOP_1:%.*]]
36 ; CHECK-NEXT: [[STORE_FORWARDED:%.*]] = phi double [ [[LOAD_INITIAL]], [[LOOP_1_PH]] ], [ 0.000000e+00, [[LOOP_1]] ]
37 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[LOOP_1_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP_1]] ]
38 ; CHECK-NEXT: [[PTR_IV_1:%.*]] = phi ptr [ @glob.1, [[LOOP_1_PH]] ], [ [[PTR_IV_1_NEXT:%.*]], [[LOOP_1]] ]
39 ; CHECK-NEXT: [[GEP_IV:%.*]] = getelementptr inbounds double, ptr @glob.2, i64 [[IV]]
40 ; CHECK-NEXT: [[L_1:%.*]] = load double, ptr [[GEP_IV]], align 8
41 ; CHECK-NEXT: [[GEP_IV_1:%.*]] = getelementptr inbounds double, ptr getelementptr inbounds (double, ptr @glob.2, i64 1), i64 [[IV]]
42 ; CHECK-NEXT: store double 0.000000e+00, ptr [[GEP_IV_1]], align 8
43 ; CHECK-NEXT: store double 0.000000e+00, ptr [[DST_1]], align 8
44 ; CHECK-NEXT: [[PTR_IV_1_NEXT]] = getelementptr inbounds double, ptr [[PTR_IV_1]], i64 1
45 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
46 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV]], [[N]]
47 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[LOOP_2_PH_LOOPEXIT3:%.*]], label [[LOOP_1]]
48 ; CHECK: loop.2.ph.loopexit:
49 ; CHECK-NEXT: [[LCSSA_PTR_IV_1_PH:%.*]] = phi ptr [ [[PTR_IV_1_LVER_ORIG]], [[LOOP_1_LVER_ORIG]] ]
50 ; CHECK-NEXT: br label [[LOOP_2_PH:%.*]]
51 ; CHECK: loop.2.ph.loopexit3:
52 ; CHECK-NEXT: [[LCSSA_PTR_IV_1_PH4:%.*]] = phi ptr [ [[PTR_IV_1]], [[LOOP_1]] ]
53 ; CHECK-NEXT: br label [[LOOP_2_PH]]
55 ; CHECK-NEXT: [[LCSSA_PTR_IV_1:%.*]] = phi ptr [ [[LCSSA_PTR_IV_1_PH]], [[LOOP_2_PH_LOOPEXIT]] ], [ [[LCSSA_PTR_IV_1_PH4]], [[LOOP_2_PH_LOOPEXIT3]] ]
56 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4
57 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
59 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N]], 4
60 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]]
61 ; CHECK-NEXT: [[TMP2:%.*]] = mul i64 [[N_VEC]], 8
62 ; CHECK-NEXT: [[IND_END:%.*]] = getelementptr i8, ptr [[LCSSA_PTR_IV_1]], i64 [[TMP2]]
63 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
65 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
66 ; CHECK-NEXT: [[OFFSET_IDX:%.*]] = mul i64 [[INDEX]], 8
67 ; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[OFFSET_IDX]], 0
68 ; CHECK-NEXT: [[NEXT_GEP:%.*]] = getelementptr i8, ptr [[LCSSA_PTR_IV_1]], i64 [[TMP4]]
69 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr double, ptr [[NEXT_GEP]], i32 0
70 ; CHECK-NEXT: store <4 x double> zeroinitializer, ptr [[TMP5]], align 8
71 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
72 ; CHECK-NEXT: [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
73 ; CHECK-NEXT: br i1 [[TMP6]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
74 ; CHECK: middle.block:
75 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]]
76 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
78 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[LOOP_2_PH]] ]
79 ; CHECK-NEXT: [[BC_RESUME_VAL1:%.*]] = phi ptr [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ [[LCSSA_PTR_IV_1]], [[LOOP_2_PH]] ]
80 ; CHECK-NEXT: br label [[LOOP_2:%.*]]
82 ; CHECK-NEXT: [[IV_2:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_2_NEXT:%.*]], [[LOOP_2]] ]
83 ; CHECK-NEXT: [[PTR_IV_2:%.*]] = phi ptr [ [[BC_RESUME_VAL1]], [[SCALAR_PH]] ], [ [[PTR_IV_2_NEXT:%.*]], [[LOOP_2]] ]
84 ; CHECK-NEXT: store double 0.000000e+00, ptr [[PTR_IV_2]], align 8
85 ; CHECK-NEXT: [[PTR_IV_2_NEXT]] = getelementptr inbounds double, ptr [[PTR_IV_2]], i64 1
86 ; CHECK-NEXT: [[IV_2_NEXT]] = add nuw nsw i64 [[IV_2]], 1
87 ; CHECK-NEXT: [[EXITCOND_1_NOT:%.*]] = icmp eq i64 [[IV_2_NEXT]], [[N]]
88 ; CHECK-NEXT: br i1 [[EXITCOND_1_NOT]], label [[EXIT_LOOPEXIT:%.*]], label [[LOOP_2]], !llvm.loop [[LOOP2:![0-9]+]]
89 ; CHECK: exit.loopexit:
90 ; CHECK-NEXT: br label [[EXIT]]
92 ; CHECK-NEXT: ret void
98 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.1 ]
99 %ptr.iv.1 = phi ptr [ @glob.1, %entry ], [ %ptr.iv.1.next, %loop.1 ]
100 %gep.iv = getelementptr inbounds double, ptr @glob.2, i64 %iv
101 %l.1 = load double, ptr %gep.iv, align 8
102 %gep.iv.1 = getelementptr inbounds double, ptr getelementptr inbounds (double, ptr @glob.2, i64 1), i64 %iv
103 store double 0.000000e+00, ptr %gep.iv.1, align 8
104 store double 0.000000e+00, ptr %dst.1, align 8
105 %ptr.iv.1.next = getelementptr inbounds double, ptr %ptr.iv.1, i64 1
106 %iv.next = add nuw nsw i64 %iv, 1
107 %exitcond.not = icmp eq i64 %iv, %N
108 br i1 %exitcond.not, label %loop.2.ph, label %loop.1
111 %lcssa.ptr.iv.1 = phi ptr [ %ptr.iv.1, %loop.1 ]
115 %iv.2 = phi i64 [ 0, %loop.2.ph ] , [ %iv.2.next, %loop.2 ]
116 %ptr.iv.2 = phi ptr [ %lcssa.ptr.iv.1, %loop.2.ph ], [ %ptr.iv.2.next, %loop.2 ]
117 store double 0.000000e+00, ptr %ptr.iv.2, align 8
118 %ptr.iv.2.next = getelementptr inbounds double, ptr %ptr.iv.2, i64 1
119 %iv.2.next = add nuw nsw i64 %iv.2, 1
120 %exitcond.1.not = icmp eq i64 %iv.2.next, %N
121 br i1 %exitcond.1.not, label %exit, label %loop.2