1; RUN: opt -loop-vectorize -force-vector-width=4 -S %s | FileCheck %s
2
3@dst = external global [32 x i16], align 1
4
5define void @blend_uniform_iv_trunc(i1 %c) {
6; CHECK-LABEL: @blend_uniform_iv_trunc(
7; CHECK:       vector.ph:
8; CHECK-NEXT:    [[MASK0:%.*]] = insertelement <4 x i1> poison, i1 %c, i32 0
9; CHECK-NEXT:    [[MASK1:%.*]] = shufflevector <4 x i1> [[MASK0]], <4 x i1> poison, <4 x i32> zeroinitializer
10
11; CHECK:       vector.body:
12; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
13; CHECK-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
14; CHECK-NEXT:    [[TMP1:%.*]] = trunc i64 [[INDEX]] to i16
15; CHECK-NEXT:    [[TMP2:%.*]] = add i16 [[TMP1]], 0
16; CHECK-NEXT:    [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <4 x i16> poison, i16 [[TMP2]], i32 0
17; CHECK-NEXT:    [[BROADCAST_SPLAT2:%.*]] = shufflevector <4 x i16> [[BROADCAST_SPLATINSERT1]], <4 x i16> poison, <4 x i32> zeroinitializer
18; CHECK-NEXT:    [[TMP3:%.*]] = xor <4 x i1> [[MASK1]], <i1 true, i1 true, i1 true, i1 true>
19; CHECK-NEXT:    [[PREDPHI:%.*]] = select <4 x i1> [[MASK1]], <4 x i16> [[BROADCAST_SPLAT2]], <4 x i16> undef
20; CHECK-NEXT:    [[TMP4:%.*]] = extractelement <4 x i16> [[PREDPHI]], i32 0
21; CHECK-NEXT:    [[TMP5:%.*]] = getelementptr inbounds [32 x i16], [32 x i16]* @dst, i16 0, i16 [[TMP4]]
22; CHECK-NEXT:    [[TMP6:%.*]] = getelementptr inbounds i16, i16* [[TMP5]], i32 0
23; CHECK-NEXT:    [[TMP7:%.*]] = bitcast i16* [[TMP6]] to <4 x i16>*
24; CHECK-NEXT:    store <4 x i16> zeroinitializer, <4 x i16>* [[TMP7]], align 2
25; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
26; CHECK-NEXT:    [[TMP8:%.*]] = icmp eq i64 [[INDEX_NEXT]], 32
27; CHECK-NEXT:    br i1 [[TMP8]], label %middle.block, label %vector.body
28;
29entry:
30  br label %loop.header
31
32loop.header:                                      ; preds = %loop.latch, %entry
33  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
34  %iv.trunc.2 = trunc i64 %iv to i16
35  br i1 %c, label %loop.next, label %loop.latch
36
37loop.next:                                        ; preds = %loop.header
38  br label %loop.latch
39
40loop.latch:                                       ; preds = %loop.next, %loop.header
41  %blend = phi i16 [ undef, %loop.header ], [ %iv.trunc.2, %loop.next ]
42  %dst.ptr = getelementptr inbounds [32 x i16], [32 x i16]* @dst, i16 0, i16 %blend
43  store i16 0, i16* %dst.ptr
44  %iv.next = add nuw nsw i64 %iv, 1
45  %cmp439 = icmp ult i64 %iv, 31
46  br i1 %cmp439, label %loop.header, label %exit
47
48exit:                                             ; preds = %loop.latch
49  ret void
50}
51
52define void @blend_uniform_iv(i1 %c) {
53; CHECK-LABEL: @blend_uniform_iv(
54; CHECK:       vector.ph:
55; CHECK-NEXT:    [[MASK0:%.*]] = insertelement <4 x i1> poison, i1 %c, i32 0
56; CHECK-NEXT:    [[MASK1:%.*]] = shufflevector <4 x i1> [[MASK0]], <4 x i1> poison, <4 x i32> zeroinitializer
57
58; CHECK:       vector.body:
59; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
60; CHECK-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
61; CHECK-NEXT:    [[BROADCAST_SPLATINSERT1:%.*]] = insertelement <4 x i64> poison, i64 [[TMP0]], i32 0
62; CHECK-NEXT:    [[BROADCAST_SPLAT2:%.*]] = shufflevector <4 x i64> [[BROADCAST_SPLATINSERT1]], <4 x i64> poison, <4 x i32> zeroinitializer
63; CHECK-NEXT:    [[TMP1:%.*]] = xor <4 x i1> [[MASK1]], <i1 true, i1 true, i1 true, i1 true>
64; CHECK-NEXT:    [[PREDPHI:%.*]] = select <4 x i1> [[MASK1]], <4 x i64> [[BROADCAST_SPLAT2]], <4 x i64> undef
65; CHECK-NEXT:    [[TMP2:%.*]] = extractelement <4 x i64> [[PREDPHI]], i32 0
66; CHECK-NEXT:    [[TMP3:%.*]] = getelementptr inbounds [32 x i16], [32 x i16]* @dst, i16 0, i64 [[TMP2]]
67; CHECK-NEXT:    [[TMP4:%.*]] = getelementptr inbounds i16, i16* [[TMP3]], i32 0
68; CHECK-NEXT:    [[TMP5:%.*]] = bitcast i16* [[TMP4]] to <4 x i16>*
69; CHECK-NEXT:    store <4 x i16> zeroinitializer, <4 x i16>* [[TMP5]], align 2
70; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
71; CHECK-NEXT:    [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], 32
72; CHECK-NEXT:    br i1 [[TMP6]], label %middle.block, label %vector.body
73;
74entry:
75  br label %loop.header
76
77loop.header:                                      ; preds = %loop.latch, %entry
78  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
79  br i1 %c, label %loop.next, label %loop.latch
80
81loop.next:                                        ; preds = %loop.header
82  br label %loop.latch
83
84loop.latch:                                       ; preds = %loop.next, %loop.header
85  %blend = phi i64 [ undef, %loop.header ], [ %iv, %loop.next ]
86  %dst.ptr = getelementptr inbounds [32 x i16], [32 x i16]* @dst, i16 0, i64 %blend
87  store i16 0, i16* %dst.ptr
88  %iv.next = add nuw nsw i64 %iv, 1
89  %cmp439 = icmp ult i64 %iv, 31
90  br i1 %cmp439, label %loop.header, label %exit
91
92exit:                                             ; preds = %loop.latch
93  ret void
94}
95
96define void @blend_chain_iv(i1 %c) {
97; CHECK-LABEL: @blend_chain_iv(
98; CHECK:       vector.ph:
99; CHECK-NEXT:    [[MASK0:%.*]] = insertelement <4 x i1> poison, i1 %c, i32 0
100; CHECK-NEXT:    [[MASK1:%.*]] = shufflevector <4 x i1> [[MASK0]], <4 x i1> poison, <4 x i32> zeroinitializer
101
102; CHECK:       vector.body:
103; CHECK-NEXT:    [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ]
104; CHECK-NEXT:    [[VEC_IND:%.*]] = phi <4 x i64> [ <i64 0, i64 1, i64 2, i64 3>, %vector.ph ], [ [[VEC_IND_NEXT:%.*]], %vector.body ]
105; CHECK-NEXT:    [[TMP0:%.*]] = add i64 [[INDEX]], 0
106; CHECK-NEXT:    [[TMP1:%.*]] = add i64 [[INDEX]], 1
107; CHECK-NEXT:    [[TMP2:%.*]] = add i64 [[INDEX]], 2
108; CHECK-NEXT:    [[TMP3:%.*]] = add i64 [[INDEX]], 3
109; CHECK-NEXT:    [[TMP4:%.*]] = xor <4 x i1> [[MASK1]], <i1 true, i1 true, i1 true, i1 true>
110; CHECK-NEXT:    [[TMP5:%.*]] = select <4 x i1> [[MASK1]], <4 x i1> [[TMP4]], <4 x i1> zeroinitializer
111; CHECK-NEXT:    [[TMP6:%.*]] = select <4 x i1> [[MASK1]], <4 x i1> [[MASK1]], <4 x i1> zeroinitializer
112; CHECK-NEXT:    [[PREDPHI:%.*]] = select <4 x i1> [[TMP6]], <4 x i64> [[VEC_IND]], <4 x i64> undef
113; CHECK-NEXT:    [[TMP7:%.*]] = xor <4 x i1> [[MASK1]], <i1 true, i1 true, i1 true, i1 true>
114; CHECK-NEXT:    [[TMP8:%.*]] = or <4 x i1> [[TMP6]], [[TMP5]]
115; CHECK-NEXT:    [[PREDPHI1:%.*]] = select <4 x i1> [[TMP8]], <4 x i64> [[PREDPHI]], <4 x i64> undef
116; CHECK-NEXT:    [[TMP9:%.*]] = extractelement <4 x i64> [[PREDPHI1]], i32 0
117; CHECK-NEXT:    [[TMP10:%.*]] = getelementptr inbounds [32 x i16], [32 x i16]* @dst, i16 0, i64 [[TMP9]]
118; CHECK-NEXT:    [[TMP11:%.*]] = extractelement <4 x i64> [[PREDPHI1]], i32 1
119; CHECK-NEXT:    [[TMP12:%.*]] = getelementptr inbounds [32 x i16], [32 x i16]* @dst, i16 0, i64 [[TMP11]]
120; CHECK-NEXT:    [[TMP13:%.*]] = extractelement <4 x i64> [[PREDPHI1]], i32 2
121; CHECK-NEXT:    [[TMP14:%.*]] = getelementptr inbounds [32 x i16], [32 x i16]* @dst, i16 0, i64 [[TMP13]]
122; CHECK-NEXT:    [[TMP15:%.*]] = extractelement <4 x i64> [[PREDPHI1]], i32 3
123; CHECK-NEXT:    [[TMP16:%.*]] = getelementptr inbounds [32 x i16], [32 x i16]* @dst, i16 0, i64 [[TMP15]]
124; CHECK-NEXT:    store i16 0, i16* [[TMP10]], align 2
125; CHECK-NEXT:    store i16 0, i16* [[TMP12]], align 2
126; CHECK-NEXT:    store i16 0, i16* [[TMP14]], align 2
127; CHECK-NEXT:    store i16 0, i16* [[TMP16]], align 2
128; CHECK-NEXT:    [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
129; CHECK-NEXT:    [[VEC_IND_NEXT]] = add <4 x i64> [[VEC_IND]], <i64 4, i64 4, i64 4, i64 4>
130; CHECK-NEXT:    [[TMP17:%.*]] = icmp eq i64 [[INDEX_NEXT]], 32
131; CHECK-NEXT:    br i1 [[TMP17]], label %middle.block, label %vector.body
132;
133entry:
134  br label %loop.header
135
136loop.header:                                      ; preds = %loop.latch, %entry
137  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
138  br i1 %c, label %loop.next, label %loop.latch
139
140loop.next:                                        ; preds = %loop.header
141  br i1 %c, label %loop.next.2, label %loop.next.3
142
143loop.next.2:
144  br label %loop.next.3
145
146loop.next.3:
147  %blend.1 = phi i64 [ undef, %loop.next ], [ %iv, %loop.next.2 ]
148  br label %loop.latch
149
150loop.latch:                                       ; preds = %loop.next, %loop.header
151  %blend = phi i64 [ undef, %loop.header ], [ %blend.1, %loop.next.3 ]
152  %dst.ptr = getelementptr inbounds [32 x i16], [32 x i16]* @dst, i16 0, i64 %blend
153  store i16 0, i16* %dst.ptr
154  %iv.next = add nuw nsw i64 %iv, 1
155  %cmp439 = icmp ult i64 %iv, 31
156  br i1 %cmp439, label %loop.header, label %exit
157
158exit:                                             ; preds = %loop.latch
159  ret void
160}
161