File: strncmp-2.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 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 (147 lines) | stat: -rw-r--r-- 4,428 bytes parent folder | download | duplicates (7)
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
; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=3 < %s | FileCheck --check-prefixes=CHECK,TH-3 %s
; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=2 < %s | FileCheck --check-prefixes=CHECK,TH-2 %s
; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=1 < %s | FileCheck --check-prefixes=CHECK,TH-1 %s
; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=0 < %s | FileCheck --check-prefixes=CHECK,TH-0 %s

declare i32 @strcmp(ptr nocapture, ptr nocapture)
declare i32 @strncmp(ptr nocapture, ptr nocapture, i64)

@s1 = constant [1 x i8] c"\00", align 1
@s2n = constant [2 x i8] c"aa", align 1
@s3 = constant [3 x i8] c"aa\00", align 1
@s4 = constant [4 x i8] c"aab\00", align 1

; strncmp(s, "aa", 1)
define i1 @test_strncmp_0(ptr %s) {
entry:
  %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3, i64 1)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strncmp_0(
; CHECK: @strncmp

; strncmp(s, "aa", 2)
define i1 @test_strncmp_1(ptr %s) {
entry:
  %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3, i64 2)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strncmp_1(
; TH-3-NOT: @strncmp
; TH-2-NOT: @strncmp
; TH-1: @strncmp
; TH-0: @strncmp

define i1 @test_strncmp_1_dereferenceable(ptr dereferenceable(2) %s) {
entry:
  %call = tail call i32 @strncmp(ptr nonnull %s, ptr nonnull dereferenceable(3) @s3, i64 2)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strncmp_1_dereferenceable(
; CHECK: @strncmp

define i32 @test_strncmp_1_not_comparision(ptr %s) {
entry:
  %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3, i64 2)
  ret i32 %call
}
; CHECK-LABEL: @test_strncmp_1_not_comparision(
; CHECK: @strncmp

; strncmp(s, "aa", 3)
define i1 @test_strncmp_2(ptr %s) {
entry:
  %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3, i64 3)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strncmp_2(
; TH-3-NOT: @strncmp
; TH-2: @strncmp
; TH-1: @strncmp
; TH-0: @strncmp

; strncmp(s, "aab", 3)
define i1 @test_strncmp_3(ptr %s) {
entry:
  %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(4) @s4, i64 3)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strncmp_3(
; TH-3-NOT: @strncmp

; strncmp(s, "aab", 4)
define i1 @test_strncmp_4(ptr %s) {
entry:
  %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(4) @s4, i64 4)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strncmp_4(
; TH-3: @strncmp

; strncmp(s, "aa", 2)
define i1 @test_strncmp_5(ptr %s) {
entry:
  %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3, i64 2)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strncmp_5(
; TH-3-NOT: @strncmp

; char s2[] = {'a', 'a'}
; strncmp(s1, s2, 2)
define i1 @test_strncmp_6(ptr %s1) {
entry:
  %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s1, ptr nonnull dereferenceable(2) @s2n, i64 2)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strncmp_6(
; TH-3-NOT: @strncmp

; char s2[] = {'a', 'a'}
; strncmp(s, s2, 3)
define i1 @test_strncmp_7(ptr %s) {
entry:
  %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(2) @s2n, i64 3)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strncmp_7(
; CHECK: @strncmp

; strcmp(s, "")
define i1 @test_strcmp_0(ptr %s) {
entry:
  %call = tail call i32 @strcmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(1) @s1)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strcmp_0(
; CHECK: @strcmp

; strcmp(s, "aa")
define i1 @test_strcmp_1(ptr %s) {
entry:
  %call = tail call i32 @strcmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strcmp_1(
; TH-3-NOT: @strcmp

; strcmp(s, "aab")
define i1 @test_strcmp_2(ptr %s) {
entry:
  %call = tail call i32 @strcmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(4) @s4)
  %cmp = icmp eq i32 %call, 0
  ret i1 %cmp
}
; CHECK-LABEL: @test_strcmp_2(
; TH-3: @strcmp