Skip to content

Commit 6b9bca8

Browse files
authored
[BOLT] Preserve Offset annotation in SCTC (#91693)
Offset annotation is used in writing BAT tables. Test Plan: updated sctc-bug4.test
1 parent a427aa9 commit 6b9bca8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

bolt/lib/Passes/BinaryPasses.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,11 @@ uint64_t SimplifyConditionalTailCalls::fixTailCalls(BinaryFunction &BF) {
910910
auto &CTCAnnotation =
911911
MIB->getOrCreateAnnotationAs<uint64_t>(*CondBranch, "CTCTakenCount");
912912
CTCAnnotation = CTCTakenFreq;
913+
// Preserve Offset annotation, used in BAT.
914+
// Instr is a direct tail call instruction that was created when CTCs are
915+
// first expanded, and has the original CTC offset set.
916+
if (std::optional<uint32_t> Offset = MIB->getOffset(*Instr))
917+
MIB->setOffset(*CondBranch, *Offset);
913918

914919
// Remove the unused successor which may be eliminated later
915920
// if there are no other users.

bolt/test/X86/sctc-bug4.test

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
# Check that fallthrough blocks are handled properly.
1+
# Check that fallthrough blocks are handled properly and Offset annotation is
2+
# set for conditional tail calls.
23

34
RUN: %clang %cflags %S/Inputs/sctc_bug4.s -o %t
4-
RUN: llvm-bolt %t -o %t.null \
5+
RUN: llvm-bolt %t -o %t.null --enable-bat \
56
RUN: -funcs=test_func -print-sctc -sequential-disassembly 2>&1 | FileCheck %s
67

78
CHECK: .Ltmp2 (3 instructions, align : 1)
89
CHECK-NEXT: CFI State : 0
10+
CHECK-NEXT: Input offset: 0x24
911
CHECK-NEXT: Predecessors: .LFT1
1012
CHECK-NEXT: 00000024: cmpq $0x20, %rsi
11-
CHECK-NEXT: 00000028: ja dummy # TAILCALL {{.*}}# CTCTakenCount: 0
13+
CHECK-NEXT: 00000028: ja dummy # TAILCALL # Offset: 53 # CTCTakenCount: 0
1214
CHECK-NEXT: 0000002a: jmp .Ltmp4
1315
CHECK-NEXT: Successors: .Ltmp4
1416
CHECK-NEXT: CFI State: 0
1517

1618
CHECK: .Ltmp1 (2 instructions, align : 1)
1719
CHECK-NEXT: CFI State : 0
20+
CHECK-NEXT: Input offset: 0x2c
1821
CHECK-NEXT: Predecessors: .LFT0
1922
CHECK-NEXT: 0000002c: xorq %r11, %rax
2023
CHECK-NEXT: 0000002f: retq
2124
CHECK-NEXT: CFI State: 0
2225

2326
CHECK: .Ltmp4 (4 instructions, align : 1)
2427
CHECK-NEXT: CFI State : 0
28+
CHECK-NEXT: Input offset: 0x3a
2529
CHECK-NEXT: Predecessors: .Ltmp2

0 commit comments

Comments
 (0)