1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -mtriple=x86_64 -mattr=-avx,-avx2,-avx512f,+sse,-sse2,-sse3,-sse4.2 -passes=loop-vectorize -S %s | FileCheck --check-prefix=NOVEC %s
3 ; RUN: opt -mtriple=x86_64 -mattr=-avx,-avx2,-avx512f,+sse,-sse2,-sse3,-sse4.2 -passes=loop-vectorize -force-vector-width=4 -S %s | FileCheck --check-prefix=VEC %s
7 define void @test(ptr %p) {
8 ; NOVEC-LABEL: define void @test(
9 ; NOVEC-SAME: ptr [[P:%.*]]) #[[ATTR0:[0-9]+]] {
11 ; NOVEC-NEXT: br label [[FOR_BODY:%.*]]
13 ; NOVEC-NEXT: [[IDX_EXT_MERGE:%.*]] = phi i64 [ 1, [[ENTRY:%.*]] ], [ [[IDX:%.*]], [[FOR_BODY]] ]
14 ; NOVEC-NEXT: [[INC_MERGE:%.*]] = phi i16 [ 1, [[ENTRY]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
15 ; NOVEC-NEXT: [[IDX_MERGE:%.*]] = phi i64 [ 0, [[ENTRY]] ], [ [[IDX_EXT_MERGE]], [[FOR_BODY]] ]
16 ; NOVEC-NEXT: [[ADD:%.*]] = shl i64 [[IDX_MERGE]], 1
17 ; NOVEC-NEXT: [[ARRAYIDX:%.*]] = getelementptr i64, ptr [[P]], i64 [[ADD]]
18 ; NOVEC-NEXT: store i64 0, ptr [[ARRAYIDX]], align 8
19 ; NOVEC-NEXT: [[INC]] = add i16 [[INC_MERGE]], 1
20 ; NOVEC-NEXT: [[IDX]] = zext i16 [[INC]] to i64
21 ; NOVEC-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[P]], i64 [[IDX]]
22 ; NOVEC-NEXT: [[CMP:%.*]] = icmp ugt ptr [[GEP]], @h
23 ; NOVEC-NEXT: br i1 [[CMP]], label [[EXIT:%.*]], label [[FOR_BODY]]
25 ; NOVEC-NEXT: ret void
27 ; VEC-LABEL: define void @test(
28 ; VEC-SAME: ptr [[P:%.*]]) #[[ATTR0:[0-9]+]] {
30 ; VEC-NEXT: [[P1:%.*]] = ptrtoint ptr [[P]] to i64
31 ; VEC-NEXT: [[TMP0:%.*]] = add i64 [[P1]], 16
32 ; VEC-NEXT: [[UMAX2:%.*]] = call i64 @llvm.umax.i64(i64 [[TMP0]], i64 add (i64 ptrtoint (ptr @h to i64), i64 1))
33 ; VEC-NEXT: [[TMP1:%.*]] = add i64 [[UMAX2]], -9
34 ; VEC-NEXT: [[TMP2:%.*]] = sub i64 [[TMP1]], [[P1]]
35 ; VEC-NEXT: [[TMP3:%.*]] = lshr i64 [[TMP2]], 3
36 ; VEC-NEXT: [[TMP4:%.*]] = add nuw nsw i64 [[TMP3]], 1
37 ; VEC-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP4]], 4
38 ; VEC-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
39 ; VEC: vector.scevcheck:
40 ; VEC-NEXT: [[TMP5:%.*]] = add i64 [[P1]], 16
41 ; VEC-NEXT: [[UMAX:%.*]] = call i64 @llvm.umax.i64(i64 [[TMP5]], i64 add (i64 ptrtoint (ptr @h to i64), i64 1))
42 ; VEC-NEXT: [[TMP6:%.*]] = add i64 [[UMAX]], -9
43 ; VEC-NEXT: [[TMP7:%.*]] = sub i64 [[TMP6]], [[P1]]
44 ; VEC-NEXT: [[TMP8:%.*]] = lshr i64 [[TMP7]], 3
45 ; VEC-NEXT: [[TMP9:%.*]] = icmp ugt i64 [[TMP8]], 65535
46 ; VEC-NEXT: [[TMP10:%.*]] = trunc i64 [[TMP8]] to i16
47 ; VEC-NEXT: [[TMP11:%.*]] = add i16 2, [[TMP10]]
48 ; VEC-NEXT: [[TMP12:%.*]] = icmp ult i16 [[TMP11]], 2
49 ; VEC-NEXT: [[TMP13:%.*]] = icmp ugt i64 [[TMP8]], 65535
50 ; VEC-NEXT: [[TMP14:%.*]] = or i1 [[TMP12]], [[TMP13]]
51 ; VEC-NEXT: br i1 [[TMP14]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
53 ; VEC-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP4]], 4
54 ; VEC-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP4]], [[N_MOD_VF]]
55 ; VEC-NEXT: [[DOTCAST:%.*]] = trunc i64 [[N_VEC]] to i16
56 ; VEC-NEXT: [[IND_END:%.*]] = add i16 1, [[DOTCAST]]
57 ; VEC-NEXT: br label [[VECTOR_BODY:%.*]]
59 ; VEC-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
60 ; VEC-NEXT: [[VECTOR_RECUR:%.*]] = phi <4 x i64> [ <i64 poison, i64 poison, i64 poison, i64 1>, [[VECTOR_PH]] ], [ [[TMP28:%.*]], [[VECTOR_BODY]] ]
61 ; VEC-NEXT: [[VEC_IND:%.*]] = phi <4 x i16> [ <i16 1, i16 2, i16 3, i16 4>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
62 ; VEC-NEXT: [[TMP15:%.*]] = add i64 [[INDEX]], 0
63 ; VEC-NEXT: [[TMP16:%.*]] = add i64 [[INDEX]], 1
64 ; VEC-NEXT: [[TMP17:%.*]] = add i64 [[INDEX]], 2
65 ; VEC-NEXT: [[TMP18:%.*]] = add i64 [[INDEX]], 3
66 ; VEC-NEXT: [[TMP19:%.*]] = shl i64 [[TMP15]], 1
67 ; VEC-NEXT: [[TMP20:%.*]] = shl i64 [[TMP16]], 1
68 ; VEC-NEXT: [[TMP21:%.*]] = shl i64 [[TMP17]], 1
69 ; VEC-NEXT: [[TMP22:%.*]] = shl i64 [[TMP18]], 1
70 ; VEC-NEXT: [[TMP23:%.*]] = getelementptr i64, ptr [[P]], i64 [[TMP19]]
71 ; VEC-NEXT: [[TMP24:%.*]] = getelementptr i64, ptr [[P]], i64 [[TMP20]]
72 ; VEC-NEXT: [[TMP25:%.*]] = getelementptr i64, ptr [[P]], i64 [[TMP21]]
73 ; VEC-NEXT: [[TMP26:%.*]] = getelementptr i64, ptr [[P]], i64 [[TMP22]]
74 ; VEC-NEXT: store i64 0, ptr [[TMP23]], align 8
75 ; VEC-NEXT: store i64 0, ptr [[TMP24]], align 8
76 ; VEC-NEXT: store i64 0, ptr [[TMP25]], align 8
77 ; VEC-NEXT: store i64 0, ptr [[TMP26]], align 8
78 ; VEC-NEXT: [[TMP27:%.*]] = add <4 x i16> [[VEC_IND]], <i16 1, i16 1, i16 1, i16 1>
79 ; VEC-NEXT: [[TMP28]] = zext <4 x i16> [[TMP27]] to <4 x i64>
80 ; VEC-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
81 ; VEC-NEXT: [[VEC_IND_NEXT]] = add <4 x i16> [[VEC_IND]], <i16 4, i16 4, i16 4, i16 4>
82 ; VEC-NEXT: [[TMP30:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
83 ; VEC-NEXT: br i1 [[TMP30]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
85 ; VEC-NEXT: [[VECTOR_RECUR_EXTRACT:%.*]] = extractelement <4 x i64> [[TMP28]], i32 3
86 ; VEC-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[TMP4]], [[N_VEC]]
87 ; VEC-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
89 ; VEC-NEXT: [[BC_RESUME_VAL:%.*]] = phi i16 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 1, [[ENTRY:%.*]] ], [ 1, [[VECTOR_SCEVCHECK]] ]
90 ; VEC-NEXT: [[BC_RESUME_VAL3:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
91 ; VEC-NEXT: [[SCALAR_RECUR_INIT:%.*]] = phi i64 [ [[VECTOR_RECUR_EXTRACT]], [[MIDDLE_BLOCK]] ], [ 1, [[VECTOR_SCEVCHECK]] ], [ 1, [[ENTRY]] ]
92 ; VEC-NEXT: br label [[FOR_BODY:%.*]]
94 ; VEC-NEXT: [[SCALAR_RECUR:%.*]] = phi i64 [ [[SCALAR_RECUR_INIT]], [[SCALAR_PH]] ], [ [[IDX:%.*]], [[FOR_BODY]] ]
95 ; VEC-NEXT: [[INC_MERGE:%.*]] = phi i16 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
96 ; VEC-NEXT: [[IDX_MERGE:%.*]] = phi i64 [ [[BC_RESUME_VAL3]], [[SCALAR_PH]] ], [ [[SCALAR_RECUR]], [[FOR_BODY]] ]
97 ; VEC-NEXT: [[ADD:%.*]] = shl i64 [[IDX_MERGE]], 1
98 ; VEC-NEXT: [[ARRAYIDX:%.*]] = getelementptr i64, ptr [[P]], i64 [[ADD]]
99 ; VEC-NEXT: store i64 0, ptr [[ARRAYIDX]], align 8
100 ; VEC-NEXT: [[INC]] = add i16 [[INC_MERGE]], 1
101 ; VEC-NEXT: [[IDX]] = zext i16 [[INC]] to i64
102 ; VEC-NEXT: [[GEP:%.*]] = getelementptr i64, ptr [[P]], i64 [[IDX]]
103 ; VEC-NEXT: [[CMP:%.*]] = icmp ugt ptr [[GEP]], @h
104 ; VEC-NEXT: br i1 [[CMP]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
112 %idx.ext.merge = phi i64 [ 1, %entry ], [ %idx, %for.body ]
113 %inc.merge = phi i16 [ 1, %entry ], [ %inc, %for.body ]
114 %idx.merge = phi i64 [ 0, %entry ], [ %idx.ext.merge, %for.body ]
115 %add = shl i64 %idx.merge, 1
116 %arrayidx = getelementptr i64, ptr %p, i64 %add
117 store i64 0, ptr %arrayidx
118 %inc = add i16 %inc.merge, 1
119 %idx = zext i16 %inc to i64
120 %gep = getelementptr i64, ptr %p, i64 %idx
121 %cmp = icmp ugt ptr %gep, @h
122 br i1 %cmp, label %exit, label %for.body
128 ; VEC: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]}
129 ; VEC: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
130 ; VEC: [[META2]] = !{!"llvm.loop.unroll.runtime.disable"}
131 ; VEC: [[LOOP3]] = distinct !{[[LOOP3]], [[META1]]}