1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; Verify that strlen calls with elements of constant arrays are folded. 3; 4; RUN: opt < %s -passes=instcombine -S | FileCheck %s 5 6declare i64 @strlen(i8*) 7 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] 9 10 11; Fold strlen(a5_4[0]) to 3. 12 13define i64 @fold_a5_4_i0_to_3() { 14; CHECK-LABEL: @fold_a5_4_i0_to_3( 15; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 0, i64 0)) 16; CHECK-NEXT: ret i64 [[LEN]] 17; 18 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 0, i64 0 19 %len = call i64 @strlen(i8* %ptr) 20 ret i64 %len 21} 22 23 24; Fold strlen(&a5_4[0][1]) to 2. 25 26define i64 @fold_a5_4_i0_p1_to_2() { 27; CHECK-LABEL: @fold_a5_4_i0_p1_to_2( 28; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 0, i64 1)) 29; CHECK-NEXT: ret i64 [[LEN]] 30; 31 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 0, i64 1 32 %len = call i64 @strlen(i8* %ptr) 33 ret i64 %len 34} 35 36 37; Fold strlen(&a5_4[0][2]) to 1. 38 39define i64 @fold_a5_4_i0_p2_to_1() { 40; CHECK-LABEL: @fold_a5_4_i0_p2_to_1( 41; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 0, i64 2)) 42; CHECK-NEXT: ret i64 [[LEN]] 43; 44 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 0, i64 2 45 %len = call i64 @strlen(i8* %ptr) 46 ret i64 %len 47} 48 49 50; Fold strlen(&a5_4[0][3]) to 0. 51 52define i64 @fold_a5_4_i0_p3_to_0() { 53; CHECK-LABEL: @fold_a5_4_i0_p3_to_0( 54; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 0, i64 3)) 55; CHECK-NEXT: ret i64 [[LEN]] 56; 57 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 0, i64 3 58 %len = call i64 @strlen(i8* %ptr) 59 ret i64 %len 60} 61 62 63; Fold strlen(a5_4[1]) to 2. 64 65define i64 @fold_a5_4_i1_to_2() { 66; CHECK-LABEL: @fold_a5_4_i1_to_2( 67; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 1, i64 0)) 68; CHECK-NEXT: ret i64 [[LEN]] 69; 70 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 1, i64 0 71 %len = call i64 @strlen(i8* %ptr) 72 ret i64 %len 73} 74 75 76; Fold strlen(&a5_4[1][1]) to 1. 77 78define i64 @fold_a5_4_i1_p1_to_1() { 79; CHECK-LABEL: @fold_a5_4_i1_p1_to_1( 80; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 1, i64 1)) 81; CHECK-NEXT: ret i64 [[LEN]] 82; 83 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 1, i64 1 84 %len = call i64 @strlen(i8* %ptr) 85 ret i64 %len 86} 87 88 89; Fold strlen(&a5_4[1][2]) to 0. 90 91define i64 @fold_a5_4_i1_p2_to_0() { 92; CHECK-LABEL: @fold_a5_4_i1_p2_to_0( 93; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 1, i64 2)) 94; CHECK-NEXT: ret i64 [[LEN]] 95; 96 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 1, i64 2 97 %len = call i64 @strlen(i8* %ptr) 98 ret i64 %len 99} 100 101 102; Fold strlen(&a5_4[1][3]) to 0. 103 104define i64 @fold_a5_4_i1_p3_to_0() { 105; CHECK-LABEL: @fold_a5_4_i1_p3_to_0( 106; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 1, i64 3)) 107; CHECK-NEXT: ret i64 [[LEN]] 108; 109 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 1, i64 3 110 %len = call i64 @strlen(i8* %ptr) 111 ret i64 %len 112} 113 114 115; Fold strlen(a5_4[2]) to 1. 116 117define i64 @fold_a5_4_i2_to_1() { 118; CHECK-LABEL: @fold_a5_4_i2_to_1( 119; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 2, i64 0)) 120; CHECK-NEXT: ret i64 [[LEN]] 121; 122 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 2, i64 0 123 %len = call i64 @strlen(i8* %ptr) 124 ret i64 %len 125} 126 127 128; Fold strlen(&a5_4[2][1]) to 0. 129 130define i64 @fold_a5_4_i2_p1_to_0() { 131; CHECK-LABEL: @fold_a5_4_i2_p1_to_0( 132; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 2, i64 1)) 133; CHECK-NEXT: ret i64 [[LEN]] 134; 135 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 2, i64 1 136 %len = call i64 @strlen(i8* %ptr) 137 ret i64 %len 138} 139 140 141; Fold strlen(&a5_4[2][2]) to 0. 142 143define i64 @fold_a5_4_i2_p2_to_0() { 144; CHECK-LABEL: @fold_a5_4_i2_p2_to_0( 145; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 2, i64 2)) 146; CHECK-NEXT: ret i64 [[LEN]] 147; 148 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 2, i64 2 149 %len = call i64 @strlen(i8* %ptr) 150 ret i64 %len 151} 152 153 154; Fold strlen(&a5_4[2][3]) to 0. 155 156define i64 @fold_a5_4_i2_p3_to_0() { 157; CHECK-LABEL: @fold_a5_4_i2_p3_to_0( 158; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 2, i64 3)) 159; CHECK-NEXT: ret i64 [[LEN]] 160; 161 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 2, i64 3 162 %len = call i64 @strlen(i8* %ptr) 163 ret i64 %len 164} 165 166 167; Fold strlen(a5_4[3]) to 0 168 169define i64 @fold_a5_4_i3_to_0() { 170; CHECK-LABEL: @fold_a5_4_i3_to_0( 171; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 3, i64 0)) 172; CHECK-NEXT: ret i64 [[LEN]] 173; 174 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 3, i64 0 175 %len = call i64 @strlen(i8* %ptr) 176 ret i64 %len 177} 178 179 180; Fold strlen(&a5_4[3][1]) to 0 181 182define i64 @fold_a5_4_i3_p1_to_0() { 183; CHECK-LABEL: @fold_a5_4_i3_p1_to_0( 184; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 3, i64 1)) 185; CHECK-NEXT: ret i64 [[LEN]] 186; 187 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 3, i64 1 188 %len = call i64 @strlen(i8* %ptr) 189 ret i64 %len 190} 191 192 193; Fold strlen(&a5_4[3][2]) to 0 194 195define i64 @fold_a5_4_i3_p2_to_0() { 196; CHECK-LABEL: @fold_a5_4_i3_p2_to_0( 197; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 3, i64 2)) 198; CHECK-NEXT: ret i64 [[LEN]] 199; 200 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 3, i64 2 201 %len = call i64 @strlen(i8* %ptr) 202 ret i64 %len 203} 204 205 206; Fold strlen(&a5_4[3][3]) to 0 207 208define i64 @fold_a5_3_i4_p3_to_0() { 209; CHECK-LABEL: @fold_a5_3_i4_p3_to_0( 210; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 3, i64 3)) 211; CHECK-NEXT: ret i64 [[LEN]] 212; 213 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 3, i64 3 214 %len = call i64 @strlen(i8* %ptr) 215 ret i64 %len 216} 217 218 219; Fold strlen(a5_4[4]) to 0 220 221define i64 @fold_a5_4_i4_to_0() { 222; CHECK-LABEL: @fold_a5_4_i4_to_0( 223; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 4, i64 0)) 224; CHECK-NEXT: ret i64 [[LEN]] 225; 226 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 4, i64 0 227 %len = call i64 @strlen(i8* %ptr) 228 ret i64 %len 229} 230 231 232; Fold strlen(&a5_4[4][1]) to 0 233 234define i64 @fold_a5_4_i4_p1_to_0() { 235; CHECK-LABEL: @fold_a5_4_i4_p1_to_0( 236; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 4, i64 1)) 237; CHECK-NEXT: ret i64 [[LEN]] 238; 239 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 4, i64 1 240 %len = call i64 @strlen(i8* %ptr) 241 ret i64 %len 242} 243 244 245; Fold strlen(&a5_4[4][2]) to 0 246 247define i64 @fold_a5_4_i4_p2_to_0() { 248; CHECK-LABEL: @fold_a5_4_i4_p2_to_0( 249; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 4, i64 2)) 250; CHECK-NEXT: ret i64 [[LEN]] 251; 252 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 4, i64 2 253 %len = call i64 @strlen(i8* %ptr) 254 ret i64 %len 255} 256 257 258; Fold strlen(&a5_4[4][3]) to 0 259 260define i64 @fold_a5_4_i4_p3_to_0() { 261; CHECK-LABEL: @fold_a5_4_i4_p3_to_0( 262; CHECK-NEXT: [[LEN:%.*]] = call i64 @strlen(i8* noundef nonnull dereferenceable(1) getelementptr inbounds ([5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 4, i64 3)) 263; CHECK-NEXT: ret i64 [[LEN]] 264; 265 %ptr = getelementptr [5 x [4 x i8]], [5 x [4 x i8]]* @a5_4, i64 0, i64 4, i64 3 266 %len = call i64 @strlen(i8* %ptr) 267 ret i64 %len 268} 269