1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Verify that strlen calls with elements of constant arrays are folded.
4 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
6 declare i64 @strlen(ptr)
8 @a5_4 = constant [5 x [4 x i8]] [[4 x i8] c"123\00", [4 x i8] c"12\00\00", [4 x i8] c"1\00\00\00", [4 x i8] zeroinitializer, [4 x i8] zeroinitializer]
11 ; Fold strlen(a5_4[0]) to 3.
13 define i64 @fold_a5_4_i0_to_3() {
14 ; CHECK-LABEL: @fold_a5_4_i0_to_3(
15 ; CHECK-NEXT: ret i64 3
17 %len = call i64 @strlen(ptr @a5_4)
22 ; Fold strlen(&a5_4[0][1]) to 2.
24 define i64 @fold_a5_4_i0_p1_to_2() {
25 ; CHECK-LABEL: @fold_a5_4_i0_p1_to_2(
26 ; CHECK-NEXT: ret i64 2
28 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 0, i64 1
29 %len = call i64 @strlen(ptr %ptr)
34 ; Fold strlen(&a5_4[0][2]) to 1.
36 define i64 @fold_a5_4_i0_p2_to_1() {
37 ; CHECK-LABEL: @fold_a5_4_i0_p2_to_1(
38 ; CHECK-NEXT: ret i64 1
40 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 0, i64 2
41 %len = call i64 @strlen(ptr %ptr)
46 ; Fold strlen(&a5_4[0][3]) to 0.
48 define i64 @fold_a5_4_i0_p3_to_0() {
49 ; CHECK-LABEL: @fold_a5_4_i0_p3_to_0(
50 ; CHECK-NEXT: ret i64 0
52 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 0, i64 3
53 %len = call i64 @strlen(ptr %ptr)
58 ; Fold strlen(a5_4[1]) to 2.
60 define i64 @fold_a5_4_i1_to_2() {
61 ; CHECK-LABEL: @fold_a5_4_i1_to_2(
62 ; CHECK-NEXT: ret i64 2
64 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 1, i64 0
65 %len = call i64 @strlen(ptr %ptr)
70 ; Fold strlen(&a5_4[1][1]) to 1.
72 define i64 @fold_a5_4_i1_p1_to_1() {
73 ; CHECK-LABEL: @fold_a5_4_i1_p1_to_1(
74 ; CHECK-NEXT: ret i64 1
76 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 1, i64 1
77 %len = call i64 @strlen(ptr %ptr)
82 ; Fold strlen(&a5_4[1][2]) to 0.
84 define i64 @fold_a5_4_i1_p2_to_0() {
85 ; CHECK-LABEL: @fold_a5_4_i1_p2_to_0(
86 ; CHECK-NEXT: ret i64 0
88 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 1, i64 2
89 %len = call i64 @strlen(ptr %ptr)
94 ; Fold strlen(&a5_4[1][3]) to 0.
96 define i64 @fold_a5_4_i1_p3_to_0() {
97 ; CHECK-LABEL: @fold_a5_4_i1_p3_to_0(
98 ; CHECK-NEXT: ret i64 0
100 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 1, i64 3
101 %len = call i64 @strlen(ptr %ptr)
106 ; Fold strlen(a5_4[2]) to 1.
108 define i64 @fold_a5_4_i2_to_1() {
109 ; CHECK-LABEL: @fold_a5_4_i2_to_1(
110 ; CHECK-NEXT: ret i64 1
112 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 2, i64 0
113 %len = call i64 @strlen(ptr %ptr)
118 ; Fold strlen(&a5_4[2][1]) to 0.
120 define i64 @fold_a5_4_i2_p1_to_0() {
121 ; CHECK-LABEL: @fold_a5_4_i2_p1_to_0(
122 ; CHECK-NEXT: ret i64 0
124 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 2, i64 1
125 %len = call i64 @strlen(ptr %ptr)
130 ; Fold strlen(&a5_4[2][2]) to 0.
132 define i64 @fold_a5_4_i2_p2_to_0() {
133 ; CHECK-LABEL: @fold_a5_4_i2_p2_to_0(
134 ; CHECK-NEXT: ret i64 0
136 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 2, i64 2
137 %len = call i64 @strlen(ptr %ptr)
142 ; Fold strlen(&a5_4[2][3]) to 0.
144 define i64 @fold_a5_4_i2_p3_to_0() {
145 ; CHECK-LABEL: @fold_a5_4_i2_p3_to_0(
146 ; CHECK-NEXT: ret i64 0
148 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 2, i64 3
149 %len = call i64 @strlen(ptr %ptr)
154 ; Fold strlen(a5_4[3]) to 0
156 define i64 @fold_a5_4_i3_to_0() {
157 ; CHECK-LABEL: @fold_a5_4_i3_to_0(
158 ; CHECK-NEXT: ret i64 0
160 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 3, i64 0
161 %len = call i64 @strlen(ptr %ptr)
166 ; Fold strlen(&a5_4[3][1]) to 0
168 define i64 @fold_a5_4_i3_p1_to_0() {
169 ; CHECK-LABEL: @fold_a5_4_i3_p1_to_0(
170 ; CHECK-NEXT: ret i64 0
172 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 3, i64 1
173 %len = call i64 @strlen(ptr %ptr)
178 ; Fold strlen(&a5_4[3][2]) to 0
180 define i64 @fold_a5_4_i3_p2_to_0() {
181 ; CHECK-LABEL: @fold_a5_4_i3_p2_to_0(
182 ; CHECK-NEXT: ret i64 0
184 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 3, i64 2
185 %len = call i64 @strlen(ptr %ptr)
190 ; Fold strlen(&a5_4[3][3]) to 0
192 define i64 @fold_a5_3_i4_p3_to_0() {
193 ; CHECK-LABEL: @fold_a5_3_i4_p3_to_0(
194 ; CHECK-NEXT: ret i64 0
196 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 3, i64 3
197 %len = call i64 @strlen(ptr %ptr)
202 ; Fold strlen(a5_4[4]) to 0
204 define i64 @fold_a5_4_i4_to_0() {
205 ; CHECK-LABEL: @fold_a5_4_i4_to_0(
206 ; CHECK-NEXT: ret i64 0
208 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 4, i64 0
209 %len = call i64 @strlen(ptr %ptr)
214 ; Fold strlen(&a5_4[4][1]) to 0
216 define i64 @fold_a5_4_i4_p1_to_0() {
217 ; CHECK-LABEL: @fold_a5_4_i4_p1_to_0(
218 ; CHECK-NEXT: ret i64 0
220 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 4, i64 1
221 %len = call i64 @strlen(ptr %ptr)
226 ; Fold strlen(&a5_4[4][2]) to 0
228 define i64 @fold_a5_4_i4_p2_to_0() {
229 ; CHECK-LABEL: @fold_a5_4_i4_p2_to_0(
230 ; CHECK-NEXT: ret i64 0
232 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 4, i64 2
233 %len = call i64 @strlen(ptr %ptr)
238 ; Fold strlen(&a5_4[4][3]) to 0
240 define i64 @fold_a5_4_i4_p3_to_0() {
241 ; CHECK-LABEL: @fold_a5_4_i4_p3_to_0(
242 ; CHECK-NEXT: ret i64 0
244 %ptr = getelementptr [5 x [4 x i8]], ptr @a5_4, i64 0, i64 4, i64 3
245 %len = call i64 @strlen(ptr %ptr)