[llvm-branch-commits] [BOLT][BAT] Fix translate for branches added by BOLT (PR #90811)

Amir Ayupov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri May 3 14:34:19 PDT 2024


================
@@ -478,18 +478,34 @@ uint64_t BoltAddressTranslation::translate(uint64_t FuncAddress,
     return Offset;
 
   const MapTy &Map = Iter->second;
+  if (IsBranchSrc) {
+    // Try exact lookup first
+    auto KeyVal = Map.find(Offset);
+    if (KeyVal != Map.end() && KeyVal->second & BRANCHENTRY)
+      return KeyVal->second >> 1;
+  }
   auto KeyVal = Map.upper_bound(Offset);
   if (KeyVal == Map.begin())
     return Offset;
 
   --KeyVal;
 
   const uint32_t Val = KeyVal->second >> 1; // dropping BRANCHENTRY bit
-  // Branch source addresses are translated to the first instruction of the
-  // source BB to avoid accounting for modifications BOLT may have made in the
-  // BB regarding deletion/addition of instructions.
-  if (IsBranchSrc)
-    return Val;
+  if (IsBranchSrc) {
----------------
aaupov wrote:

No as we use `find` for exact match, and `upper_bound` for regular translation.

https://github.com/llvm/llvm-project/pull/90811


More information about the llvm-branch-commits mailing list