1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -S | FileCheck %s
4 define void @signed(ptr %x, ptr %y, i32 %n) {
5 ; CHECK-LABEL: @signed(
7 ; CHECK-NEXT: [[X2:%.*]] = ptrtoint ptr [[X:%.*]] to i64
8 ; CHECK-NEXT: [[Y1:%.*]] = ptrtoint ptr [[Y:%.*]] to i64
9 ; CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[N:%.*]], 0
10 ; CHECK-NEXT: br i1 [[CMP6]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
11 ; CHECK: for.body.preheader:
12 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[N]] to i64
13 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[WIDE_TRIP_COUNT]], 4
14 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
15 ; CHECK: vector.memcheck:
16 ; CHECK-NEXT: [[TMP0:%.*]] = sub i64 [[Y1]], [[X2]]
17 ; CHECK-NEXT: [[DIFF_CHECK:%.*]] = icmp ult i64 [[TMP0]], 16
18 ; CHECK-NEXT: br i1 [[DIFF_CHECK]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
20 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[WIDE_TRIP_COUNT]], 4
21 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[WIDE_TRIP_COUNT]], [[N_MOD_VF]]
22 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
24 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
25 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 0
26 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds float, ptr [[X]], i64 [[TMP1]]
27 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds float, ptr [[TMP2]], i32 0
28 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP3]], align 4
29 ; CHECK-NEXT: [[TMP4:%.*]] = call <4 x i32> @llvm.fptosi.sat.v4i32.v4f32(<4 x float> [[WIDE_LOAD]])
30 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i32, ptr [[Y]], i64 [[TMP1]]
31 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[TMP5]], i32 0
32 ; CHECK-NEXT: store <4 x i32> [[TMP4]], ptr [[TMP6]], align 4
33 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
34 ; CHECK-NEXT: [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
35 ; CHECK-NEXT: br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
36 ; CHECK: middle.block:
37 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[WIDE_TRIP_COUNT]], [[N_VEC]]
38 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[SCALAR_PH]]
40 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER]] ], [ 0, [[VECTOR_MEMCHECK]] ]
41 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
42 ; CHECK: for.cond.cleanup.loopexit:
43 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
44 ; CHECK: for.cond.cleanup:
45 ; CHECK-NEXT: ret void
47 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
48 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, ptr [[X]], i64 [[INDVARS_IV]]
49 ; CHECK-NEXT: [[TMP8:%.*]] = load float, ptr [[ARRAYIDX]], align 4
50 ; CHECK-NEXT: [[TMP9:%.*]] = tail call i32 @llvm.fptosi.sat.i32.f32(float [[TMP8]])
51 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[Y]], i64 [[INDVARS_IV]]
52 ; CHECK-NEXT: store i32 [[TMP9]], ptr [[ARRAYIDX2]], align 4
53 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
54 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
55 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP2:![0-9]+]]
58 %cmp6 = icmp sgt i32 %n, 0
59 br i1 %cmp6, label %for.body.preheader, label %for.cond.cleanup
61 for.body.preheader: ; preds = %entry
62 %wide.trip.count = zext i32 %n to i64
65 for.cond.cleanup: ; preds = %for.body, %entry
68 for.body: ; preds = %for.body.preheader, %for.body
69 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
70 %arrayidx = getelementptr inbounds float, ptr %x, i64 %indvars.iv
71 %0 = load float, ptr %arrayidx, align 4
72 %1 = tail call i32 @llvm.fptosi.sat.i32.f32(float %0)
73 %arrayidx2 = getelementptr inbounds i32, ptr %y, i64 %indvars.iv
74 store i32 %1, ptr %arrayidx2, align 4
75 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
76 %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
77 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
80 define void @unsigned(ptr %x, ptr %y, i32 %n) {
81 ; CHECK-LABEL: @unsigned(
83 ; CHECK-NEXT: [[X2:%.*]] = ptrtoint ptr [[X:%.*]] to i64
84 ; CHECK-NEXT: [[Y1:%.*]] = ptrtoint ptr [[Y:%.*]] to i64
85 ; CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[N:%.*]], 0
86 ; CHECK-NEXT: br i1 [[CMP6]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
87 ; CHECK: for.body.preheader:
88 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[N]] to i64
89 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[WIDE_TRIP_COUNT]], 4
90 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
91 ; CHECK: vector.memcheck:
92 ; CHECK-NEXT: [[TMP0:%.*]] = sub i64 [[Y1]], [[X2]]
93 ; CHECK-NEXT: [[DIFF_CHECK:%.*]] = icmp ult i64 [[TMP0]], 16
94 ; CHECK-NEXT: br i1 [[DIFF_CHECK]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
96 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[WIDE_TRIP_COUNT]], 4
97 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[WIDE_TRIP_COUNT]], [[N_MOD_VF]]
98 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
100 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
101 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 0
102 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds float, ptr [[X]], i64 [[TMP1]]
103 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds float, ptr [[TMP2]], i32 0
104 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP3]], align 4
105 ; CHECK-NEXT: [[TMP4:%.*]] = call <4 x i32> @llvm.fptoui.sat.v4i32.v4f32(<4 x float> [[WIDE_LOAD]])
106 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i32, ptr [[Y]], i64 [[TMP1]]
107 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[TMP5]], i32 0
108 ; CHECK-NEXT: store <4 x i32> [[TMP4]], ptr [[TMP6]], align 4
109 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
110 ; CHECK-NEXT: [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
111 ; CHECK-NEXT: br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
112 ; CHECK: middle.block:
113 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[WIDE_TRIP_COUNT]], [[N_VEC]]
114 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP_LOOPEXIT:%.*]], label [[SCALAR_PH]]
116 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER]] ], [ 0, [[VECTOR_MEMCHECK]] ]
117 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
118 ; CHECK: for.cond.cleanup.loopexit:
119 ; CHECK-NEXT: br label [[FOR_COND_CLEANUP]]
120 ; CHECK: for.cond.cleanup:
121 ; CHECK-NEXT: ret void
123 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
124 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, ptr [[X]], i64 [[INDVARS_IV]]
125 ; CHECK-NEXT: [[TMP8:%.*]] = load float, ptr [[ARRAYIDX]], align 4
126 ; CHECK-NEXT: [[TMP9:%.*]] = tail call i32 @llvm.fptoui.sat.i32.f32(float [[TMP8]])
127 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[Y]], i64 [[INDVARS_IV]]
128 ; CHECK-NEXT: store i32 [[TMP9]], ptr [[ARRAYIDX2]], align 4
129 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
130 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], [[WIDE_TRIP_COUNT]]
131 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP_LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
134 %cmp6 = icmp sgt i32 %n, 0
135 br i1 %cmp6, label %for.body.preheader, label %for.cond.cleanup
137 for.body.preheader: ; preds = %entry
138 %wide.trip.count = zext i32 %n to i64
141 for.cond.cleanup: ; preds = %for.body, %entry
144 for.body: ; preds = %for.body.preheader, %for.body
145 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
146 %arrayidx = getelementptr inbounds float, ptr %x, i64 %indvars.iv
147 %0 = load float, ptr %arrayidx, align 4
148 %1 = tail call i32 @llvm.fptoui.sat.i32.f32(float %0)
149 %arrayidx2 = getelementptr inbounds i32, ptr %y, i64 %indvars.iv
150 store i32 %1, ptr %arrayidx2, align 4
151 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
152 %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
153 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
156 declare i32 @llvm.fptosi.sat.i32.f32(float)
157 declare i32 @llvm.fptoui.sat.i32.f32(float)