[llvm] d68a285 - [BPI] Teach BPI about bcmp function

Dávid Bolvanský via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 11:45:27 PDT 2020


Author: Dávid Bolvanský
Date: 2020-08-11T20:44:53+02:00
New Revision: d68a2859ab410426edf1683d926fa2d1b58c5935

URL: https://github.com/llvm/llvm-project/commit/d68a2859ab410426edf1683d926fa2d1b58c5935
DIFF: https://github.com/llvm/llvm-project/commit/d68a2859ab410426edf1683d926fa2d1b58c5935.diff

LOG: [BPI] Teach BPI about bcmp function
bcmp is similar to memcmp

Added: 
    

Modified: 
    llvm/lib/Analysis/BranchProbabilityInfo.cpp
    llvm/test/Analysis/BranchProbabilityInfo/libfunc_call.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 0a14c8c2bc44..eae2c4ea9da8 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -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

diff  --git a/llvm/test/Analysis/BranchProbabilityInfo/libfunc_call.ll b/llvm/test/Analysis/BranchProbabilityInfo/libfunc_call.ll
index 13bc0de90a61..fea0299765e2 100644
--- a/llvm/test/Analysis/BranchProbabilityInfo/libfunc_call.ll
+++ b/llvm/test/Analysis/BranchProbabilityInfo/libfunc_call.ll
@@ -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
+}
\ No newline at end of file


        


More information about the llvm-commits mailing list