[BPI] Teach BPI about bcmp function

bcmp is similar to memcmp
This commit is contained in:
Dávid Bolvanský 2020-08-11 20:42:58 +02:00
parent 61afdf0ab4
commit d68a2859ab
2 changed files with 94 additions and 1 deletions

View File

@ -898,7 +898,8 @@ bool BranchProbabilityInfo::calcZeroHeuristics(const BasicBlock *BB,
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

View File

@ -7,6 +7,7 @@ declare i32 @strncmp(i8*, i8*, i32)
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 @@ exit:
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 @@ exit:
%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
}