1; REQUIRES: asserts
2; RUN: opt < %s  -passes='loop-vectorize' -force-vector-width=2 -enable-epilogue-vectorization -epilogue-vectorization-force-VF=2 --debug-only=loop-vectorize -S 2>&1 | FileCheck %s
3
4target datalayout = "e-m:e-i64:64-n32:64-v256:256:256-v512:512:512"
5
6; Currently we cannot handle reduction loops.
7; CHECK: LV: Checking a loop in "f1"
8; CHECK: LEV: Unable to vectorize epilogue because the loop is not a supported candidate.
9
10define signext i32 @f1(i8* noalias %A, i32 signext %n) {
11entry:
12  %cmp1 = icmp sgt i32 %n, 0
13  br i1 %cmp1, label %for.body.preheader, label %for.end
14
15for.body.preheader:                               ; preds = %entry
16  %wide.trip.count = zext i32 %n to i64
17  br label %for.body
18
19for.body:                                         ; preds = %for.body.preheader, %for.body
20  %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
21  %sum.02 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ]
22  %arrayidx = getelementptr inbounds i8, i8* %A, i64 %indvars.iv
23  %0 = load i8, i8* %arrayidx, align 1
24  %conv = zext i8 %0 to i32
25  %add = add nuw nsw i32 %sum.02, %conv
26  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
27  %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count
28  br i1 %exitcond, label %for.body, label %for.end.loopexit
29
30for.end.loopexit:                                 ; preds = %for.body
31  %add.lcssa = phi i32 [ %add, %for.body ]
32  br label %for.end
33
34for.end:                                          ; preds = %for.end.loopexit, %entry
35  %sum.0.lcssa = phi i32 [ 0, %entry ], [ %add.lcssa, %for.end.loopexit ]
36  ret i32 %sum.0.lcssa
37}
38
39; Currently we cannot handle live-out variables that are recurrences.
40; CHECK: LV: Checking a loop in "f2"
41; CHECK: LEV: Unable to vectorize epilogue because the loop is not a supported candidate.
42
43define signext i32 @f2(i8* noalias %A, i32 signext %n) {
44entry:
45  %cmp1 = icmp sgt i32 %n, 0
46  br i1 %cmp1, label %for.body.preheader, label %for.end
47
48for.body.preheader:                               ; preds = %entry
49  %wide.trip.count = zext i32 %n to i64
50  br label %for.body
51
52for.body:                                         ; preds = %for.body.preheader, %for.body
53  %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
54  %arrayidx = getelementptr inbounds i8, i8* %A, i64 %indvars.iv
55  %0 = load i8, i8* %arrayidx, align 1
56  %add = add i8 %0, 1
57  %arrayidx3 = getelementptr inbounds i8, i8* %A, i64 %indvars.iv
58  store i8 %add, i8* %arrayidx3, align 1
59  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
60  %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count
61  br i1 %exitcond, label %for.body, label %for.end.loopexit
62
63for.end.loopexit:                                 ; preds = %for.body
64  %inc.lcssa.wide = phi i64 [ %indvars.iv.next, %for.body ]
65  %1 = trunc i64 %inc.lcssa.wide to i32
66  br label %for.end
67
68for.end:                                          ; preds = %for.end.loopexit, %entry
69  %i.0.lcssa = phi i32 [ 0, %entry ], [ %1, %for.end.loopexit ]
70  ret i32 %i.0.lcssa
71}
72
73; Currently we cannot handle widended/truncated inductions.
74; CHECK: LV: Checking a loop in "f3"
75; CHECK: LEV: Unable to vectorize epilogue because the loop is not a supported candidate.
76
77define void @f3(i8* noalias %A, i32 signext %n) {
78entry:
79  %cmp1 = icmp sgt i32 %n, 0
80  br i1 %cmp1, label %for.body.preheader, label %for.end
81
82for.body.preheader:                               ; preds = %entry
83  %wide.trip.count = zext i32 %n to i64
84  br label %for.body
85
86for.body:                                         ; preds = %for.body.preheader, %for.body
87  %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
88  %0 = trunc i64 %indvars.iv to i32
89  %conv = trunc i32 %0 to i8
90  %arrayidx = getelementptr inbounds i8, i8* %A, i64 %indvars.iv
91  store i8 %conv, i8* %arrayidx, align 1
92  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
93  %exitcond = icmp ne i64 %indvars.iv.next, %wide.trip.count
94  br i1 %exitcond, label %for.body, label %for.end.loopexit
95
96for.end.loopexit:                                 ; preds = %for.body
97  br label %for.end
98
99for.end:                                          ; preds = %for.end.loopexit, %entry
100  ret void
101}
102