File: runtime-check-size-based-threshold.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 1,998,492 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (171 lines) | stat: -rw-r--r-- 6,634 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
; RUN: opt -passes=loop-vectorize -mtriple=arm64-apple-iphoneos -vectorizer-min-trip-count=8 \
; RUN:   -enable-epilogue-vectorization=false -S %s | FileCheck --check-prefixes=CHECK,DEFAULT %s
; RUN: opt -passes=loop-vectorize -mtriple=arm64-apple-iphoneos -vectorizer-min-trip-count=8 \
; RUN:   -enable-epilogue-vectorization=false -vectorize-memory-check-threshold=1 -S %s | FileCheck --check-prefixes=CHECK,THRESHOLD %s

; Tests for loops with large numbers of runtime checks. Check that loops are
; vectorized, if the loop trip counts are large and the impact of the runtime
; checks is very small compared to the expected loop runtimes.


; The trip count in the loop in this function is too to warrant large runtime checks.
; CHECK-LABEL: define {{.*}} @test_tc_too_small
; CHECK-NOT: vector.memcheck
; CHECK-NOT: vector.body
define void @test_tc_too_small(ptr %ptr.1, ptr %ptr.2, ptr %ptr.3, ptr %ptr.4, i64 %off.1, i64 %off.2) {
entry:
  br label %loop

loop:                                             ; preds = %bb54, %bb37
  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
  %gep.1 = getelementptr inbounds i16, ptr %ptr.1, i64 %iv
  %lv.1 = load i16, ptr %gep.1, align 2
  %ext.1 = sext i16 %lv.1 to i32
  %gep.2 = getelementptr inbounds i16, ptr %ptr.2, i64 %iv
  %lv.2 = load i16, ptr %gep.2, align 2
  %ext.2 = sext i16 %lv.2 to i32
  %gep.off.1 = getelementptr inbounds i16, ptr %gep.2, i64 %off.1
  %lv.3 = load i16, ptr %gep.off.1, align 2
  %ext.3 = sext i16 %lv.3 to i32
  %gep.off.2 = getelementptr inbounds i16, ptr %gep.2, i64 %off.2
  %lv.4 = load i16, ptr %gep.off.2, align 2
  %ext.4 = sext i16 %lv.4 to i32
  %tmp62 = mul nsw i32 %ext.2, 11
  %tmp66 = mul nsw i32 %ext.3, -4
  %tmp70 = add nsw i32 %tmp62, 4
  %tmp71 = add nsw i32 %tmp70, %tmp66
  %tmp72 = add nsw i32 %tmp71, %ext.4
  %tmp73 = lshr i32 %tmp72, 3
  %tmp74 = add nsw i32 %tmp73, %ext.1
  %tmp75 = lshr i32 %tmp74, 1
  %tmp76 = mul nsw i32 %ext.2, 5
  %tmp77 = shl nsw i32 %ext.3, 2
  %tmp78 = add nsw i32 %tmp76, 4
  %tmp79 = add nsw i32 %tmp78, %tmp77
  %tmp80 = sub nsw i32 %tmp79, %ext.4
  %tmp81 = lshr i32 %tmp80, 3
  %tmp82 = sub nsw i32 %tmp81, %ext.1
  %tmp83 = lshr i32 %tmp82, 1
  %trunc.1 = trunc i32 %tmp75 to i16
  %gep.3 = getelementptr inbounds i16, ptr %ptr.3, i64 %iv
  store i16 %trunc.1, ptr %gep.3, align 2
  %trunc.2 = trunc i32 %tmp83 to i16
  %gep.4 = getelementptr inbounds i16, ptr %ptr.4, i64 %iv
  store i16 %trunc.2, ptr %gep.4, align 2
  %iv.next = add nuw nsw i64 %iv, 1
  %cmp = icmp ult i64 %iv, 10
  br i1 %cmp, label %loop, label %exit

exit:
  ret void
}

; The trip count in the loop in this function high enough to warrant large runtime checks.
; CHECK-LABEL: define {{.*}} @test_tc_big_enough
; DEFAULT: vector.memcheck
; DEFAULT: vector.body
; THRESHOLD-NOT: vector.memcheck
; THRESHOLD-NOT: vector.body
;
define void @test_tc_big_enough(ptr %ptr.1, ptr %ptr.2, ptr %ptr.3, ptr %ptr.4, i64 %off.1, i64 %off.2) {
entry:
  br label %loop

loop:                                             ; preds = %bb54, %bb37
  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
  %gep.1 = getelementptr inbounds i16, ptr %ptr.1, i64 %iv
  %lv.1 = load i16, ptr %gep.1, align 2
  %ext.1 = sext i16 %lv.1 to i32
  %gep.2 = getelementptr inbounds i16, ptr %ptr.2, i64 %iv
  %lv.2 = load i16, ptr %gep.2, align 2
  %ext.2 = sext i16 %lv.2 to i32
  %gep.off.1 = getelementptr inbounds i16, ptr %gep.2, i64 %off.1
  %lv.3 = load i16, ptr %gep.off.1, align 2
  %ext.3 = sext i16 %lv.3 to i32
  %gep.off.2 = getelementptr inbounds i16, ptr %gep.2, i64 %off.2
  %lv.4 = load i16, ptr %gep.off.2, align 2
  %ext.4 = sext i16 %lv.4 to i32
  %tmp62 = mul nsw i32 %ext.2, 11
  %tmp66 = mul nsw i32 %ext.3, -4
  %tmp70 = add nsw i32 %tmp62, 4
  %tmp71 = add nsw i32 %tmp70, %tmp66
  %tmp72 = add nsw i32 %tmp71, %ext.4
  %tmp73 = lshr i32 %tmp72, 3
  %tmp74 = add nsw i32 %tmp73, %ext.1
  %tmp75 = lshr i32 %tmp74, 1
  %tmp76 = mul nsw i32 %ext.2, 5
  %tmp77 = shl nsw i32 %ext.3, 2
  %tmp78 = add nsw i32 %tmp76, 4
  %tmp79 = add nsw i32 %tmp78, %tmp77
  %tmp80 = sub nsw i32 %tmp79, %ext.4
  %tmp81 = lshr i32 %tmp80, 3
  %tmp82 = sub nsw i32 %tmp81, %ext.1
  %tmp83 = lshr i32 %tmp82, 1
  %trunc.1 = trunc i32 %tmp75 to i16
  %gep.3 = getelementptr inbounds i16, ptr %ptr.3, i64 %iv
  store i16 %trunc.1, ptr %gep.3, align 2
  %trunc.2 = trunc i32 %tmp83 to i16
  %gep.4 = getelementptr inbounds i16, ptr %ptr.4, i64 %iv
  store i16 %trunc.2, ptr %gep.4, align 2
  %iv.next = add nuw nsw i64 %iv, 1
  %cmp = icmp ult i64 %iv, 500
  br i1 %cmp, label %loop, label %exit

exit:
  ret void
}

define void @test_tc_unknown(ptr %ptr.1, ptr %ptr.2, ptr %ptr.3, ptr %ptr.4, i64 %off.1, i64 %off.2, i64 %N) {
; CHECK-LABEL: define void @test_tc_unknown
; DEFAULT:       [[ADD:%.+]] = add i64 %N, 1
; DEFAULT-NEXT:  [[C:%.+]] = icmp ult i64 [[ADD]], 16
; DEFAULT-NEXT:  br i1 [[C]], label %scalar.ph, label %vector.memcheck
; THRESHOLD-NOT: vector.memcheck
; THRESHOLD-NOT: vector.body
;
entry:
  br label %loop

loop:                                             ; preds = %bb54, %bb37
  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
  %gep.1 = getelementptr inbounds i16, ptr %ptr.1, i64 %iv
  %lv.1 = load i16, ptr %gep.1, align 2
  %ext.1 = sext i16 %lv.1 to i32
  %gep.2 = getelementptr inbounds i16, ptr %ptr.2, i64 %iv
  %lv.2 = load i16, ptr %gep.2, align 2
  %ext.2 = sext i16 %lv.2 to i32
  %gep.off.1 = getelementptr inbounds i16, ptr %gep.2, i64 %off.1
  %lv.3 = load i16, ptr %gep.off.1, align 2
  %ext.3 = sext i16 %lv.3 to i32
  %gep.off.2 = getelementptr inbounds i16, ptr %gep.2, i64 %off.2
  %lv.4 = load i16, ptr %gep.off.2, align 2
  %ext.4 = sext i16 %lv.4 to i32
  %tmp62 = mul nsw i32 %ext.2, 11
  %tmp66 = mul nsw i32 %ext.3, -4
  %tmp70 = add nsw i32 %tmp62, 4
  %tmp71 = add nsw i32 %tmp70, %tmp66
  %tmp72 = add nsw i32 %tmp71, %ext.4
  %tmp73 = lshr i32 %tmp72, 3
  %tmp74 = add nsw i32 %tmp73, %ext.1
  %tmp75 = lshr i32 %tmp74, 1
  %tmp76 = mul nsw i32 %ext.2, 5
  %tmp77 = shl nsw i32 %ext.3, 2
  %tmp78 = add nsw i32 %tmp76, 4
  %tmp79 = add nsw i32 %tmp78, %tmp77
  %tmp80 = sub nsw i32 %tmp79, %ext.4
  %tmp81 = lshr i32 %tmp80, 3
  %tmp82 = sub nsw i32 %tmp81, %ext.1
  %tmp83 = lshr i32 %tmp82, 1
  %trunc.1 = trunc i32 %tmp75 to i16
  %gep.3 = getelementptr inbounds i16, ptr %ptr.3, i64 %iv
  store i16 %trunc.1, ptr %gep.3, align 2
  %trunc.2 = trunc i32 %tmp83 to i16
  %gep.4 = getelementptr inbounds i16, ptr %ptr.4, i64 %iv
  store i16 %trunc.2, ptr %gep.4, align 2
  %iv.next = add nuw nsw i64 %iv, 1
  %cmp = icmp ult i64 %iv, %N
  br i1 %cmp, label %loop, label %exit

exit:
  ret void
}