72 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; Verify that calls to memcmp with counts in excess of the array sizes are3; either folded gracefully or expanded to library calls.4;5; RUN: opt < %s -passes=instcombine -S -data-layout="E" | FileCheck %s --check-prefixes=BE6; RUN: opt < %s -passes=instcombine -S -data-layout="e" | FileCheck %s --check-prefixes=LE7 8declare i32 @memcmp(ptr, ptr, i64)9 10@ia16a = constant [4 x i16] [i16 24930, i16 25444, i16 25958, i16 26472]11@ia16b = constant [5 x i16] [i16 24930, i16 25444, i16 25958, i16 26472, i16 26992]12@ia16c = constant [6 x i16] [i16 24930, i16 25444, i16 25958, i16 26472, i16 26993, i16 29042]13 14 15; Fold calls with a count in excess of the size of one of the arrays that16; differ. They're strictly undefined but folding the result to the expected17; value (analogous to strncmp) is safer than letting a SIMD library18; implementation return a bogus value.19 20define void @fold_memcmp_mismatch_too_big(ptr %pcmp) {21; BE-LABEL: @fold_memcmp_mismatch_too_big(22; BE-NEXT: store i32 -1, ptr [[PCMP:%.*]], align 423; BE-NEXT: [[PSTOR_CB:%.*]] = getelementptr i8, ptr [[PCMP]], i64 424; BE-NEXT: store i32 1, ptr [[PSTOR_CB]], align 425; BE-NEXT: ret void26;27; LE-LABEL: @fold_memcmp_mismatch_too_big(28; LE-NEXT: store i32 -1, ptr [[PCMP:%.*]], align 429; LE-NEXT: [[PSTOR_CB:%.*]] = getelementptr i8, ptr [[PCMP]], i64 430; LE-NEXT: store i32 1, ptr [[PSTOR_CB]], align 431; LE-NEXT: ret void32;33 34 %cmp_bc = call i32 @memcmp(ptr @ia16b, ptr @ia16c, i64 12)35 store i32 %cmp_bc, ptr %pcmp36 37 %cmp_cb = call i32 @memcmp(ptr @ia16c, ptr @ia16b, i64 12)38 %pstor_cb = getelementptr i32, ptr %pcmp, i64 139 store i32 %cmp_cb, ptr %pstor_cb40 41 ret void42}43 44 45; Fold even calls with excessive byte counts of arrays with matching bytes.46; Like in the instances above, this is preferable to letting the undefined47; calls take place, although it does prevent sanitizers from detecting them.48 49define void @fold_memcmp_match_too_big(ptr %pcmp) {50; BE-LABEL: @fold_memcmp_match_too_big(51; BE-NEXT: store i32 0, ptr [[PCMP:%.*]], align 452; BE-NEXT: [[PSTOR_AB_M1:%.*]] = getelementptr i8, ptr [[PCMP]], i64 453; BE-NEXT: store i32 0, ptr [[PSTOR_AB_M1]], align 454; BE-NEXT: ret void55;56; LE-LABEL: @fold_memcmp_match_too_big(57; LE-NEXT: store i32 0, ptr [[PCMP:%.*]], align 458; LE-NEXT: [[PSTOR_AB_M1:%.*]] = getelementptr i8, ptr [[PCMP]], i64 459; LE-NEXT: store i32 0, ptr [[PSTOR_AB_M1]], align 460; LE-NEXT: ret void61;62 63 %cmp_ab_9 = call i32 @memcmp(ptr @ia16a, ptr @ia16b, i64 9)64 store i32 %cmp_ab_9, ptr %pcmp65 66 %cmp_ab_m1 = call i32 @memcmp(ptr @ia16a, ptr @ia16b, i64 -1)67 %pstor_ab_m1 = getelementptr i32, ptr %pcmp, i64 168 store i32 %cmp_ab_m1, ptr %pstor_ab_m169 70 ret void71}72