1; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=3 < %s | FileCheck --check-prefixes=CHECK,TH-3 %s 2; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=2 < %s | FileCheck --check-prefixes=CHECK,TH-2 %s 3; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=1 < %s | FileCheck --check-prefixes=CHECK,TH-1 %s 4; RUN: opt -S -passes=aggressive-instcombine -strncmp-inline-threshold=0 < %s | FileCheck --check-prefixes=CHECK,TH-0 %s 5 6declare i32 @strcmp(ptr nocapture, ptr nocapture) 7declare i32 @strncmp(ptr nocapture, ptr nocapture, i64) 8 9@s1 = constant [1 x i8] c"\00", align 1 10@s2n = constant [2 x i8] c"aa", align 1 11@s3 = constant [3 x i8] c"aa\00", align 1 12@s4 = constant [4 x i8] c"aab\00", align 1 13 14; strncmp(s, "aa", 1) 15define i1 @test_strncmp_0(ptr %s) { 16entry: 17 %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3, i64 1) 18 %cmp = icmp eq i32 %call, 0 19 ret i1 %cmp 20} 21; CHECK-LABEL: @test_strncmp_0( 22; CHECK: @strncmp 23 24; strncmp(s, "aa", 2) 25define i1 @test_strncmp_1(ptr %s) { 26entry: 27 %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3, i64 2) 28 %cmp = icmp eq i32 %call, 0 29 ret i1 %cmp 30} 31; CHECK-LABEL: @test_strncmp_1( 32; TH-3-NOT: @strncmp 33; TH-2-NOT: @strncmp 34; TH-1: @strncmp 35; TH-0: @strncmp 36 37define i1 @test_strncmp_1_dereferenceable(ptr dereferenceable(2) %s) { 38entry: 39 %call = tail call i32 @strncmp(ptr nonnull %s, ptr nonnull dereferenceable(3) @s3, i64 2) 40 %cmp = icmp eq i32 %call, 0 41 ret i1 %cmp 42} 43; CHECK-LABEL: @test_strncmp_1_dereferenceable( 44; CHECK: @strncmp 45 46define i32 @test_strncmp_1_not_comparision(ptr %s) { 47entry: 48 %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3, i64 2) 49 ret i32 %call 50} 51; CHECK-LABEL: @test_strncmp_1_not_comparision( 52; CHECK: @strncmp 53 54; strncmp(s, "aa", 3) 55define i1 @test_strncmp_2(ptr %s) { 56entry: 57 %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3, i64 3) 58 %cmp = icmp eq i32 %call, 0 59 ret i1 %cmp 60} 61; CHECK-LABEL: @test_strncmp_2( 62; TH-3-NOT: @strncmp 63; TH-2: @strncmp 64; TH-1: @strncmp 65; TH-0: @strncmp 66 67; strncmp(s, "aab", 3) 68define i1 @test_strncmp_3(ptr %s) { 69entry: 70 %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(4) @s4, i64 3) 71 %cmp = icmp eq i32 %call, 0 72 ret i1 %cmp 73} 74; CHECK-LABEL: @test_strncmp_3( 75; TH-3-NOT: @strncmp 76 77; strncmp(s, "aab", 4) 78define i1 @test_strncmp_4(ptr %s) { 79entry: 80 %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(4) @s4, i64 4) 81 %cmp = icmp eq i32 %call, 0 82 ret i1 %cmp 83} 84; CHECK-LABEL: @test_strncmp_4( 85; TH-3: @strncmp 86 87; strncmp(s, "aa", 2) 88define i1 @test_strncmp_5(ptr %s) { 89entry: 90 %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3, i64 2) 91 %cmp = icmp eq i32 %call, 0 92 ret i1 %cmp 93} 94; CHECK-LABEL: @test_strncmp_5( 95; TH-3-NOT: @strncmp 96 97; char s2[] = {'a', 'a'} 98; strncmp(s1, s2, 2) 99define i1 @test_strncmp_6(ptr %s1) { 100entry: 101 %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s1, ptr nonnull dereferenceable(2) @s2n, i64 2) 102 %cmp = icmp eq i32 %call, 0 103 ret i1 %cmp 104} 105; CHECK-LABEL: @test_strncmp_6( 106; TH-3-NOT: @strncmp 107 108; char s2[] = {'a', 'a'} 109; strncmp(s, s2, 3) 110define i1 @test_strncmp_7(ptr %s) { 111entry: 112 %call = tail call i32 @strncmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(2) @s2n, i64 3) 113 %cmp = icmp eq i32 %call, 0 114 ret i1 %cmp 115} 116; CHECK-LABEL: @test_strncmp_7( 117; CHECK: @strncmp 118 119; strcmp(s, "") 120define i1 @test_strcmp_0(ptr %s) { 121entry: 122 %call = tail call i32 @strcmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(1) @s1) 123 %cmp = icmp eq i32 %call, 0 124 ret i1 %cmp 125} 126; CHECK-LABEL: @test_strcmp_0( 127; CHECK: @strcmp 128 129; strcmp(s, "aa") 130define i1 @test_strcmp_1(ptr %s) { 131entry: 132 %call = tail call i32 @strcmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(3) @s3) 133 %cmp = icmp eq i32 %call, 0 134 ret i1 %cmp 135} 136; CHECK-LABEL: @test_strcmp_1( 137; TH-3-NOT: @strcmp 138 139; strcmp(s, "aab") 140define i1 @test_strcmp_2(ptr %s) { 141entry: 142 %call = tail call i32 @strcmp(ptr nonnull dereferenceable(1) %s, ptr nonnull dereferenceable(4) @s4) 143 %cmp = icmp eq i32 %call, 0 144 ret i1 %cmp 145} 146; CHECK-LABEL: @test_strcmp_2( 147; TH-3: @strcmp 148