Skip to content

[BOLT] Improve BinaryFunction::inferFallThroughCounts() #105450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bolt/lib/Core/BinaryFunctionProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ void BinaryFunction::inferFallThroughCounts() {
if (SuccBI.Count == 0) {
SuccBI.Count = Inferred;
SuccBI.MispredictedCount = BinaryBasicBlock::COUNT_INFERRED;
Succ->ExecutionCount += Inferred;
Succ->ExecutionCount =
std::max(Succ->getKnownExecutionCount(), Inferred);
}
}
}
Expand Down
45 changes: 45 additions & 0 deletions bolt/test/X86/infer-fall-throughs.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Test that infer-fall-throughs would correctly infer the wrong fall-through
## edge count in the example

# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.o
# RUN: link_fdata %s %t.o %t.fdata
# RUN: llvm-strip --strip-unneeded %t.o
# RUN: %clang %cflags %t.o -o %t.exe -Wl,-q
# RUN: llvm-bolt %t.exe -o %t.bolt \
# RUN: --print-estimate-edge-counts --data=%t.fdata \
# RUN: 2>&1 | FileCheck --check-prefix=WITHOUTINFERENCE %s
# RUN: llvm-bolt %t.exe -o %t.bolt --infer-fall-throughs \
# RUN: --print-estimate-edge-counts --data=%t.fdata \
# RUN: 2>&1 | FileCheck --check-prefix=CORRECTINFERENCE %s


# WITHOUTINFERENCE: Binary Function "main" after estimate-edge-counts
# WITHOUTINFERENCE: {{^\.Ltmp0}}
# WITHOUTINFERENCE: Successors: .Ltmp1 (mispreds: 0, count: 10), .LFT0 (mispreds: 0, count: 0)
# WITHOUTINFERENCE: {{^\.LFT0}}
# WITHOUTINFERENCE: Exec Count : 490

# CORRECTINFERENCE: Binary Function "main" after estimate-edge-counts
# CORRECTINFERENCE: {{^\.Ltmp0}}
# CORRECTINFERENCE: Successors: .Ltmp1 (mispreds: 0, count: 10), .LFT0 (inferred count: 490)
# CORRECTINFERENCE: {{^\.LFT0}}
# CORRECTINFERENCE: Exec Count : 490


.globl main
.type main, @function
main:
LLmain_LLstart:
jmp LLstart
# FDATA: 1 main #LLmain_LLstart# 1 main #LLstart# 0 500
LLstart:
jge LLexit
# FDATA: 1 main #LLstart# 1 main #LLexit# 0 10
# FDATA: 1 main #LLstart# 1 main #LLmore# 0 0
LLmore:
movl $5, %eax
# FDATA: 1 main #LLmore# 1 main #LLexit# 0 490
LLexit:
ret
.LLmain_end:
.size main, .LLmain_end-main
Loading