1 ; RUN: opt < %s -passes=loop-vectorize -prefer-predicate-over-epilogue=predicate-dont-vectorize -force-vector-width=4 -S | FileCheck %s
3 ; Check that a counting-down loop which has no primary induction variable
4 ; is vectorized with preferred predication.
6 ; CHECK-LABEL: vector.body:
7 ; CHECK-LABEL: middle.block:
8 ; CHECK-NEXT: br i1 true,
10 target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
12 define dso_local void @foo(ptr noalias nocapture readonly %A, ptr noalias nocapture readonly %B, ptr noalias nocapture %C, i32 %N) {
14 %cmp6 = icmp eq i32 %N, 0
15 br i1 %cmp6, label %while.end, label %while.body.preheader
21 %N.addr.010 = phi i32 [ %dec, %while.body ], [ %N, %while.body.preheader ]
22 %C.addr.09 = phi ptr [ %incdec.ptr4, %while.body ], [ %C, %while.body.preheader ]
23 %B.addr.08 = phi ptr [ %incdec.ptr1, %while.body ], [ %B, %while.body.preheader ]
24 %A.addr.07 = phi ptr [ %incdec.ptr, %while.body ], [ %A, %while.body.preheader ]
25 %incdec.ptr = getelementptr inbounds i8, ptr %A.addr.07, i32 1
26 %0 = load i8, ptr %A.addr.07, align 1
27 %incdec.ptr1 = getelementptr inbounds i8, ptr %B.addr.08, i32 1
28 %1 = load i8, ptr %B.addr.08, align 1
30 %incdec.ptr4 = getelementptr inbounds i8, ptr %C.addr.09, i32 1
31 store i8 %add, ptr %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
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.
46 define void @reuse_const_btc(ptr %A) optsize {
47 ; CHECK-LABEL: @reuse_const_btc
48 ; CHECK: {{%.*}} = icmp ule <4 x i32> {{%.*}}, splat (i32 13)
49 ; CHECK: {{%.*}} = select <4 x i1> {{%.*}}, <4 x i32> splat (i32 12), <4 x i32> splat (i32 13)
55 %riv = phi i32 [ 13, %entry ], [ %rivMinus1, %merge ]
56 %sub = sub nuw nsw i32 20, %riv
57 %arrayidx = getelementptr inbounds i8, ptr %A, i32 %sub
58 %cond0 = icmp eq i32 %riv, 7
59 br i1 %cond0, label %then, label %else
65 %blend = phi i32 [ 13, %then ], [ 12, %else ]
66 %trunc = trunc i32 %blend to i8
67 store i8 %trunc, ptr %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