1 ; Test that memcmp won't be converted to CLC if calls are
2 ; marked with nobuiltin, eg. for sanitizers.
4 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
6 declare signext i32 @memcmp(i8 *%src1, i8 *%src2, i64 %size)
8 ; Zero-length comparisons should be optimized away.
9 define i32 @f1(i8 *%src1, i8 *%src2) {
12 ; CHECK: brasl %r14, memcmp
14 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 0) nobuiltin
18 ; Check a case where the result is used as an integer.
19 define i32 @f2(i8 *%src1, i8 *%src2) {
22 ; CHECK: brasl %r14, memcmp
24 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 2) nobuiltin
28 ; Check a case where the result is tested for equality.
29 define void @f3(i8 *%src1, i8 *%src2, i32 *%dest) {
32 ; CHECK: brasl %r14, memcmp
34 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 3) nobuiltin
35 %cmp = icmp eq i32 %res, 0
36 br i1 %cmp, label %exit, label %store
39 store i32 0, i32 *%dest
46 ; Check a case where the result is tested for inequality.
47 define void @f4(i8 *%src1, i8 *%src2, i32 *%dest) {
50 ; CHECK: brasl %r14, memcmp
53 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 4) nobuiltin
54 %cmp = icmp ne i32 %res, 0
55 br i1 %cmp, label %exit, label %store
58 store i32 0, i32 *%dest
65 ; Check a case where the result is tested via slt.
66 define void @f5(i8 *%src1, i8 *%src2, i32 *%dest) {
69 ; CHECK: brasl %r14, memcmp
72 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 5) nobuiltin
73 %cmp = icmp slt i32 %res, 0
74 br i1 %cmp, label %exit, label %store
77 store i32 0, i32 *%dest
84 ; Check a case where the result is tested for sgt.
85 define void @f6(i8 *%src1, i8 *%src2, i32 *%dest) {
88 ; CHECK: brasl %r14, memcmp
91 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 6) nobuiltin
92 %cmp = icmp sgt i32 %res, 0
93 br i1 %cmp, label %exit, label %store
96 store i32 0, i32 *%dest
103 ; Check the upper end of the CLC range. Here the result is used both as
104 ; an integer and for branching.
105 define i32 @f7(i8 *%src1, i8 *%src2, i32 *%dest) {
108 ; CHECK: brasl %r14, memcmp
111 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 256) nobuiltin
112 %cmp = icmp slt i32 %res, 0
113 br i1 %cmp, label %exit, label %store
116 store i32 0, i32 *%dest
123 ; 257 bytes needs two CLCs.
124 define i32 @f8(i8 *%src1, i8 *%src2) {
127 ; CHECK: brasl %r14, memcmp
129 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 257) nobuiltin
133 ; Test a comparison of 258 bytes in which the CC result can be used directly.
134 define void @f9(i8 *%src1, i8 *%src2, i32 *%dest) {
137 ; CHECK: brasl %r14, memcmp
140 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 257) nobuiltin
141 %cmp = icmp slt i32 %res, 0
142 br i1 %cmp, label %exit, label %store
145 store i32 0, i32 *%dest
152 ; Test the largest size that can use two CLCs.
153 define i32 @f10(i8 *%src1, i8 *%src2) {
156 ; CHECK: brasl %r14, memcmp
158 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 512) nobuiltin
162 ; Test the smallest size that needs 3 CLCs.
163 define i32 @f11(i8 *%src1, i8 *%src2) {
166 ; CHECK: brasl %r14, memcmp
168 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 513) nobuiltin
172 ; Test the largest size than can use 3 CLCs.
173 define i32 @f12(i8 *%src1, i8 *%src2) {
176 ; CHECK: brasl %r14, memcmp
178 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 768) nobuiltin
182 ; The next size up uses a loop instead. We leave the more complicated
183 ; loop tests to memcpy-01.ll, which shares the same form.
184 define i32 @f13(i8 *%src1, i8 *%src2) {
187 ; CHECK: brasl %r14, memcmp
189 %res = call i32 @memcmp(i8 *%src1, i8 *%src2, i64 769) nobuiltin