xref: /llvm-project/llvm/test/Transforms/InstCombine/strspn-1.ll (revision 4ab40eca080965c65802710e39adbb78c4ce7bde)
1; Test that the strspn library call simplifier works correctly.
2;
3; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4
5@abcba = constant [6 x i8] c"abcba\00"
6@abc = constant [4 x i8] c"abc\00"
7@null = constant [1 x i8] zeroinitializer
8
9declare i64 @strspn(ptr, ptr)
10
11; Check strspn(s, "") -> 0.
12
13define i64 @test_simplify1(ptr %str) {
14; CHECK-LABEL: @test_simplify1(
15
16  %ret = call i64 @strspn(ptr %str, ptr @null)
17  ret i64 %ret
18; CHECK-NEXT: ret i64 0
19}
20
21; Check strspn("", s) -> 0.
22
23define i64 @test_simplify2(ptr %pat) {
24; CHECK-LABEL: @test_simplify2(
25
26  %ret = call i64 @strspn(ptr @null, ptr %pat)
27  ret i64 %ret
28; CHECK-NEXT: ret i64 0
29}
30
31; Check strspn(s1, s2), where s1 and s2 are constants.
32
33define i64 @test_simplify3() {
34; CHECK-LABEL: @test_simplify3(
35
36  %ret = call i64 @strspn(ptr @abcba, ptr @abc)
37  ret i64 %ret
38; CHECK-NEXT: ret i64 5
39}
40
41; Check cases that shouldn't be simplified.
42
43define i64 @test_no_simplify1(ptr %str, ptr %pat) {
44; CHECK-LABEL: @test_no_simplify1(
45
46  %ret = call i64 @strspn(ptr %str, ptr %pat)
47; CHECK-NEXT: %ret = call i64 @strspn(ptr %str, ptr %pat)
48  ret i64 %ret
49; CHECK-NEXT: ret i64 %ret
50}
51