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