1; RUN: opt -S -loop-vectorize -force-vector-interleave=1 -force-vector-width=2 < %s | FileCheck %s 2 3; CHECK-LABEL: @postinc 4; CHECK-LABEL: scalar.ph: 5; CHECK: %bc.resume.val = phi i32 [ %n.vec, %middle.block ], [ 0, %entry ] 6; CHECK-LABEL: for.end: 7; CHECK: %[[RET:.*]] = phi i32 [ {{.*}}, %for.body ], [ %n.vec, %middle.block ] 8; CHECK: ret i32 %[[RET]] 9define i32 @postinc(i32 %k) { 10entry: 11 br label %for.body 12 13for.body: 14 %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ] 15 %inc = add nsw i32 %inc.phi, 1 16 %cmp = icmp eq i32 %inc, %k 17 br i1 %cmp, label %for.end, label %for.body 18 19for.end: 20 ret i32 %inc 21} 22 23; CHECK-LABEL: @preinc 24; CHECK-LABEL: middle.block: 25; CHECK: %[[v3:.+]] = sub i32 %n.vec, 1 26; CHECK: %ind.escape = add i32 0, %[[v3]] 27; CHECK-LABEL: scalar.ph: 28; CHECK: %bc.resume.val = phi i32 [ %n.vec, %middle.block ], [ 0, %entry ] 29; CHECK-LABEL: for.end: 30; CHECK: %[[RET:.*]] = phi i32 [ {{.*}}, %for.body ], [ %ind.escape, %middle.block ] 31; CHECK: ret i32 %[[RET]] 32define i32 @preinc(i32 %k) { 33entry: 34 br label %for.body 35 36for.body: 37 %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ] 38 %inc = add nsw i32 %inc.phi, 1 39 %cmp = icmp eq i32 %inc, %k 40 br i1 %cmp, label %for.end, label %for.body 41 42for.end: 43 ret i32 %inc.phi 44} 45 46; CHECK-LABEL: @constpre 47; CHECK-LABEL: for.end: 48; CHECK: %[[RET:.*]] = phi i32 [ {{.*}}, %for.body ], [ 2, %middle.block ] 49; CHECK: ret i32 %[[RET]] 50define i32 @constpre() { 51entry: 52 br label %for.body 53 54for.body: 55 %inc.phi = phi i32 [ 32, %entry ], [ %inc, %for.body ] 56 %inc = sub nsw i32 %inc.phi, 2 57 %cmp = icmp eq i32 %inc, 0 58 br i1 %cmp, label %for.end, label %for.body 59 60for.end: 61 ret i32 %inc.phi 62} 63 64; CHECK-LABEL: @geppre 65; CHECK-LABEL: middle.block: 66; CHECK: %ind.escape = getelementptr i32, i32* %ptr, i64 124 67; CHECK-LABEL: for.end: 68; CHECK: %[[RET:.*]] = phi i32* [ {{.*}}, %for.body ], [ %ind.escape, %middle.block ] 69; CHECK: ret i32* %[[RET]] 70define i32* @geppre(i32* %ptr) { 71entry: 72 br label %for.body 73 74for.body: 75 %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ] 76 %ptr.phi = phi i32* [ %ptr, %entry ], [ %inc.ptr, %for.body ] 77 %inc = add nsw i32 %inc.phi, 1 78 %inc.ptr = getelementptr i32, i32* %ptr.phi, i32 4 79 %cmp = icmp eq i32 %inc, 32 80 br i1 %cmp, label %for.end, label %for.body 81 82for.end: 83 ret i32* %ptr.phi 84} 85 86; CHECK-LABEL: @both 87; CHECK-LABEL: middle.block: 88; CHECK: %[[END:.*]] = sub i64 %n.vec, 1 89; CHECK: %ind.escape = getelementptr i32, i32* %base, i64 %[[END]] 90; CHECK-LABEL: for.end: 91; CHECK: %[[RET:.*]] = phi i32* [ %inc.lag1, %for.body ], [ %ind.escape, %middle.block ] 92; CHECK: ret i32* %[[RET]] 93 94define i32* @both(i32 %k) { 95entry: 96 %base = getelementptr inbounds i32, i32* undef, i64 1 97 br label %for.body 98 99for.body: 100 %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ] 101 %inc.lag1 = phi i32* [ %base, %entry ], [ %tmp, %for.body] 102 %inc.lag2 = phi i32* [ undef, %entry ], [ %inc.lag1, %for.body] 103 %tmp = getelementptr inbounds i32, i32* %inc.lag1, i64 1 104 %inc = add nsw i32 %inc.phi, 1 105 %cmp = icmp eq i32 %inc, %k 106 br i1 %cmp, label %for.end, label %for.body 107 108for.end: 109 ret i32* %inc.lag1 110} 111 112; CHECK-LABEL: @multiphi 113; CHECK-LABEL: scalar.ph: 114; CHECK: %bc.resume.val = phi i32 [ %n.vec, %middle.block ], [ 0, %entry ] 115; CHECK-LABEL: for.end: 116; CHECK: %phi = phi i32 [ {{.*}}, %for.body ], [ %n.vec, %middle.block ] 117; CHECK: %phi2 = phi i32 [ {{.*}}, %for.body ], [ %n.vec, %middle.block ] 118; CHECK: store i32 %phi2, i32* %p 119; CHECK: ret i32 %phi 120define i32 @multiphi(i32 %k, i32* %p) { 121entry: 122 br label %for.body 123 124for.body: 125 %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ] 126 %inc = add nsw i32 %inc.phi, 1 127 %cmp = icmp eq i32 %inc, %k 128 br i1 %cmp, label %for.end, label %for.body 129 130for.end: 131 %phi = phi i32 [ %inc, %for.body ] 132 %phi2 = phi i32 [ %inc, %for.body ] 133 store i32 %phi2, i32* %p 134 ret i32 %phi 135} 136