2 ; RUN: opt -mtriple=s390x-unknown-linux -mcpu=z13 -passes=loop-vectorize \
3 ; RUN: -debug-only=loop-vectorize,vectorutils -max-interleave-group-factor=64\
4 ; RUN: -disable-output < %s 2>&1 | FileCheck %s
6 ; Check that some cost estimations for interleave groups make sense.
8 ; This loop is loading four i16 values at indices [0, 1, 2, 3], with a stride
9 ; of 4. At VF=4, memory interleaving means loading 4 * 4 * 16 bits = 2 vector
10 ; registers. Each of the 4 vector values must then be constructed from the
11 ; two vector registers using one vperm each, which gives a cost of 2 + 4 = 6.
13 ; CHECK: LV: Checking a loop in 'fun0'
14 ; CHECK: LV: Found an estimated cost of 6 for VF 4 For instruction: %ld0 = load i16
15 ; CHECK: LV: Found an estimated cost of 0 for VF 4 For instruction: %ld1 = load i16
16 ; CHECK: LV: Found an estimated cost of 0 for VF 4 For instruction: %ld2 = load i16
17 ; CHECK: LV: Found an estimated cost of 0 for VF 4 For instruction: %ld3 = load i16
18 define void @fun0(ptr %ptr, ptr %dst) {
23 %ivptr = phi ptr [ %ptr.next, %for.body ], [ %ptr, %entry ]
24 %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ]
26 %ld0 = load i16, ptr %ivptr
27 %ptr1 = getelementptr inbounds i16, ptr %ivptr, i64 1
28 %ld1 = load i16, ptr %ptr1
29 %ptr2 = getelementptr inbounds i16, ptr %ivptr, i64 2
30 %ld2 = load i16, ptr %ptr2
31 %ptr3 = getelementptr inbounds i16, ptr %ivptr, i64 3
32 %ld3 = load i16, ptr %ptr3
33 %a1 = add i16 %ld0, %ld1
34 %a2 = add i16 %a1, %ld2
35 %a3 = add i16 %a2, %ld3
36 %dstptr = getelementptr inbounds i16, ptr %dst, i64 %iv
37 store i16 %a3, ptr %dstptr
38 %ptr.next = getelementptr inbounds i16, ptr %ivptr, i64 4
39 %cmp = icmp eq i64 %inc, 100
40 br i1 %cmp, label %for.end, label %for.body
46 ; This loop loads one i8 value in a stride of 3. At VF=16, this means loading
47 ; 3 vector registers, and then constructing the vector value with two vperms,
48 ; which gives a cost of 5.
50 ; CHECK: LV: Checking a loop in 'fun1'
51 ; CHECK: LV: Found an estimated cost of 5 for VF 16 For instruction: %ld0 = load i8
52 define void @fun1(ptr %ptr, ptr %dst) {
57 %ivptr = phi ptr [ %ptr.next, %for.body ], [ %ptr, %entry ]
58 %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ]
60 %ld0 = load i8, ptr %ivptr
61 %dstptr = getelementptr inbounds i8, ptr %dst, i64 %iv
62 store i8 %ld0, ptr %dstptr
63 %ptr.next = getelementptr inbounds i8, ptr %ivptr, i64 3
64 %cmp = icmp eq i64 %inc, 100
65 br i1 %cmp, label %for.end, label %for.body
71 ; This loop is loading 4 i8 values at indexes [0, 1, 2, 3], with a stride of
72 ; 32. At VF=2, this means loading 2 vector registers, and using 4 vperms to
73 ; produce the vector values, which gives a cost of 6.
75 ; CHECK: LV: Checking a loop in 'fun2'
76 ; CHECK: LV: Found an estimated cost of 6 for VF 2 For instruction: %ld0 = load i8
77 ; CHECK: LV: Found an estimated cost of 0 for VF 2 For instruction: %ld1 = load i8
78 ; CHECK: LV: Found an estimated cost of 0 for VF 2 For instruction: %ld2 = load i8
79 ; CHECK: LV: Found an estimated cost of 0 for VF 2 For instruction: %ld3 = load i8
80 define void @fun2(ptr %ptr, ptr %dst) {
85 %ivptr = phi ptr [ %ptr.next, %for.body ], [ %ptr, %entry ]
86 %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ]
88 %ld0 = load i8, ptr %ivptr
89 %ptr1 = getelementptr inbounds i8, ptr %ivptr, i64 1
90 %ld1 = load i8, ptr %ptr1
91 %ptr2 = getelementptr inbounds i8, ptr %ivptr, i64 2
92 %ld2 = load i8, ptr %ptr2
93 %ptr3 = getelementptr inbounds i8, ptr %ivptr, i64 3
94 %ld3 = load i8, ptr %ptr3
95 %a1 = add i8 %ld0, %ld1
96 %a2 = add i8 %a1, %ld2
97 %a3 = add i8 %a2, %ld3
98 %dstptr = getelementptr inbounds i8, ptr %dst, i64 %iv
99 store i8 %a3, ptr %dstptr
100 %ptr.next = getelementptr inbounds i8, ptr %ivptr, i64 32
101 %cmp = icmp eq i64 %inc, 100
102 br i1 %cmp, label %for.end, label %for.body
108 ; This loop is loading 4 i8 values at indexes [0, 1, 2, 3], with a stride of
109 ; 30. At VF=2, this means loading 3 vector registers, and using 4 vperms to
110 ; produce the vector values, which gives a cost of 7. This is the same loop
111 ; as in fun2, except the stride makes the second iterations values overlap a
112 ; vector register boundary.
114 ; CHECK: LV: Checking a loop in 'fun3'
115 ; CHECK: LV: Found an estimated cost of 7 for VF 2 For instruction: %ld0 = load i8
116 ; CHECK: LV: Found an estimated cost of 0 for VF 2 For instruction: %ld1 = load i8
117 ; CHECK: LV: Found an estimated cost of 0 for VF 2 For instruction: %ld2 = load i8
118 ; CHECK: LV: Found an estimated cost of 0 for VF 2 For instruction: %ld3 = load i8
119 define void @fun3(ptr %ptr, ptr %dst) {
124 %ivptr = phi ptr [ %ptr.next, %for.body ], [ %ptr, %entry ]
125 %iv = phi i64 [ %inc, %for.body ], [ 0, %entry ]
126 %inc = add i64 %iv, 4
127 %ld0 = load i8, ptr %ivptr
128 %ptr1 = getelementptr inbounds i8, ptr %ivptr, i64 1
129 %ld1 = load i8, ptr %ptr1
130 %ptr2 = getelementptr inbounds i8, ptr %ivptr, i64 2
131 %ld2 = load i8, ptr %ptr2
132 %ptr3 = getelementptr inbounds i8, ptr %ivptr, i64 3
133 %ld3 = load i8, ptr %ptr3
134 %a1 = add i8 %ld0, %ld1
135 %a2 = add i8 %a1, %ld2
136 %a3 = add i8 %a2, %ld3
137 %dstptr = getelementptr inbounds i8, ptr %dst, i64 %iv
138 store i8 %a3, ptr %dstptr
139 %ptr.next = getelementptr inbounds i8, ptr %ivptr, i64 30
140 %cmp = icmp eq i64 %inc, 100
141 br i1 %cmp, label %for.end, label %for.body