1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -S -passes=loop-vectorize -force-vector-interleave=2 | FileCheck %s 3 4; Demonstrate a case where we unroll a loop, but don't vectorize it. 5; The original loop runs stores in the latch block on iterations 0 to 1022, 6; and exits when %indvars.iv = 1023. (That is, it actually runs the stores 7; for an odd number of iterations.) If we unroll by two in the "vector.body" 8; loop, we must exit to the epilogue on iteration with %indvars.iv = 1022 to 9; avoid an out of bounds access. 10 11define void @test(ptr %data) { 12; CHECK-LABEL: @test( 13; CHECK-NEXT: entry: 14; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]] 15; CHECK: vector.ph: 16; CHECK-NEXT: br label [[VECTOR_BODY:%.*]] 17; CHECK: vector.body: 18; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] 19; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0 20; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 1 21; CHECK-NEXT: [[TMP2:%.*]] = shl nuw nsw i64 [[TMP0]], 1 22; CHECK-NEXT: [[TMP3:%.*]] = shl nuw nsw i64 [[TMP1]], 1 23; CHECK-NEXT: [[TMP4:%.*]] = or disjoint i64 [[TMP2]], 1 24; CHECK-NEXT: [[TMP5:%.*]] = or disjoint i64 [[TMP3]], 1 25; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds double, ptr [[DATA:%.*]], i64 [[TMP4]] 26; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds double, ptr [[DATA]], i64 [[TMP5]] 27; CHECK-NEXT: [[TMP8:%.*]] = load double, ptr [[TMP6]], align 8 28; CHECK-NEXT: [[TMP9:%.*]] = load double, ptr [[TMP7]], align 8 29; CHECK-NEXT: [[TMP10:%.*]] = fneg double [[TMP8]] 30; CHECK-NEXT: [[TMP11:%.*]] = fneg double [[TMP9]] 31; CHECK-NEXT: store double [[TMP10]], ptr [[TMP6]], align 8 32; CHECK-NEXT: store double [[TMP11]], ptr [[TMP7]], align 8 33; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2 34; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1022 35; CHECK-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] 36; CHECK: middle.block: 37; CHECK-NEXT: br label [[SCALAR_PH]] 38; CHECK: scalar.ph: 39; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1022, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ] 40; CHECK-NEXT: br label [[FOR_BODY:%.*]] 41; CHECK: for.body: 42; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_LATCH:%.*]] ] 43; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1 44; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 1024 45; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_END:%.*]], label [[FOR_LATCH]] 46; CHECK: for.latch: 47; CHECK-NEXT: [[T15:%.*]] = shl nuw nsw i64 [[INDVARS_IV]], 1 48; CHECK-NEXT: [[T16:%.*]] = or disjoint i64 [[T15]], 1 49; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[DATA]], i64 [[T16]] 50; CHECK-NEXT: [[T17:%.*]] = load double, ptr [[ARRAYIDX]], align 8 51; CHECK-NEXT: [[FNEG:%.*]] = fneg double [[T17]] 52; CHECK-NEXT: store double [[FNEG]], ptr [[ARRAYIDX]], align 8 53; CHECK-NEXT: br label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]] 54; CHECK: for.end: 55; CHECK-NEXT: ret void 56; 57entry: 58 br label %for.body 59 60for.body: 61 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.latch ] 62 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 63 %exitcond.not = icmp eq i64 %indvars.iv.next, 1024 64 br i1 %exitcond.not, label %for.end, label %for.latch 65 66for.latch: 67 %t15 = shl nuw nsw i64 %indvars.iv, 1 68 %t16 = or disjoint i64 %t15, 1 69 %arrayidx = getelementptr inbounds double, ptr %data, i64 %t16 70 %t17 = load double, ptr %arrayidx, align 8 71 %fneg = fneg double %t17 72 store double %fneg, ptr %arrayidx, align 8 73 br label %for.body 74 75for.end: 76 ret void 77} 78