[BPI] Teach BPI about bcmp function
bcmp is similar to memcmp
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 0a14c8c2..eae2c4e 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -898,7 +898,8 @@
Func == LibFunc_strcmp ||
Func == LibFunc_strncasecmp ||
Func == LibFunc_strncmp ||
- Func == LibFunc_memcmp) {
+ Func == LibFunc_memcmp ||
+ Func == LibFunc_bcmp) {
// strcmp and similar functions return zero, negative, or positive, if the
// first string is equal, less, or greater than the second. We consider it
// likely that the strings are not equal, so a comparison with zero is
diff --git a/llvm/test/Analysis/BranchProbabilityInfo/libfunc_call.ll b/llvm/test/Analysis/BranchProbabilityInfo/libfunc_call.ll
index 13bc0de..fea0299 100644
--- a/llvm/test/Analysis/BranchProbabilityInfo/libfunc_call.ll
+++ b/llvm/test/Analysis/BranchProbabilityInfo/libfunc_call.ll
@@ -7,6 +7,7 @@
declare i32 @strcasecmp(i8*, i8*)
declare i32 @strncasecmp(i8*, i8*, i32)
declare i32 @memcmp(i8*, i8*)
+declare i32 @bcmp(i8*, i8*)
declare i32 @nonstrcmp(i8*, i8*)
@@ -35,6 +36,28 @@
ret i32 %result
}
+define i32 @test_strcmp_eq5(i8* %p, i8* %q) {
+; CHECK: Printing analysis {{.*}} for function 'test_strcmp_eq5'
+entry:
+ %val = call i32 @strcmp(i8* %p, i8* %q)
+ %cond = icmp eq i32 %val, 5
+ br i1 %cond, label %then, label %else
+; CHECK: edge entry -> then probability is 0x30000000 / 0x80000000 = 37.50%
+; CHECK: edge entry -> else probability is 0x50000000 / 0x80000000 = 62.50%
+
+then:
+ br label %exit
+; CHECK: edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+
+else:
+ br label %exit
+; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+
+exit:
+ %result = phi i32 [ 0, %then ], [ 1, %else ]
+ ret i32 %result
+}
+
define i32 @test_strcmp_ne(i8* %p, i8* %q) {
; CHECK: Printing analysis {{.*}} for function 'test_strcmp_ne'
entry:
@@ -262,3 +285,72 @@
%result = phi i32 [ 0, %then ], [ 1, %else ]
ret i32 %result
}
+
+
+define i32 @test_bcmp_eq(i8* %p, i8* %q) {
+; CHECK: Printing analysis {{.*}} for function 'test_bcmp_eq'
+entry:
+ %val = call i32 @bcmp(i8* %p, i8* %q)
+ %cond = icmp eq i32 %val, 0
+ br i1 %cond, label %then, label %else
+; CHECK: edge entry -> then probability is 0x30000000 / 0x80000000 = 37.50%
+; CHECK: edge entry -> else probability is 0x50000000 / 0x80000000 = 62.50%
+
+then:
+ br label %exit
+; CHECK: edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+
+else:
+ br label %exit
+; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+
+exit:
+ %result = phi i32 [ 0, %then ], [ 1, %else ]
+ ret i32 %result
+}
+
+define i32 @test_bcmp_eq5(i8* %p, i8* %q) {
+; CHECK: Printing analysis {{.*}} for function 'test_bcmp_eq5'
+entry:
+ %val = call i32 @bcmp(i8* %p, i8* %q)
+ %cond = icmp eq i32 %val, 5
+ br i1 %cond, label %then, label %else
+; CHECK: edge entry -> then probability is 0x30000000 / 0x80000000 = 37.50%
+; CHECK: edge entry -> else probability is 0x50000000 / 0x80000000 = 62.50%
+
+then:
+ br label %exit
+; CHECK: edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+
+else:
+ br label %exit
+; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+
+exit:
+ %result = phi i32 [ 0, %then ], [ 1, %else ]
+ ret i32 %result
+}
+
+
+
+define i32 @test_bcmp_ne(i8* %p, i8* %q) {
+; CHECK: Printing analysis {{.*}} for function 'test_bcmp_ne'
+entry:
+ %val = call i32 @bcmp(i8* %p, i8* %q)
+ %cond = icmp ne i32 %val, 0
+ br i1 %cond, label %then, label %else
+; CHECK: edge entry -> then probability is 0x50000000 / 0x80000000 = 62.50%
+; CHECK: edge entry -> else probability is 0x30000000 / 0x80000000 = 37.50%
+
+then:
+ br label %exit
+; CHECK: edge then -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+
+else:
+ br label %exit
+; CHECK: edge else -> exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
+
+exit:
+ %result = phi i32 [ 0, %then ], [ 1, %else ]
+ ret i32 %result
+}
\ No newline at end of file