1; RUN: opt < %s -loop-vectorize -prefer-predicate-over-epilogue=predicate-dont-vectorize -force-vector-width=4 -S | FileCheck %s 2 3; Check that a counting-down loop which has no primary induction variable 4; is vectorized with preferred predication. 5 6; CHECK-LABEL: vector.body: 7; CHECK-LABEL: middle.block: 8; CHECK-NEXT: br i1 true, 9 10target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" 11 12define dso_local void @foo(i8* noalias nocapture readonly %A, i8* noalias nocapture readonly %B, i8* noalias nocapture %C, i32 %N) { 13entry: 14 %cmp6 = icmp eq i32 %N, 0 15 br i1 %cmp6, label %while.end, label %while.body.preheader 16 17while.body.preheader: 18 br label %while.body 19 20while.body: 21 %N.addr.010 = phi i32 [ %dec, %while.body ], [ %N, %while.body.preheader ] 22 %C.addr.09 = phi i8* [ %incdec.ptr4, %while.body ], [ %C, %while.body.preheader ] 23 %B.addr.08 = phi i8* [ %incdec.ptr1, %while.body ], [ %B, %while.body.preheader ] 24 %A.addr.07 = phi i8* [ %incdec.ptr, %while.body ], [ %A, %while.body.preheader ] 25 %incdec.ptr = getelementptr inbounds i8, i8* %A.addr.07, i32 1 26 %0 = load i8, i8* %A.addr.07, align 1 27 %incdec.ptr1 = getelementptr inbounds i8, i8* %B.addr.08, i32 1 28 %1 = load i8, i8* %B.addr.08, align 1 29 %add = add i8 %1, %0 30 %incdec.ptr4 = getelementptr inbounds i8, i8* %C.addr.09, i32 1 31 store i8 %add, i8* %C.addr.09, align 1 32 %dec = add i32 %N.addr.010, -1 33 %cmp = icmp eq i32 %dec, 0 34 br i1 %cmp, label %while.end.loopexit, label %while.body 35 36while.end.loopexit: 37 br label %while.end 38 39while.end: 40 ret void 41} 42 43; Make sure a loop is successfully vectorized with fold-tail when the backedge 44; taken count is constant and used inside the loop. Issue revealed by D76992. 45; 46define void @reuse_const_btc(i8* %A) optsize { 47; CHECK-LABEL: @reuse_const_btc 48; CHECK: {{%.*}} = icmp ule <4 x i32> {{%.*}}, <i32 13, i32 13, i32 13, i32 13> 49; CHECK: {{%.*}} = select <4 x i1> {{%.*}}, <4 x i32> <i32 12, i32 12, i32 12, i32 12>, <4 x i32> <i32 13, i32 13, i32 13, i32 13> 50; 51entry: 52 br label %loop 53 54loop: 55 %riv = phi i32 [ 13, %entry ], [ %rivMinus1, %merge ] 56 %sub = sub nuw nsw i32 20, %riv 57 %arrayidx = getelementptr inbounds i8, i8* %A, i32 %sub 58 %cond0 = icmp eq i32 %riv, 7 59 br i1 %cond0, label %then, label %else 60then: 61 br label %merge 62else: 63 br label %merge 64merge: 65 %blend = phi i32 [ 13, %then ], [ 12, %else ] 66 %trunc = trunc i32 %blend to i8 67 store i8 %trunc, i8* %arrayidx, align 1 68 %rivMinus1 = add nuw nsw i32 %riv, -1 69 %cond = icmp eq i32 %riv, 0 70 br i1 %cond, label %exit, label %loop 71 72exit: 73 ret void 74} 75