Skip to content

Commit a4caa47

Browse files
committed
Add tests showing runtime checks cost with low trip counts
1 parent 36a073a commit a4caa47

File tree

1 file changed

+187
-0
lines changed

1 file changed

+187
-0
lines changed
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
; REQUIRES: asserts
2+
; RUN: opt -p loop-vectorize -debug-only=loop-vectorize -S -disable-output < %s 2>&1 | FileCheck %s
3+
4+
target triple = "aarch64-unknown-linux-gnu"
5+
6+
7+
define void @outer_no_tc(ptr nocapture noundef %a, ptr nocapture noundef readonly %b, i64 noundef %m, i64 noundef %n) {
8+
; CHECK-LABEL: LV: Checking a loop in 'outer_no_tc'
9+
; CHECK: Calculating cost of runtime checks:
10+
; CHECK: Total cost of runtime checks: 6
11+
; CHECK-NEXT: LV: Minimum required TC for runtime checks to be profitable:16
12+
entry:
13+
br label %outer.loop
14+
15+
outer.loop:
16+
%outer.iv = phi i64 [ %outer.iv.next, %inner.exit ], [ 0, %entry ]
17+
%mul.us = mul nsw i64 %outer.iv, %n
18+
br label %inner.loop
19+
20+
inner.loop:
21+
%inner.iv = phi i64 [ 0, %outer.loop ], [ %inner.iv.next, %inner.loop ]
22+
%add.us = add nuw nsw i64 %inner.iv, %mul.us
23+
%arrayidx.us = getelementptr inbounds i8, ptr %b, i64 %add.us
24+
%0 = load i8, ptr %arrayidx.us, align 1
25+
%arrayidx7.us = getelementptr inbounds i8, ptr %a, i64 %add.us
26+
%1 = load i8, ptr %arrayidx7.us, align 1
27+
%add9.us = add i8 %1, %0
28+
store i8 %add9.us, ptr %arrayidx7.us, align 1
29+
%inner.iv.next = add nuw nsw i64 %inner.iv, 1
30+
%exitcond.not = icmp eq i64 %inner.iv.next, %n
31+
br i1 %exitcond.not, label %inner.exit, label %inner.loop
32+
33+
inner.exit:
34+
%outer.iv.next = add nuw nsw i64 %outer.iv, 1
35+
%exitcond27.not = icmp eq i64 %outer.iv.next, %m
36+
br i1 %exitcond27.not, label %outer.exit, label %outer.loop
37+
38+
outer.exit:
39+
ret void
40+
}
41+
42+
43+
define void @outer_known_tc3(ptr nocapture noundef %a, ptr nocapture noundef readonly %b, i64 noundef %n) {
44+
; CHECK-LABEL: LV: Checking a loop in 'outer_known_tc3'
45+
; CHECK: Calculating cost of runtime checks:
46+
; CHECK: Total cost of runtime checks: 6
47+
; CHECK-NEXT: LV: Minimum required TC for runtime checks to be profitable:16
48+
entry:
49+
br label %outer.loop
50+
51+
outer.loop:
52+
%outer.iv = phi i64 [ %outer.iv.next, %inner.exit ], [ 0, %entry ]
53+
%mul.us = mul nsw i64 %outer.iv, %n
54+
br label %inner.loop
55+
56+
inner.loop:
57+
%inner.iv = phi i64 [ 0, %outer.loop ], [ %inner.iv.next, %inner.loop ]
58+
%add.us = add nuw nsw i64 %inner.iv, %mul.us
59+
%arrayidx.us = getelementptr inbounds i8, ptr %b, i64 %add.us
60+
%0 = load i8, ptr %arrayidx.us, align 1
61+
%arrayidx7.us = getelementptr inbounds i8, ptr %a, i64 %add.us
62+
%1 = load i8, ptr %arrayidx7.us, align 1
63+
%add9.us = add i8 %1, %0
64+
store i8 %add9.us, ptr %arrayidx7.us, align 1
65+
%inner.iv.next = add nuw nsw i64 %inner.iv, 1
66+
%exitcond.not = icmp eq i64 %inner.iv.next, %n
67+
br i1 %exitcond.not, label %inner.exit, label %inner.loop
68+
69+
inner.exit:
70+
%outer.iv.next = add nuw nsw i64 %outer.iv, 1
71+
%exitcond26.not = icmp eq i64 %outer.iv.next, 3
72+
br i1 %exitcond26.not, label %outer.exit, label %outer.loop
73+
74+
outer.exit:
75+
ret void
76+
}
77+
78+
79+
define void @outer_known_tc64(ptr nocapture noundef %a, ptr nocapture noundef readonly %b, i64 noundef %n) {
80+
; CHECK-LABEL: LV: Checking a loop in 'outer_known_tc64'
81+
; CHECK: Calculating cost of runtime checks:
82+
; CHECK: Total cost of runtime checks: 6
83+
; CHECK-NEXT: LV: Minimum required TC for runtime checks to be profitable:16
84+
entry:
85+
br label %outer.loop
86+
87+
outer.loop:
88+
%outer.iv = phi i64 [ %outer.iv.next, %inner.exit ], [ 0, %entry ]
89+
%mul.us = mul nsw i64 %outer.iv, %n
90+
br label %inner.loop
91+
92+
inner.loop:
93+
%inner.iv = phi i64 [ 0, %outer.loop ], [ %inner.iv.next, %inner.loop ]
94+
%add.us = add nuw nsw i64 %inner.iv, %mul.us
95+
%arrayidx.us = getelementptr inbounds i8, ptr %b, i64 %add.us
96+
%0 = load i8, ptr %arrayidx.us, align 1
97+
%arrayidx7.us = getelementptr inbounds i8, ptr %a, i64 %add.us
98+
%1 = load i8, ptr %arrayidx7.us, align 1
99+
%add9.us = add i8 %1, %0
100+
store i8 %add9.us, ptr %arrayidx7.us, align 1
101+
%inner.iv.next = add nuw nsw i64 %inner.iv, 1
102+
%exitcond.not = icmp eq i64 %inner.iv.next, %n
103+
br i1 %exitcond.not, label %inner.exit, label %inner.loop
104+
105+
inner.exit:
106+
%outer.iv.next = add nuw nsw i64 %outer.iv, 1
107+
%exitcond26.not = icmp eq i64 %outer.iv.next, 64
108+
br i1 %exitcond26.not, label %outer.exit, label %outer.loop
109+
110+
outer.exit:
111+
ret void
112+
}
113+
114+
115+
define void @outer_pgo_3(ptr nocapture noundef %a, ptr nocapture noundef readonly %b, i64 noundef %m, i64 noundef %n) {
116+
; CHECK-LABEL: LV: Checking a loop in 'outer_pgo_3'
117+
; CHECK: Calculating cost of runtime checks:
118+
; CHECK: Total cost of runtime checks: 6
119+
; CHECK-NEXT: LV: Minimum required TC for runtime checks to be profitable:16
120+
entry:
121+
br label %outer.loop
122+
123+
outer.loop:
124+
%outer.iv = phi i64 [ %outer.iv.next, %inner.exit ], [ 0, %entry ]
125+
%mul.us = mul nsw i64 %outer.iv, %n
126+
br label %inner.loop
127+
128+
inner.loop:
129+
%inner.iv = phi i64 [ 0, %outer.loop ], [ %inner.iv.next, %inner.loop ]
130+
%add.us = add nuw nsw i64 %inner.iv, %mul.us
131+
%arrayidx.us = getelementptr inbounds i8, ptr %b, i64 %add.us
132+
%0 = load i8, ptr %arrayidx.us, align 1
133+
%arrayidx7.us = getelementptr inbounds i8, ptr %a, i64 %add.us
134+
%1 = load i8, ptr %arrayidx7.us, align 1
135+
%add9.us = add i8 %1, %0
136+
store i8 %add9.us, ptr %arrayidx7.us, align 1
137+
%inner.iv.next = add nuw nsw i64 %inner.iv, 1
138+
%exitcond.not = icmp eq i64 %inner.iv.next, %n
139+
br i1 %exitcond.not, label %inner.exit, label %inner.loop
140+
141+
inner.exit:
142+
%outer.iv.next = add nuw nsw i64 %outer.iv, 1
143+
%exitcond26.not = icmp eq i64 %outer.iv.next, %m
144+
br i1 %exitcond26.not, label %outer.exit, label %outer.loop, !prof !0
145+
146+
outer.exit:
147+
ret void
148+
}
149+
150+
151+
define void @outer_known_tc3_full_range_checks(ptr nocapture noundef %dst, ptr nocapture noundef readonly %src, i64 noundef %n) {
152+
; CHECK-LABEL: LV: Checking a loop in 'outer_known_tc3_full_range_checks'
153+
; CHECK: Calculating cost of runtime checks:
154+
; CHECK: Total cost of runtime checks: 6
155+
; CHECK-NEXT: LV: Minimum required TC for runtime checks to be profitable:8
156+
entry:
157+
br label %outer.loop
158+
159+
outer.loop:
160+
%outer.iv = phi i64 [ 0, %entry ], [ %outer.iv.next, %inner.exit ]
161+
%0 = mul nsw i64 %outer.iv, %n
162+
br label %inner.loop
163+
164+
inner.loop:
165+
%iv.inner = phi i64 [ 0, %outer.loop ], [ %iv.inner.next, %inner.loop ]
166+
%1 = add nuw nsw i64 %iv.inner, %0
167+
%arrayidx.us = getelementptr inbounds i32, ptr %src, i64 %1
168+
%2 = load i32, ptr %arrayidx.us, align 4
169+
%arrayidx8.us = getelementptr inbounds i32, ptr %dst, i64 %1
170+
%3 = load i32, ptr %arrayidx8.us, align 4
171+
%add9.us = add nsw i32 %3, %2
172+
store i32 %add9.us, ptr %arrayidx8.us, align 4
173+
%iv.inner.next = add nuw nsw i64 %iv.inner, 1
174+
%inner.exit.cond = icmp eq i64 %iv.inner.next, %n
175+
br i1 %inner.exit.cond, label %inner.exit, label %inner.loop
176+
177+
inner.exit:
178+
%outer.iv.next = add nuw nsw i64 %outer.iv, 1
179+
%outer.exit.cond = icmp eq i64 %outer.iv.next, 3
180+
br i1 %outer.exit.cond, label %outer.exit, label %outer.loop
181+
182+
outer.exit:
183+
ret void
184+
}
185+
186+
187+
!0 = !{!"branch_weights", i32 10, i32 20}

0 commit comments

Comments
 (0)