1; RUN: opt < %s -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -dce -instcombine -S | FileCheck %s 2; RUN: opt < %s -loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -dce -instcombine -S | FileCheck %s --check-prefix=UNROLL 3; RUN: opt < %s -loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -S | FileCheck %s --check-prefix=UNROLL-NO-IC 4; RUN: opt < %s -loop-vectorize -force-vector-width=1 -force-vector-interleave=2 -S | FileCheck %s --check-prefix=UNROLL-NO-VF 5; RUN: opt < %s -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S | FileCheck %s --check-prefix=SINK-AFTER 6; RUN: opt < %s -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S | FileCheck %s --check-prefix=NO-SINK-AFTER 7 8target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128" 9 10; void recurrence_1(int *a, int *b, int n) { 11; for(int i = 0; i < n; i++) 12; b[i] = a[i] + a[i - 1] 13; } 14; 15; CHECK-LABEL: @recurrence_1( 16; CHECK: vector.ph: 17; CHECK: %vector.recur.init = insertelement <4 x i32> poison, i32 %pre_load, i32 3 18; CHECK: vector.body: 19; CHECK: %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ [[L1:%[a-zA-Z0-9.]+]], %vector.body ] 20; CHECK: [[L1]] = load <4 x i32> 21; CHECK: {{.*}} = shufflevector <4 x i32> %vector.recur, <4 x i32> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 22; CHECK: middle.block: 23; CHECK: %vector.recur.extract = extractelement <4 x i32> [[L1]], i32 3 24; CHECK: scalar.ph: 25; CHECK: %scalar.recur.init = phi i32 [ %pre_load, %vector.memcheck ], [ %pre_load, %for.preheader ], [ %vector.recur.extract, %middle.block ] 26; CHECK: scalar.body: 27; CHECK: %scalar.recur = phi i32 [ %scalar.recur.init, %scalar.ph ], [ {{.*}}, %scalar.body ] 28; 29; UNROLL-LABEL: @recurrence_1( 30; UNROLL: vector.body: 31; UNROLL: %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ [[L2:%[a-zA-Z0-9.]+]], %vector.body ] 32; UNROLL: [[L1:%[a-zA-Z0-9.]+]] = load <4 x i32> 33; UNROLL: [[L2]] = load <4 x i32> 34; UNROLL: {{.*}} = shufflevector <4 x i32> %vector.recur, <4 x i32> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 35; UNROLL: {{.*}} = shufflevector <4 x i32> [[L1]], <4 x i32> [[L2]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 36; UNROLL: middle.block: 37; UNROLL: %vector.recur.extract = extractelement <4 x i32> [[L2]], i32 3 38; 39define void @recurrence_1(i32* nocapture readonly %a, i32* nocapture %b, i32 %n) { 40entry: 41 br label %for.preheader 42 43for.preheader: 44 %arrayidx.phi.trans.insert = getelementptr inbounds i32, i32* %a, i64 0 45 %pre_load = load i32, i32* %arrayidx.phi.trans.insert 46 br label %scalar.body 47 48scalar.body: 49 %0 = phi i32 [ %pre_load, %for.preheader ], [ %1, %scalar.body ] 50 %indvars.iv = phi i64 [ 0, %for.preheader ], [ %indvars.iv.next, %scalar.body ] 51 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 52 %arrayidx32 = getelementptr inbounds i32, i32* %a, i64 %indvars.iv.next 53 %1 = load i32, i32* %arrayidx32 54 %arrayidx34 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv 55 %add35 = add i32 %1, %0 56 store i32 %add35, i32* %arrayidx34 57 %lftr.wideiv = trunc i64 %indvars.iv.next to i32 58 %exitcond = icmp eq i32 %lftr.wideiv, %n 59 br i1 %exitcond, label %for.exit, label %scalar.body 60 61for.exit: 62 ret void 63} 64 65; int recurrence_2(int *a, int n) { 66; int minmax; 67; for (int i = 0; i < n; ++i) 68; minmax = min(minmax, max(a[i] - a[i-1], 0)); 69; return minmax; 70; } 71; 72; CHECK-LABEL: @recurrence_2( 73; CHECK: vector.ph: 74; CHECK: %vector.recur.init = insertelement <4 x i32> poison, i32 %.pre, i32 3 75; CHECK: vector.body: 76; CHECK: %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ [[L1:%[a-zA-Z0-9.]+]], %vector.body ] 77; CHECK: [[L1]] = load <4 x i32> 78; CHECK: {{.*}} = shufflevector <4 x i32> %vector.recur, <4 x i32> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 79; CHECK: middle.block: 80; CHECK: %vector.recur.extract = extractelement <4 x i32> [[L1]], i32 3 81; CHECK: scalar.ph: 82; CHECK: %scalar.recur.init = phi i32 [ %.pre, %for.preheader ], [ %vector.recur.extract, %middle.block ] 83; CHECK: scalar.body: 84; CHECK: %scalar.recur = phi i32 [ %scalar.recur.init, %scalar.ph ], [ {{.*}}, %scalar.body ] 85; 86; UNROLL-LABEL: @recurrence_2( 87; UNROLL: vector.body: 88; UNROLL: %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ [[L2:%[a-zA-Z0-9.]+]], %vector.body ] 89; UNROLL: [[L1:%[a-zA-Z0-9.]+]] = load <4 x i32> 90; UNROLL: [[L2]] = load <4 x i32> 91; UNROLL: {{.*}} = shufflevector <4 x i32> %vector.recur, <4 x i32> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 92; UNROLL: {{.*}} = shufflevector <4 x i32> [[L1]], <4 x i32> [[L2]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 93; UNROLL: middle.block: 94; UNROLL: %vector.recur.extract = extractelement <4 x i32> [[L2]], i32 3 95; 96define i32 @recurrence_2(i32* nocapture readonly %a, i32 %n) { 97entry: 98 %cmp27 = icmp sgt i32 %n, 0 99 br i1 %cmp27, label %for.preheader, label %for.cond.cleanup 100 101for.preheader: 102 %arrayidx2.phi.trans.insert = getelementptr inbounds i32, i32* %a, i64 -1 103 %.pre = load i32, i32* %arrayidx2.phi.trans.insert, align 4 104 br label %scalar.body 105 106for.cond.cleanup.loopexit: 107 %minmax.0.cond.lcssa = phi i32 [ %minmax.0.cond, %scalar.body ] 108 br label %for.cond.cleanup 109 110for.cond.cleanup: 111 %minmax.0.lcssa = phi i32 [ poison, %entry ], [ %minmax.0.cond.lcssa, %for.cond.cleanup.loopexit ] 112 ret i32 %minmax.0.lcssa 113 114scalar.body: 115 %0 = phi i32 [ %.pre, %for.preheader ], [ %1, %scalar.body ] 116 %indvars.iv = phi i64 [ 0, %for.preheader ], [ %indvars.iv.next, %scalar.body ] 117 %minmax.028 = phi i32 [ poison, %for.preheader ], [ %minmax.0.cond, %scalar.body ] 118 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv 119 %1 = load i32, i32* %arrayidx, align 4 120 %sub3 = sub nsw i32 %1, %0 121 %cmp4 = icmp sgt i32 %sub3, 0 122 %cond = select i1 %cmp4, i32 %sub3, i32 0 123 %cmp5 = icmp slt i32 %minmax.028, %cond 124 %minmax.0.cond = select i1 %cmp5, i32 %minmax.028, i32 %cond 125 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 126 %lftr.wideiv = trunc i64 %indvars.iv.next to i32 127 %exitcond = icmp eq i32 %lftr.wideiv, %n 128 br i1 %exitcond, label %for.cond.cleanup.loopexit, label %scalar.body 129} 130 131; void recurrence_3(short *a, double *b, int n, float f, short p) { 132; b[0] = (double)a[0] - f * (double)p; 133; for (int i = 1; i < n; i++) 134; b[i] = (double)a[i] - f * (double)a[i - 1]; 135; } 136; 137; CHECK-LABEL: @recurrence_3( 138; CHECK: vector.ph: 139; CHECK: %vector.recur.init = insertelement <4 x i16> poison, i16 %0, i32 3 140; CHECK: vector.body: 141; CHECK: %vector.recur = phi <4 x i16> [ %vector.recur.init, %vector.ph ], [ [[L1:%[a-zA-Z0-9.]+]], %vector.body ] 142; CHECK: [[L1]] = load <4 x i16> 143; CHECK: [[SHUF:%[a-zA-Z0-9.]+]] = shufflevector <4 x i16> %vector.recur, <4 x i16> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 144; Check also that the casts were not moved needlessly. 145; CHECK: sitofp <4 x i16> [[L1]] to <4 x double> 146; CHECK: sitofp <4 x i16> [[SHUF]] to <4 x double> 147; CHECK: middle.block: 148; CHECK: %vector.recur.extract = extractelement <4 x i16> [[L1]], i32 3 149; CHECK: scalar.ph: 150; CHECK: %scalar.recur.init = phi i16 [ %0, %vector.memcheck ], [ %0, %for.preheader ], [ %vector.recur.extract, %middle.block ] 151; CHECK: scalar.body: 152; CHECK: %scalar.recur = phi i16 [ %scalar.recur.init, %scalar.ph ], [ {{.*}}, %scalar.body ] 153; 154; UNROLL-LABEL: @recurrence_3( 155; UNROLL: vector.body: 156; UNROLL: %vector.recur = phi <4 x i16> [ %vector.recur.init, %vector.ph ], [ [[L2:%[a-zA-Z0-9.]+]], %vector.body ] 157; UNROLL: [[L1:%[a-zA-Z0-9.]+]] = load <4 x i16> 158; UNROLL: [[L2]] = load <4 x i16> 159; UNROLL: {{.*}} = shufflevector <4 x i16> %vector.recur, <4 x i16> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 160; UNROLL: {{.*}} = shufflevector <4 x i16> [[L1]], <4 x i16> [[L2]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 161; UNROLL: middle.block: 162; UNROLL: %vector.recur.extract = extractelement <4 x i16> [[L2]], i32 3 163; 164define void @recurrence_3(i16* nocapture readonly %a, double* nocapture %b, i32 %n, float %f, i16 %p) { 165entry: 166 %0 = load i16, i16* %a, align 2 167 %conv = sitofp i16 %0 to double 168 %conv1 = fpext float %f to double 169 %conv2 = sitofp i16 %p to double 170 %mul = fmul fast double %conv2, %conv1 171 %sub = fsub fast double %conv, %mul 172 store double %sub, double* %b, align 8 173 %cmp25 = icmp sgt i32 %n, 1 174 br i1 %cmp25, label %for.preheader, label %for.end 175 176for.preheader: 177 br label %scalar.body 178 179scalar.body: 180 %1 = phi i16 [ %0, %for.preheader ], [ %2, %scalar.body ] 181 %advars.iv = phi i64 [ %advars.iv.next, %scalar.body ], [ 1, %for.preheader ] 182 %arrayidx5 = getelementptr inbounds i16, i16* %a, i64 %advars.iv 183 %2 = load i16, i16* %arrayidx5, align 2 184 %conv6 = sitofp i16 %2 to double 185 %conv11 = sitofp i16 %1 to double 186 %mul12 = fmul fast double %conv11, %conv1 187 %sub13 = fsub fast double %conv6, %mul12 188 %arrayidx15 = getelementptr inbounds double, double* %b, i64 %advars.iv 189 store double %sub13, double* %arrayidx15, align 8 190 %advars.iv.next = add nuw nsw i64 %advars.iv, 1 191 %lftr.wideiv = trunc i64 %advars.iv.next to i32 192 %exitcond = icmp eq i32 %lftr.wideiv, %n 193 br i1 %exitcond, label %for.end.loopexit, label %scalar.body 194 195for.end.loopexit: 196 br label %for.end 197 198for.end: 199 ret void 200} 201 202; void PR26734(short *a, int *b, int *c, int d, short *e) { 203; for (; d != 21; d++) { 204; *b &= *c; 205; *e = *a - 6; 206; *c = *e; 207; } 208; } 209; 210; CHECK-LABEL: @PR26734( 211; CHECK-NOT: vector.ph: 212; CHECK: } 213; 214define void @PR26734(i16* %a, i32* %b, i32* %c, i32 %d, i16* %e) { 215entry: 216 %cmp4 = icmp eq i32 %d, 21 217 br i1 %cmp4, label %entry.for.end_crit_edge, label %for.body.lr.ph 218 219entry.for.end_crit_edge: 220 %.pre = load i32, i32* %b, align 4 221 br label %for.end 222 223for.body.lr.ph: 224 %0 = load i16, i16* %a, align 2 225 %sub = add i16 %0, -6 226 %conv2 = sext i16 %sub to i32 227 %c.promoted = load i32, i32* %c, align 4 228 %b.promoted = load i32, i32* %b, align 4 229 br label %for.body 230 231for.body: 232 %inc7 = phi i32 [ %d, %for.body.lr.ph ], [ %inc, %for.body ] 233 %and6 = phi i32 [ %b.promoted, %for.body.lr.ph ], [ %and, %for.body ] 234 %conv25 = phi i32 [ %c.promoted, %for.body.lr.ph ], [ %conv2, %for.body ] 235 %and = and i32 %and6, %conv25 236 %inc = add nsw i32 %inc7, 1 237 %cmp = icmp eq i32 %inc, 21 238 br i1 %cmp, label %for.cond.for.end_crit_edge, label %for.body 239 240for.cond.for.end_crit_edge: 241 %and.lcssa = phi i32 [ %and, %for.body ] 242 store i32 %conv2, i32* %c, align 4 243 store i32 %and.lcssa, i32* %b, align 4 244 store i16 %sub, i16* %e, align 2 245 br label %for.end 246 247for.end: 248 ret void 249} 250 251; int PR27246() { 252; unsigned int e, n; 253; for (int i = 1; i < 49; ++i) { 254; for (int k = i; k > 1; --k) 255; e = k; 256; n = e; 257; } 258; return n; 259; } 260; 261; CHECK-LABEL: @PR27246( 262; CHECK-NOT: vector.ph: 263; CHECK: } 264; 265define i32 @PR27246() { 266entry: 267 br label %for.cond1.preheader 268 269for.cond1.preheader: 270 %i.016 = phi i32 [ 1, %entry ], [ %inc, %for.cond.cleanup3 ] 271 %e.015 = phi i32 [ poison, %entry ], [ %e.1.lcssa, %for.cond.cleanup3 ] 272 br label %for.cond1 273 274for.cond.cleanup: 275 %e.1.lcssa.lcssa = phi i32 [ %e.1.lcssa, %for.cond.cleanup3 ] 276 ret i32 %e.1.lcssa.lcssa 277 278for.cond1: 279 %e.1 = phi i32 [ %k.0, %for.cond1 ], [ %e.015, %for.cond1.preheader ] 280 %k.0 = phi i32 [ %dec, %for.cond1 ], [ %i.016, %for.cond1.preheader ] 281 %cmp2 = icmp sgt i32 %k.0, 1 282 %dec = add nsw i32 %k.0, -1 283 br i1 %cmp2, label %for.cond1, label %for.cond.cleanup3 284 285for.cond.cleanup3: 286 %e.1.lcssa = phi i32 [ %e.1, %for.cond1 ] 287 %inc = add nuw nsw i32 %i.016, 1 288 %exitcond = icmp eq i32 %inc, 49 289 br i1 %exitcond, label %for.cond.cleanup, label %for.cond1.preheader 290} 291 292; UNROLL-NO-IC-LABEL: @PR30183( 293; UNROLL-NO-IC: vector.ph: 294; UNROLL-NO-IC: [[VECTOR_RECUR_INIT:%.*]] = insertelement <4 x i32> poison, i32 [[PRE_LOAD:%.*]], i32 3 295; UNROLL-NO-IC-NEXT: br label %vector.body 296; UNROLL-NO-IC: vector.body: 297; UNROLL-NO-IC-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %vector.ph ], [ [[INDEX_NEXT:%.*]], %vector.body ] 298; UNROLL-NO-IC-NEXT: [[VECTOR_RECUR:%.*]] = phi <4 x i32> [ [[VECTOR_RECUR_INIT]], %vector.ph ], [ [[TMP42:%.*]], %vector.body ] 299; UNROLL-NO-IC: [[TMP27:%.*]] = load i32, i32* {{.*}} 300; UNROLL-NO-IC-NEXT: [[TMP28:%.*]] = load i32, i32* {{.*}} 301; UNROLL-NO-IC-NEXT: [[TMP29:%.*]] = load i32, i32* {{.*}} 302; UNROLL-NO-IC-NEXT: [[TMP30:%.*]] = load i32, i32* {{.*}} 303; UNROLL-NO-IC-NEXT: [[TMP35:%.*]] = insertelement <4 x i32> poison, i32 [[TMP27]], i32 0 304; UNROLL-NO-IC-NEXT: [[TMP36:%.*]] = insertelement <4 x i32> [[TMP35]], i32 [[TMP28]], i32 1 305; UNROLL-NO-IC-NEXT: [[TMP37:%.*]] = insertelement <4 x i32> [[TMP36]], i32 [[TMP29]], i32 2 306; UNROLL-NO-IC-NEXT: [[TMP38:%.*]] = insertelement <4 x i32> [[TMP37]], i32 [[TMP30]], i32 3 307; UNROLL-NO-IC-NEXT: [[TMP31:%.*]] = load i32, i32* {{.*}} 308; UNROLL-NO-IC-NEXT: [[TMP32:%.*]] = load i32, i32* {{.*}} 309; UNROLL-NO-IC-NEXT: [[TMP33:%.*]] = load i32, i32* {{.*}} 310; UNROLL-NO-IC-NEXT: [[TMP34:%.*]] = load i32, i32* {{.*}} 311; UNROLL-NO-IC-NEXT: [[TMP39:%.*]] = insertelement <4 x i32> poison, i32 [[TMP31]], i32 0 312; UNROLL-NO-IC-NEXT: [[TMP40:%.*]] = insertelement <4 x i32> [[TMP39]], i32 [[TMP32]], i32 1 313; UNROLL-NO-IC-NEXT: [[TMP41:%.*]] = insertelement <4 x i32> [[TMP40]], i32 [[TMP33]], i32 2 314; UNROLL-NO-IC-NEXT: [[TMP42]] = insertelement <4 x i32> [[TMP41]], i32 [[TMP34]], i32 3 315; UNROLL-NO-IC-NEXT: [[TMP43:%.*]] = shufflevector <4 x i32> [[VECTOR_RECUR]], <4 x i32> [[TMP38]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 316; UNROLL-NO-IC-NEXT: [[TMP44:%.*]] = shufflevector <4 x i32> [[TMP38]], <4 x i32> [[TMP42]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 317; UNROLL-NO-IC-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 8 318; UNROLL-NO-IC: br i1 {{.*}}, label %middle.block, label %vector.body 319; 320define void @PR30183(i32 %pre_load, i32* %a, i32* %b, i64 %n) { 321entry: 322 br label %scalar.body 323 324scalar.body: 325 %i = phi i64 [ 0, %entry ], [ %i.next, %scalar.body ] 326 %tmp0 = phi i32 [ %pre_load, %entry ], [ %tmp2, %scalar.body ] 327 %i.next = add nuw nsw i64 %i, 2 328 %tmp1 = getelementptr inbounds i32, i32* %a, i64 %i.next 329 %tmp2 = load i32, i32* %tmp1 330 %cond = icmp eq i64 %i.next,%n 331 br i1 %cond, label %for.end, label %scalar.body 332 333for.end: 334 ret void 335} 336 337; UNROLL-NO-IC-LABEL: @constant_folded_previous_value( 338; UNROLL-NO-IC: vector.body: 339; UNROLL-NO-IC: [[VECTOR_RECUR:%.*]] = phi <4 x i64> [ <i64 poison, i64 poison, i64 poison, i64 0>, %vector.ph ], [ <i64 1, i64 1, i64 1, i64 1>, %vector.body ] 340; UNROLL-NO-IC-NEXT: [[TMP0:%.*]] = shufflevector <4 x i64> [[VECTOR_RECUR]], <4 x i64> <i64 1, i64 1, i64 1, i64 1>, <4 x i32> <i32 3, i32 4, i32 5, i32 6> 341; UNROLL-NO-IC: br i1 {{.*}}, label %middle.block, label %vector.body 342; 343define void @constant_folded_previous_value() { 344entry: 345 br label %scalar.body 346 347scalar.body: 348 %i = phi i64 [ 0, %entry ], [ %i.next, %scalar.body ] 349 %tmp2 = phi i64 [ 0, %entry ], [ %tmp3, %scalar.body ] 350 %tmp3 = add i64 0, 1 351 %i.next = add nuw nsw i64 %i, 1 352 %cond = icmp eq i64 %i.next, undef 353 br i1 %cond, label %for.end, label %scalar.body 354 355for.end: 356 ret void 357} 358 359; We vectorize this first order recurrence, by generating two 360; extracts for the phi `val.phi` - one at the last index and 361; another at the second last index. We need these 2 extracts because 362; the first order recurrence phi is used outside the loop, so we require the phi 363; itself and not its update (addx). 364; UNROLL-NO-IC-LABEL: extract_second_last_iteration 365; UNROLL-NO-IC: vector.body 366; UNROLL-NO-IC: %step.add = add <4 x i32> %vec.ind, <i32 4, i32 4, i32 4, i32 4> 367; UNROLL-NO-IC: %[[L1:.+]] = add <4 x i32> %vec.ind, %broadcast.splat 368; UNROLL-NO-IC: %[[L2:.+]] = add <4 x i32> %step.add, %broadcast.splat 369; UNROLL-NO-IC: %index.next = add i32 %index, 8 370; UNROLL-NO-IC: icmp eq i32 %index.next, 96 371; UNROLL-NO-IC: middle.block 372; UNROLL-NO-IC: icmp eq i32 96, 96 373; UNROLL-NO-IC: %vector.recur.extract = extractelement <4 x i32> %[[L2]], i32 3 374; UNROLL-NO-IC: %vector.recur.extract.for.phi = extractelement <4 x i32> %[[L2]], i32 2 375; UNROLL-NO-IC: for.end 376; UNROLL-NO-IC: %val.phi.lcssa = phi i32 [ %scalar.recur, %for.body ], [ %vector.recur.extract.for.phi, %middle.block ] 377; Check the case when unrolled but not vectorized. 378; UNROLL-NO-VF-LABEL: extract_second_last_iteration 379; UNROLL-NO-VF: vector.body: 380; UNROLL-NO-VF: %induction = add i32 %index, 0 381; UNROLL-NO-VF: %induction1 = add i32 %index, 1 382; UNROLL-NO-VF: %[[L1:.+]] = add i32 %induction, %x 383; UNROLL-NO-VF: %[[L2:.+]] = add i32 %induction1, %x 384; UNROLL-NO-VF: %index.next = add i32 %index, 2 385; UNROLL-NO-VF: icmp eq i32 %index.next, 96 386; UNROLL-NO-VF: for.end: 387; UNROLL-NO-VF: %val.phi.lcssa = phi i32 [ %scalar.recur, %for.body ], [ %[[L1]], %middle.block ] 388define i32 @extract_second_last_iteration(i32* %cval, i32 %x) { 389entry: 390 br label %for.body 391 392for.body: 393 %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ] 394 %val.phi = phi i32 [ 0, %entry ], [ %addx, %for.body ] 395 %inc = add i32 %inc.phi, 1 396 %bc = zext i32 %inc.phi to i64 397 %addx = add i32 %inc.phi, %x 398 %cmp = icmp eq i32 %inc.phi, 95 399 br i1 %cmp, label %for.end, label %for.body 400 401for.end: 402 ret i32 %val.phi 403} 404 405; We vectorize this first order recurrence, with a set of insertelements for 406; each unrolled part. Make sure these insertelements are generated in-order, 407; because the shuffle of the first order recurrence will be added after the 408; insertelement of the last part UF - 1, assuming the latter appears after the 409; insertelements of all other parts. 410; 411; int PR33613(double *b, double j, int d) { 412; int a = 0; 413; for(int i = 0; i < 10240; i++, b+=25) { 414; double f = b[d]; // Scalarize to form insertelements 415; if (j * f) 416; a++; 417; j = f; 418; } 419; return a; 420; } 421; 422; UNROLL-NO-IC-LABEL: @PR33613( 423; UNROLL-NO-IC: vector.body: 424; UNROLL-NO-IC: [[VECTOR_RECUR:%.*]] = phi <4 x double> 425; UNROLL-NO-IC: shufflevector <4 x double> [[VECTOR_RECUR]], <4 x double> {{.*}}, <4 x i32> <i32 3, i32 4, i32 5, i32 6> 426; UNROLL-NO-IC-NEXT: shufflevector <4 x double> {{.*}}, <4 x double> {{.*}}, <4 x i32> <i32 3, i32 4, i32 5, i32 6> 427; UNROLL-NO-IC-NOT: insertelement <4 x double> 428; UNROLL-NO-IC: middle.block: 429; 430define i32 @PR33613(double* %b, double %j, i32 %d) { 431entry: 432 %idxprom = sext i32 %d to i64 433 br label %for.body 434 435for.cond.cleanup: 436 %a.1.lcssa = phi i32 [ %a.1, %for.body ] 437 ret i32 %a.1.lcssa 438 439for.body: 440 %b.addr.012 = phi double* [ %b, %entry ], [ %add.ptr, %for.body ] 441 %i.011 = phi i32 [ 0, %entry ], [ %inc1, %for.body ] 442 %a.010 = phi i32 [ 0, %entry ], [ %a.1, %for.body ] 443 %j.addr.09 = phi double [ %j, %entry ], [ %0, %for.body ] 444 %arrayidx = getelementptr inbounds double, double* %b.addr.012, i64 %idxprom 445 %0 = load double, double* %arrayidx, align 8 446 %mul = fmul double %j.addr.09, %0 447 %tobool = fcmp une double %mul, 0.000000e+00 448 %inc = zext i1 %tobool to i32 449 %a.1 = add nsw i32 %a.010, %inc 450 %inc1 = add nuw nsw i32 %i.011, 1 451 %add.ptr = getelementptr inbounds double, double* %b.addr.012, i64 25 452 %exitcond = icmp eq i32 %inc1, 10240 453 br i1 %exitcond, label %for.cond.cleanup, label %for.body 454} 455 456; void sink_after(short *a, int n, int *b) { 457; for(int i = 0; i < n; i++) 458; b[i] = (a[i] * a[i + 1]); 459; } 460; 461; SINK-AFTER-LABEL: sink_after 462; Check that the sext sank after the load in the vector loop. 463; SINK-AFTER: vector.body 464; SINK-AFTER: %vector.recur = phi <4 x i16> [ %vector.recur.init, %vector.ph ], [ %wide.load, %vector.body ] 465; SINK-AFTER: %wide.load = load <4 x i16> 466; SINK-AFTER: %[[VSHUF:.+]] = shufflevector <4 x i16> %vector.recur, <4 x i16> %wide.load, <4 x i32> <i32 3, i32 4, i32 5, i32 6> 467; SINK-AFTER: %[[VCONV:.+]] = sext <4 x i16> %[[VSHUF]] to <4 x i32> 468; SINK-AFTER: %[[VCONV3:.+]] = sext <4 x i16> %wide.load to <4 x i32> 469; SINK-AFTER: mul nsw <4 x i32> %[[VCONV3]], %[[VCONV]] 470; 471define void @sink_after(i16* %a, i32* %b, i64 %n) { 472entry: 473 %.pre = load i16, i16* %a 474 br label %for.body 475 476for.body: 477 %0 = phi i16 [ %.pre, %entry ], [ %1, %for.body ] 478 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] 479 %conv = sext i16 %0 to i32 480 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 481 %arrayidx2 = getelementptr inbounds i16, i16* %a, i64 %indvars.iv.next 482 %1 = load i16, i16* %arrayidx2 483 %conv3 = sext i16 %1 to i32 484 %mul = mul nsw i32 %conv3, %conv 485 %arrayidx5 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv 486 store i32 %mul, i32* %arrayidx5 487 %exitcond = icmp eq i64 %indvars.iv.next, %n 488 br i1 %exitcond, label %for.end, label %for.body 489 490for.end: 491 ret void 492} 493 494; PR34711: given three consecutive instructions such that the first will be 495; widened, the second is a cast that will be widened and needs to sink after the 496; third, and the third is a first-order-recurring load that will be replicated 497; instead of widened. Although the cast and the first instruction will both be 498; widened, and are originally adjacent to each other, make sure the replicated 499; load ends up appearing between them. 500; 501; void PR34711(short[2] *a, int *b, int *c, int n) { 502; for(int i = 0; i < n; i++) { 503; c[i] = 7; 504; b[i] = (a[i][0] * a[i][1]); 505; } 506; } 507; 508; SINK-AFTER-LABEL: @PR34711 509; Check that the sext sank after the load in the vector loop. 510; SINK-AFTER: vector.body 511; SINK-AFTER: %vector.recur = phi <4 x i16> [ %vector.recur.init, %vector.ph ], [ {{.*}}, %vector.body ] 512; SINK-AFTER: %[[VSHUF:.+]] = shufflevector <4 x i16> %vector.recur, <4 x i16> %{{.*}}, <4 x i32> <i32 3, i32 4, i32 5, i32 6> 513; SINK-AFTER: %[[VCONV:.+]] = sext <4 x i16> %[[VSHUF]] to <4 x i32> 514; SINK-AFTER: %[[VCONV3:.+]] = sext <4 x i16> {{.*}} to <4 x i32> 515; SINK-AFTER: mul nsw <4 x i32> %[[VCONV3]], %[[VCONV]] 516; 517define void @PR34711([2 x i16]* %a, i32* %b, i32* %c, i64 %n) { 518entry: 519 %pre.index = getelementptr inbounds [2 x i16], [2 x i16]* %a, i64 0, i64 0 520 %.pre = load i16, i16* %pre.index 521 br label %for.body 522 523for.body: 524 %0 = phi i16 [ %.pre, %entry ], [ %1, %for.body ] 525 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] 526 %arraycidx = getelementptr inbounds i32, i32* %c, i64 %indvars.iv 527 %cur.index = getelementptr inbounds [2 x i16], [2 x i16]* %a, i64 %indvars.iv, i64 1 528 store i32 7, i32* %arraycidx ; 1st instruction, to be widened. 529 %conv = sext i16 %0 to i32 ; 2nd, cast to sink after third. 530 %1 = load i16, i16* %cur.index ; 3rd, first-order-recurring load not widened. 531 %conv3 = sext i16 %1 to i32 532 %mul = mul nsw i32 %conv3, %conv 533 %arrayidx5 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv 534 store i32 %mul, i32* %arrayidx5 535 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 536 %exitcond = icmp eq i64 %indvars.iv.next, %n 537 br i1 %exitcond, label %for.end, label %for.body 538 539for.end: 540 ret void 541} 542 543; void no_sink_after(short *a, int n, int *b) { 544; for(int i = 0; i < n; i++) 545; b[i] = ((a[i] + 2) * a[i + 1]); 546; } 547; 548; NO-SINK-AFTER-LABEL: no_sink_after 549; NO-SINK-AFTER-NOT: vector.ph: 550; NO-SINK-AFTER: } 551; 552define void @no_sink_after(i16* %a, i32* %b, i64 %n) { 553entry: 554 %.pre = load i16, i16* %a 555 br label %for.body 556 557for.body: 558 %0 = phi i16 [ %.pre, %entry ], [ %1, %for.body ] 559 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] 560 %conv = sext i16 %0 to i32 561 %add = add nsw i32 %conv, 2 562 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 563 %arrayidx2 = getelementptr inbounds i16, i16* %a, i64 %indvars.iv.next 564 %1 = load i16, i16* %arrayidx2 565 %conv3 = sext i16 %1 to i32 566 %mul = mul nsw i32 %add, %conv3 567 %arrayidx5 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv 568 store i32 %mul, i32* %arrayidx5 569 %exitcond = icmp eq i64 %indvars.iv.next, %n 570 br i1 %exitcond, label %for.end, label %for.body 571 572for.end: 573 ret void 574} 575 576; Do not sink branches: While branches are if-converted and do not require 577; sinking, instructions with side effects (e.g. loads) conditioned by those 578; branches will become users of the condition bit after vectorization and would 579; need to be sunk if the loop is vectorized. 580define void @do_not_sink_branch(i32 %x, i32* %in, i32* %out, i32 %tc) local_unnamed_addr #0 { 581; NO-SINK-AFTER-LABEL: do_not_sink_branch 582; NO-SINK-AFTER-NOT: vector.ph: 583; NO-SINK-AFTER: } 584entry: 585 %cmp530 = icmp slt i32 0, %tc 586 br label %for.body4 587 588for.body4: ; preds = %cond.end, %entry 589 %indvars.iv = phi i32 [ 0, %entry ], [ %indvars.iv.next, %cond.end ] 590 %cmp534 = phi i1 [ %cmp530, %entry ], [ %cmp5, %cond.end ] 591 br i1 %cmp534, label %cond.true, label %cond.end 592 593cond.true: ; preds = %for.body4 594 %arrayidx7 = getelementptr inbounds i32, i32* %in, i32 %indvars.iv 595 %in.val = load i32, i32* %arrayidx7, align 4 596 br label %cond.end 597 598cond.end: ; preds = %for.body4, %cond.true 599 %cond = phi i32 [ %in.val, %cond.true ], [ 0, %for.body4 ] 600 %arrayidx8 = getelementptr inbounds i32, i32* %out, i32 %indvars.iv 601 store i32 %cond, i32* %arrayidx8, align 4 602 %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1 603 %cmp5 = icmp slt i32 %indvars.iv.next, %tc 604 %exitcond = icmp eq i32 %indvars.iv.next, %x 605 br i1 %exitcond, label %for.end12.loopexit, label %for.body4 606 607for.end12.loopexit: ; preds = %cond.end 608 ret void 609} 610 611; Dead instructions, like the exit condition are not part of the actual VPlan 612; and do not need to be sunk. PR44634. 613define void @sink_dead_inst() { 614; SINK-AFTER-LABEL: define void @sink_dead_inst( 615; SINK-AFTER-LABEL: vector.body: ; preds = %vector.body, %vector.ph 616; SINK-AFTER-NEXT: %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ] 617; SINK-AFTER-NEXT: %vec.ind = phi <4 x i16> [ <i16 -27, i16 -26, i16 -25, i16 -24>, %vector.ph ], [ %vec.ind.next, %vector.body ] 618; SINK-AFTER-NEXT: %vector.recur = phi <4 x i16> [ <i16 poison, i16 poison, i16 poison, i16 0>, %vector.ph ], [ %3, %vector.body ] 619; SINK-AFTER-NEXT: %vector.recur2 = phi <4 x i32> [ <i32 poison, i32 poison, i32 poison, i32 -27>, %vector.ph ], [ %1, %vector.body ] 620; SINK-AFTER-NEXT: %0 = add <4 x i16> %vec.ind, <i16 1, i16 1, i16 1, i16 1> 621; SINK-AFTER-NEXT: %1 = zext <4 x i16> %0 to <4 x i32> 622; SINK-AFTER-NEXT: %2 = shufflevector <4 x i32> %vector.recur2, <4 x i32> %1, <4 x i32> <i32 3, i32 4, i32 5, i32 6> 623; SINK-AFTER-NEXT: %3 = add <4 x i16> %0, <i16 5, i16 5, i16 5, i16 5> 624; SINK-AFTER-NEXT: %4 = shufflevector <4 x i16> %vector.recur, <4 x i16> %3, <4 x i32> <i32 3, i32 4, i32 5, i32 6> 625; SINK-AFTER-NEXT: %5 = sub <4 x i16> %4, <i16 10, i16 10, i16 10, i16 10> 626; SINK-AFTER-NEXT: %index.next = add i32 %index, 4 627; SINK-AFTER-NEXT: %vec.ind.next = add <4 x i16> %vec.ind, <i16 4, i16 4, i16 4, i16 4> 628; SINK-AFTER-NEXT: %6 = icmp eq i32 %index.next, 40 629; SINK-AFTER-NEXT: br i1 %6, label %middle.block, label %vector.body, !llvm.loop !43 630; 631entry: 632 br label %for.cond 633 634for.cond: 635 %iv = phi i16 [ -27, %entry ], [ %iv.next, %for.cond ] 636 %rec.1 = phi i16 [ 0, %entry ], [ %rec.1.prev, %for.cond ] 637 %rec.2 = phi i32 [ -27, %entry ], [ %rec.2.prev, %for.cond ] 638 %use.rec.1 = sub i16 %rec.1, 10 639 %cmp = icmp eq i32 %rec.2, 15 640 %iv.next = add i16 %iv, 1 641 %rec.2.prev = zext i16 %iv.next to i32 642 %rec.1.prev = add i16 %iv.next, 5 643 br i1 %cmp, label %for.end, label %for.cond 644 645for.end: 646 ret void 647} 648 649define i32 @sink_into_replication_region(i32 %y) { 650; CHECK-LABEL: @sink_into_replication_region( 651; CHECK-NEXT: bb: 652; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[Y:%.*]], 1 653; CHECK-NEXT: [[SMIN:%.*]] = call i32 @llvm.smin.i32(i32 [[Y]], i32 1) 654; CHECK-NEXT: [[TMP1:%.*]] = sub i32 [[TMP0]], [[SMIN]] 655; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]] 656; CHECK: vector.ph: 657; CHECK-NEXT: [[N_RND_UP:%.*]] = add i32 [[TMP1]], 3 658; CHECK-NEXT: [[N_VEC:%.*]] = and i32 [[N_RND_UP]], -4 659; CHECK-NEXT: [[TRIP_COUNT_MINUS_1:%.*]] = add i32 [[TMP1]], -1 660; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[TRIP_COUNT_MINUS_1]], i32 0 661; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer 662; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] 663; CHECK: vector.body: 664; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_UDIV_CONTINUE9:%.*]] ] 665; CHECK-NEXT: [[VECTOR_RECUR:%.*]] = phi <4 x i32> [ <i32 poison, i32 poison, i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[TMP21:%.*]], [[PRED_UDIV_CONTINUE9]] ] 666; CHECK-NEXT: [[VEC_PHI1:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP23:%.*]], [[PRED_UDIV_CONTINUE9]] ] 667; CHECK-NEXT: [[OFFSET_IDX:%.*]] = sub i32 [[Y]], [[INDEX]] 668; CHECK-NEXT: [[BROADCAST_SPLATINSERT2:%.*]] = insertelement <4 x i32> poison, i32 [[INDEX]], i32 0 669; CHECK-NEXT: [[BROADCAST_SPLAT3:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT2]], <4 x i32> poison, <4 x i32> zeroinitializer 670; CHECK-NEXT: [[VEC_IV:%.*]] = or <4 x i32> [[BROADCAST_SPLAT3]], <i32 0, i32 1, i32 2, i32 3> 671; CHECK-NEXT: [[TMP2:%.*]] = icmp ule <4 x i32> [[VEC_IV]], [[BROADCAST_SPLAT]] 672; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x i1> [[TMP2]], i32 0 673; CHECK-NEXT: br i1 [[TMP3]], label [[PRED_UDIV_IF:%.*]], label [[PRED_UDIV_CONTINUE:%.*]] 674; CHECK: pred.udiv.if: 675; CHECK-NEXT: [[TMP4:%.*]] = udiv i32 219220132, [[OFFSET_IDX]] 676; CHECK-NEXT: [[TMP5:%.*]] = insertelement <4 x i32> poison, i32 [[TMP4]], i32 0 677; CHECK-NEXT: br label [[PRED_UDIV_CONTINUE]] 678; CHECK: pred.udiv.continue: 679; CHECK-NEXT: [[TMP6:%.*]] = phi <4 x i32> [ poison, [[VECTOR_BODY]] ], [ [[TMP5]], [[PRED_UDIV_IF]] ] 680; CHECK-NEXT: [[TMP7:%.*]] = extractelement <4 x i1> [[TMP2]], i32 1 681; CHECK-NEXT: br i1 [[TMP7]], label [[PRED_UDIV_IF4:%.*]], label [[PRED_UDIV_CONTINUE5:%.*]] 682; CHECK: pred.udiv.if4: 683; CHECK-NEXT: [[TMP8:%.*]] = add i32 [[OFFSET_IDX]], -1 684; CHECK-NEXT: [[TMP9:%.*]] = udiv i32 219220132, [[TMP8]] 685; CHECK-NEXT: [[TMP10:%.*]] = insertelement <4 x i32> [[TMP6]], i32 [[TMP9]], i32 1 686; CHECK-NEXT: br label [[PRED_UDIV_CONTINUE5]] 687; CHECK: pred.udiv.continue5: 688; CHECK-NEXT: [[TMP11:%.*]] = phi <4 x i32> [ [[TMP6]], [[PRED_UDIV_CONTINUE]] ], [ [[TMP10]], [[PRED_UDIV_IF4]] ] 689; CHECK-NEXT: [[TMP12:%.*]] = extractelement <4 x i1> [[TMP2]], i32 2 690; CHECK-NEXT: br i1 [[TMP12]], label [[PRED_UDIV_IF6:%.*]], label [[PRED_UDIV_CONTINUE7:%.*]] 691; CHECK: pred.udiv.if6: 692; CHECK-NEXT: [[TMP13:%.*]] = add i32 [[OFFSET_IDX]], -2 693; CHECK-NEXT: [[TMP14:%.*]] = udiv i32 219220132, [[TMP13]] 694; CHECK-NEXT: [[TMP15:%.*]] = insertelement <4 x i32> [[TMP11]], i32 [[TMP14]], i32 2 695; CHECK-NEXT: br label [[PRED_UDIV_CONTINUE7]] 696; CHECK: pred.udiv.continue7: 697; CHECK-NEXT: [[TMP16:%.*]] = phi <4 x i32> [ [[TMP11]], [[PRED_UDIV_CONTINUE5]] ], [ [[TMP15]], [[PRED_UDIV_IF6]] ] 698; CHECK-NEXT: [[TMP17:%.*]] = extractelement <4 x i1> [[TMP2]], i32 3 699; CHECK-NEXT: br i1 [[TMP17]], label [[PRED_UDIV_IF8:%.*]], label [[PRED_UDIV_CONTINUE9]] 700; CHECK: pred.udiv.if8: 701; CHECK-NEXT: [[TMP18:%.*]] = add i32 [[OFFSET_IDX]], -3 702; CHECK-NEXT: [[TMP19:%.*]] = udiv i32 219220132, [[TMP18]] 703; CHECK-NEXT: [[TMP20:%.*]] = insertelement <4 x i32> [[TMP16]], i32 [[TMP19]], i32 3 704; CHECK-NEXT: br label [[PRED_UDIV_CONTINUE9]] 705; CHECK: pred.udiv.continue9: 706; CHECK-NEXT: [[TMP21]] = phi <4 x i32> [ [[TMP16]], [[PRED_UDIV_CONTINUE7]] ], [ [[TMP20]], [[PRED_UDIV_IF8]] ] 707; CHECK-NEXT: [[TMP22:%.*]] = shufflevector <4 x i32> [[VECTOR_RECUR]], <4 x i32> [[TMP21]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 708; CHECK-NEXT: [[TMP23]] = add <4 x i32> [[VEC_PHI1]], [[TMP22]] 709; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 4 710; CHECK-NEXT: [[TMP24:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]] 711; CHECK-NEXT: br i1 [[TMP24]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !prof !45, [[LOOP46:!llvm.loop !.*]] 712; CHECK: middle.block: 713; CHECK-NEXT: [[TMP25:%.*]] = select <4 x i1> [[TMP2]], <4 x i32> [[TMP23]], <4 x i32> [[VEC_PHI1]] 714; CHECK-NEXT: [[TMP26:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[TMP25]]) 715; CHECK-NEXT: br i1 true, label [[BB1:%.*]], label [[SCALAR_PH]] 716; CHECK: scalar.ph: 717; CHECK-NEXT: br label [[BB2:%.*]] 718; CHECK: bb1: 719; CHECK-NEXT: [[TMP:%.*]] = phi i32 [ undef, [[BB2]] ], [ [[TMP26]], [[MIDDLE_BLOCK]] ] 720; CHECK-NEXT: ret i32 [[TMP]] 721; CHECK: bb2: 722; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB2]], !prof !47, [[LOOP48:!llvm.loop !.*]] 723; 724bb: 725 br label %bb2 726 727 bb1: ; preds = %bb2 728 %tmp = phi i32 [ %tmp6, %bb2 ] 729 ret i32 %tmp 730 731 bb2: ; preds = %bb2, %bb 732 %tmp3 = phi i32 [ %tmp8, %bb2 ], [ %y, %bb ] 733 %tmp4 = phi i32 [ %tmp7, %bb2 ], [ 0, %bb ] 734 %tmp5 = phi i32 [ %tmp6, %bb2 ], [ 0, %bb ] 735 %tmp6 = add i32 %tmp5, %tmp4 736 %tmp7 = udiv i32 219220132, %tmp3 737 %tmp8 = add nsw i32 %tmp3, -1 738 %tmp9 = icmp slt i32 %tmp3, 2 739 br i1 %tmp9, label %bb1, label %bb2, !prof !2 740} 741 742define i32 @sink_into_replication_region_multiple(i32 *%x, i32 %y) { 743; CHECK-LABEL: @sink_into_replication_region_multiple( 744; CHECK-NEXT: bb: 745; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[Y:%.*]], 1 746; CHECK-NEXT: [[SMIN:%.*]] = call i32 @llvm.smin.i32(i32 [[Y]], i32 1) 747; CHECK-NEXT: [[TMP1:%.*]] = sub i32 [[TMP0]], [[SMIN]] 748; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]] 749; CHECK: vector.ph: 750; CHECK-NEXT: [[N_RND_UP:%.*]] = add i32 [[TMP1]], 3 751; CHECK-NEXT: [[N_VEC:%.*]] = and i32 [[N_RND_UP]], -4 752; CHECK-NEXT: [[TRIP_COUNT_MINUS_1:%.*]] = add i32 [[TMP1]], -1 753; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x i32> poison, i32 [[TRIP_COUNT_MINUS_1]], i32 0 754; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x i32> [[BROADCAST_SPLATINSERT]], <4 x i32> poison, <4 x i32> zeroinitializer 755; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] 756; CHECK: vector.body: 757; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[PRED_STORE_CONTINUE16:%.*]] ] 758; CHECK-NEXT: [[VEC_IND2:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT3:%.*]], [[PRED_STORE_CONTINUE16]] ] 759; CHECK-NEXT: [[VECTOR_RECUR:%.*]] = phi <4 x i32> [ <i32 poison, i32 poison, i32 poison, i32 0>, [[VECTOR_PH]] ], [ [[TMP21:%.*]], [[PRED_STORE_CONTINUE16]] ] 760; CHECK-NEXT: [[VEC_PHI4:%.*]] = phi <4 x i32> [ zeroinitializer, [[VECTOR_PH]] ], [ [[TMP23:%.*]], [[PRED_STORE_CONTINUE16]] ] 761; CHECK-NEXT: [[OFFSET_IDX:%.*]] = sub i32 [[Y]], [[INDEX]] 762; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[OFFSET_IDX]], -1 763; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[OFFSET_IDX]], -2 764; CHECK-NEXT: [[TMP4:%.*]] = add i32 [[OFFSET_IDX]], -3 765; CHECK-NEXT: [[TMP5:%.*]] = icmp ule <4 x i32> [[VEC_IND2]], [[BROADCAST_SPLAT]] 766; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x i1> [[TMP5]], i32 0 767; CHECK-NEXT: br i1 [[TMP6]], label [[PRED_UDIV_IF:%.*]], label [[PRED_UDIV_CONTINUE:%.*]] 768; CHECK: pred.udiv.if: 769; CHECK-NEXT: [[TMP7:%.*]] = udiv i32 219220132, [[OFFSET_IDX]] 770; CHECK-NEXT: [[TMP8:%.*]] = insertelement <4 x i32> poison, i32 [[TMP7]], i32 0 771; CHECK-NEXT: br label [[PRED_UDIV_CONTINUE]] 772; CHECK: pred.udiv.continue: 773; CHECK-NEXT: [[TMP9:%.*]] = phi <4 x i32> [ poison, [[VECTOR_BODY]] ], [ [[TMP8]], [[PRED_UDIV_IF]] ] 774; CHECK-NEXT: [[TMP10:%.*]] = extractelement <4 x i1> [[TMP5]], i32 1 775; CHECK-NEXT: br i1 [[TMP10]], label [[PRED_UDIV_IF5:%.*]], label [[PRED_UDIV_CONTINUE6:%.*]] 776; CHECK: pred.udiv.if5: 777; CHECK-NEXT: [[TMP11:%.*]] = udiv i32 219220132, [[TMP2]] 778; CHECK-NEXT: [[TMP12:%.*]] = insertelement <4 x i32> [[TMP9]], i32 [[TMP11]], i32 1 779; CHECK-NEXT: br label [[PRED_UDIV_CONTINUE6]] 780; CHECK: pred.udiv.continue6: 781; CHECK-NEXT: [[TMP13:%.*]] = phi <4 x i32> [ [[TMP9]], [[PRED_UDIV_CONTINUE]] ], [ [[TMP12]], [[PRED_UDIV_IF5]] ] 782; CHECK-NEXT: [[TMP14:%.*]] = extractelement <4 x i1> [[TMP5]], i32 2 783; CHECK-NEXT: br i1 [[TMP14]], label [[PRED_UDIV_IF7:%.*]], label [[PRED_UDIV_CONTINUE8:%.*]] 784; CHECK: pred.udiv.if7: 785; CHECK-NEXT: [[TMP15:%.*]] = udiv i32 219220132, [[TMP3]] 786; CHECK-NEXT: [[TMP16:%.*]] = insertelement <4 x i32> [[TMP13]], i32 [[TMP15]], i32 2 787; CHECK-NEXT: br label [[PRED_UDIV_CONTINUE8]] 788; CHECK: pred.udiv.continue8: 789; CHECK-NEXT: [[TMP17:%.*]] = phi <4 x i32> [ [[TMP13]], [[PRED_UDIV_CONTINUE6]] ], [ [[TMP16]], [[PRED_UDIV_IF7]] ] 790; CHECK-NEXT: [[TMP18:%.*]] = extractelement <4 x i1> [[TMP5]], i32 3 791; CHECK-NEXT: br i1 [[TMP18]], label [[PRED_UDIV_IF9:%.*]], label [[PRED_UDIV_CONTINUE10:%.*]] 792; CHECK: pred.udiv.if9: 793; CHECK-NEXT: [[TMP19:%.*]] = udiv i32 219220132, [[TMP4]] 794; CHECK-NEXT: [[TMP20:%.*]] = insertelement <4 x i32> [[TMP17]], i32 [[TMP19]], i32 3 795; CHECK-NEXT: br label [[PRED_UDIV_CONTINUE10]] 796; CHECK: pred.udiv.continue10: 797; CHECK-NEXT: [[TMP21]] = phi <4 x i32> [ [[TMP17]], [[PRED_UDIV_CONTINUE8]] ], [ [[TMP20]], [[PRED_UDIV_IF9]] ] 798; CHECK-NEXT: [[TMP22:%.*]] = shufflevector <4 x i32> [[VECTOR_RECUR]], <4 x i32> [[TMP21]], <4 x i32> <i32 3, i32 4, i32 5, i32 6> 799; CHECK-NEXT: [[TMP23]] = add <4 x i32> [[VEC_PHI4]], [[TMP22]] 800; CHECK-NEXT: [[TMP24:%.*]] = extractelement <4 x i1> [[TMP5]], i32 0 801; CHECK-NEXT: br i1 [[TMP24]], label [[PRED_STORE_IF:%.*]], label [[PRED_STORE_CONTINUE:%.*]] 802; CHECK: pred.store.if: 803; CHECK-NEXT: [[TMP25:%.*]] = sext i32 [[INDEX]] to i64 804; CHECK-NEXT: [[TMP26:%.*]] = getelementptr inbounds i32, i32* [[X:%.*]], i64 [[TMP25]] 805; CHECK-NEXT: store i32 [[OFFSET_IDX]], i32* [[TMP26]], align 4 806; CHECK-NEXT: br label [[PRED_STORE_CONTINUE]] 807; CHECK: pred.store.continue: 808; CHECK-NEXT: [[TMP27:%.*]] = extractelement <4 x i1> [[TMP5]], i32 1 809; CHECK-NEXT: br i1 [[TMP27]], label [[PRED_STORE_IF11:%.*]], label [[PRED_STORE_CONTINUE12:%.*]] 810; CHECK: pred.store.if11: 811; CHECK-NEXT: [[TMP28:%.*]] = or i32 [[INDEX]], 1 812; CHECK-NEXT: [[TMP29:%.*]] = sext i32 [[TMP28]] to i64 813; CHECK-NEXT: [[TMP30:%.*]] = getelementptr inbounds i32, i32* [[X]], i64 [[TMP29]] 814; CHECK-NEXT: store i32 [[TMP2]], i32* [[TMP30]], align 4 815; CHECK-NEXT: br label [[PRED_STORE_CONTINUE12]] 816; CHECK: pred.store.continue12: 817; CHECK-NEXT: [[TMP31:%.*]] = extractelement <4 x i1> [[TMP5]], i32 2 818; CHECK-NEXT: br i1 [[TMP31]], label [[PRED_STORE_IF13:%.*]], label [[PRED_STORE_CONTINUE14:%.*]] 819; CHECK: pred.store.if13: 820; CHECK-NEXT: [[TMP32:%.*]] = or i32 [[INDEX]], 2 821; CHECK-NEXT: [[TMP33:%.*]] = sext i32 [[TMP32]] to i64 822; CHECK-NEXT: [[TMP34:%.*]] = getelementptr inbounds i32, i32* [[X]], i64 [[TMP33]] 823; CHECK-NEXT: store i32 [[TMP3]], i32* [[TMP34]], align 4 824; CHECK-NEXT: br label [[PRED_STORE_CONTINUE14]] 825; CHECK: pred.store.continue14: 826; CHECK-NEXT: [[TMP35:%.*]] = extractelement <4 x i1> [[TMP5]], i32 3 827; CHECK-NEXT: br i1 [[TMP35]], label [[PRED_STORE_IF15:%.*]], label [[PRED_STORE_CONTINUE16]] 828; CHECK: pred.store.if15: 829; CHECK-NEXT: [[TMP36:%.*]] = or i32 [[INDEX]], 3 830; CHECK-NEXT: [[TMP37:%.*]] = sext i32 [[TMP36]] to i64 831; CHECK-NEXT: [[TMP38:%.*]] = getelementptr inbounds i32, i32* [[X]], i64 [[TMP37]] 832; CHECK-NEXT: store i32 [[TMP4]], i32* [[TMP38]], align 4 833; CHECK-NEXT: br label [[PRED_STORE_CONTINUE16]] 834; CHECK: pred.store.continue16: 835; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 4 836; CHECK-NEXT: [[VEC_IND_NEXT3]] = add <4 x i32> [[VEC_IND2]], <i32 4, i32 4, i32 4, i32 4> 837; CHECK-NEXT: [[TMP39:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]] 838; CHECK-NEXT: br i1 [[TMP39]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !prof !45, [[LOOP49:!llvm.loop !.*]] 839; CHECK: middle.block: 840; CHECK-NEXT: [[TMP40:%.*]] = select <4 x i1> [[TMP5]], <4 x i32> [[TMP23]], <4 x i32> [[VEC_PHI4]] 841; CHECK-NEXT: [[TMP41:%.*]] = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> [[TMP40]]) 842; CHECK-NEXT: br i1 true, label [[BB1:%.*]], label [[SCALAR_PH]] 843; CHECK: scalar.ph: 844; CHECK-NEXT: br label [[BB2:%.*]] 845; CHECK: bb1: 846; CHECK-NEXT: [[TMP:%.*]] = phi i32 [ undef, [[BB2]] ], [ [[TMP41]], [[MIDDLE_BLOCK]] ] 847; CHECK-NEXT: ret i32 [[TMP]] 848; CHECK: bb2: 849; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB2]], !prof !47, [[LOOP50:!llvm.loop !.*]] 850; 851bb: 852 br label %bb2 853 854 bb1: ; preds = %bb2 855 %tmp = phi i32 [ %tmp6, %bb2 ] 856 ret i32 %tmp 857 858 bb2: ; preds = %bb2, %bb 859 %tmp3 = phi i32 [ %tmp8, %bb2 ], [ %y, %bb ] 860 %iv = phi i32 [ %iv.next, %bb2 ], [ 0, %bb ] 861 %tmp4 = phi i32 [ %tmp7, %bb2 ], [ 0, %bb ] 862 %tmp5 = phi i32 [ %tmp6, %bb2 ], [ 0, %bb ] 863 %g = getelementptr inbounds i32, i32* %x, i32 %iv 864 %tmp6 = add i32 %tmp5, %tmp4 865 %tmp7 = udiv i32 219220132, %tmp3 866 store i32 %tmp3, i32* %g, align 4 867 %tmp8 = add nsw i32 %tmp3, -1 868 %iv.next = add nsw i32 %iv, 1 869 %tmp9 = icmp slt i32 %tmp3, 2 870 br i1 %tmp9, label %bb1, label %bb2, !prof !2 871} 872 873!2 = !{!"branch_weights", i32 1, i32 1} 874