Skip to content

[WPD]Provide branch weight for checking mode. #124084

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 2 commits into from
Jan 23, 2025
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
5 changes: 3 additions & 2 deletions llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,9 @@ void DevirtModule::applySingleImplDevirt(VTableSlotInfo &SlotInfo,
// perform a debug trap.
if (DevirtCheckMode == WPDCheckMode::Trap) {
auto *Cond = Builder.CreateICmpNE(CB.getCalledOperand(), Callee);
Instruction *ThenTerm =
SplitBlockAndInsertIfThen(Cond, &CB, /*Unreachable=*/false);
Instruction *ThenTerm = SplitBlockAndInsertIfThen(
Cond, &CB, /*Unreachable=*/false,
MDBuilder(M.getContext()).createUnlikelyBranchWeights());
Builder.SetInsertPoint(ThenTerm);
Function *TrapFn =
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::debugtrap);
Expand Down
4 changes: 3 additions & 1 deletion llvm/test/ThinLTO/X86/devirt_check.ll
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ entry:
; Ensure !prof and !callees metadata for indirect call promotion removed.
; TRAP-NOT: prof
; TRAP-NOT: callees
; TRAP: br i1 %.not, label %1, label %0
; TRAP: br i1 %.not, label %1, label %0, !prof ![[PROF:[0-9]+]]
; TRAP: 0:
; TRAP: tail call void @llvm.debugtrap()
; TRAP: br label %1
Expand Down Expand Up @@ -89,6 +89,8 @@ entry:
; CHECK-LABEL: ret i32
; CHECK-LABEL: }

; TRAP: ![[PROF]] = !{!"branch_weights", i32 1048575, i32 1}

declare i1 @llvm.type.test(i8*, metadata)
declare void @llvm.assume(i1)

Expand Down
Loading