Skip to content

Commit 54b17fa

Browse files
committed
[BOLT] Preserve Offset annotation in fixDoubleJumps (#91898)
Offset annotation was missed when optimizing an unconditional branch to a tail call. Test Plan: update bb-with-two-tail-calls.s
1 parent a037d88 commit 54b17fa

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ static uint64_t fixDoubleJumps(BinaryFunction &Function, bool MarkInvalid) {
715715
Pred->removeSuccessor(&BB);
716716
Pred->eraseInstruction(Pred->findInstruction(Branch));
717717
Pred->addTailCallInstruction(SuccSym);
718+
MCInst *TailCall = Pred->getLastNonPseudoInstr();
719+
assert(TailCall);
720+
MIB->setOffset(*TailCall, BB.getOffset());
718721
} else {
719722
return false;
720723
}

bolt/test/X86/bb-with-two-tail-calls.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
# RUN: llvm-strip --strip-unneeded %t.o
1010
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q -nostdlib
1111
# RUN: llvm-bolt %t.exe -o %t.out --data %t.fdata --lite=0 --dyno-stats \
12-
# RUN: --print-sctc --print-only=_start 2>&1 | FileCheck %s
12+
# RUN: --print-sctc --print-only=_start -enable-bat 2>&1 | FileCheck %s
1313
# CHECK-NOT: Assertion `BranchInfo.size() == 2 && "could only be called for blocks with 2 successors"' failed.
1414
# Two tail calls in the same basic block after SCTC:
15-
# CHECK: {{.*}}: ja {{.*}} # TAILCALL # CTCTakenCount: {{.*}}
16-
# CHECK-NEXT: {{.*}}: jmp {{.*}} # TAILCALL
15+
# CHECK: {{.*}}: ja {{.*}} # TAILCALL # Offset: 7 # CTCTakenCount: 4
16+
# CHECK-NEXT: {{.*}}: jmp {{.*}} # TAILCALL # Offset: 12
1717

1818
.globl _start
1919
_start:

0 commit comments

Comments
 (0)