[llvm] [BOLT][AArch64] Check Last Element Instead of Returning `nullptr` in `lookupStubFromGroup` (PR #114015)

Paschalis Mpeis via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 31 08:14:48 PDT 2024


================
@@ -130,9 +130,9 @@ BinaryBasicBlock *LongJmpPass::lookupStubFromGroup(
           const std::pair<uint64_t, BinaryBasicBlock *> &RHS) {
         return LHS.first < RHS.first;
       });
-  if (Cand == Candidates.end())
-    return nullptr;
-  if (Cand != Candidates.begin()) {
+  if (Cand == Candidates.end()) {
+    Cand = std::prev(Cand);
----------------
paschalis-mpeis wrote:

This could be alternatively seen as having only a `LeftCand` in the next if block, eg:
```diff
- if (Cand == Candidates.end()) {
-    Cand = std::prev(Cand);
} else if (Cand != Candidates.begin()) {
    const StubTy *LeftCand = std::prev(Cand);
-     if (Cand->first - DotAddress > DotAddress - LeftCand->first)
+     if (Cand==Candidates.end() || Cand->first - DotAddress > DotAddress - LeftCand->first)
      Cand = LeftCand;
  }
```

Not saying this is the way forward. Either way, might worth adding a single line comment explaining the case.

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


More information about the llvm-commits mailing list