75 lines · plain
1; RUN: opt < %s -passes=loop-vectorize -prefer-predicate-over-epilogue=predicate-dont-vectorize -force-vector-width=4 -S | FileCheck %s2 3; Check that a counting-down loop which has no primary induction variable4; is vectorized with preferred predication.5 6; CHECK-LABEL: vector.body:7; CHECK-LABEL: middle.block:8; CHECK-NEXT: br label %while.end.loopexit9 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(ptr noalias nocapture readonly %A, ptr noalias nocapture readonly %B, ptr noalias nocapture %C, i32 %N) {13entry:14 %cmp6 = icmp eq i32 %N, 015 br i1 %cmp6, label %while.end, label %while.body.preheader16 17while.body.preheader:18 br label %while.body19 20while.body: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 126 %0 = load i8, ptr %A.addr.07, align 127 %incdec.ptr1 = getelementptr inbounds i8, ptr %B.addr.08, i32 128 %1 = load i8, ptr %B.addr.08, align 129 %add = add i8 %1, %030 %incdec.ptr4 = getelementptr inbounds i8, ptr %C.addr.09, i32 131 store i8 %add, ptr %C.addr.09, align 132 %dec = add i32 %N.addr.010, -133 %cmp = icmp eq i32 %dec, 034 br i1 %cmp, label %while.end.loopexit, label %while.body35 36while.end.loopexit:37 br label %while.end38 39while.end:40 ret void41}42 43; Make sure a loop is successfully vectorized with fold-tail when the backedge44; taken count is constant and used inside the loop. Issue revealed by D76992.45;46define void @reuse_const_btc(ptr %A) {47; CHECK-LABEL: @reuse_const_btc48; CHECK: {{%.*}} = icmp ule <4 x i32> {{%.*}}, splat (i32 13)49; CHECK: {{%.*}} = select <4 x i1> {{%.*}}, <4 x i32> splat (i32 13), <4 x i32> splat (i32 12)50;51entry:52 br label %loop53 54loop:55 %riv = phi i32 [ 13, %entry ], [ %rivMinus1, %merge ]56 %sub = sub nuw nsw i32 20, %riv57 %arrayidx = getelementptr inbounds i8, ptr %A, i32 %sub58 %cond0 = icmp eq i32 %riv, 759 br i1 %cond0, label %then, label %else60then:61 br label %merge62else:63 br label %merge64merge:65 %blend = phi i32 [ 13, %then ], [ 12, %else ]66 %trunc = trunc i32 %blend to i867 store i8 %trunc, ptr %arrayidx, align 168 %rivMinus1 = add nuw nsw i32 %riv, -169 %cond = icmp eq i32 %riv, 070 br i1 %cond, label %exit, label %loop71 72exit:73 ret void74}75