Skip to content

Commit 452c2f5

Browse files
committed
[LVer][profcheck] explicitly set unknown branch weights for the versioned/unversioned selector
1 parent c34f582 commit 452c2f5

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

llvm/lib/Transforms/Utils/LoopVersioning.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/IR/Dominators.h"
2424
#include "llvm/IR/MDBuilder.h"
2525
#include "llvm/IR/PassManager.h"
26+
#include "llvm/IR/ProfDataUtils.h"
2627
#include "llvm/Support/CommandLine.h"
2728
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
2829
#include "llvm/Transforms/Utils/Cloning.h"
@@ -109,8 +110,13 @@ void LoopVersioning::versionLoop(
109110
// Insert the conditional branch based on the result of the memchecks.
110111
Instruction *OrigTerm = RuntimeCheckBB->getTerminator();
111112
Builder.SetInsertPoint(OrigTerm);
112-
Builder.CreateCondBr(RuntimeCheck, NonVersionedLoop->getLoopPreheader(),
113-
VersionedLoop->getLoopPreheader());
113+
auto *BI =
114+
Builder.CreateCondBr(RuntimeCheck, NonVersionedLoop->getLoopPreheader(),
115+
VersionedLoop->getLoopPreheader());
116+
// We don't know what the probability of executing the versioned vs the
117+
// unversioned variants is.
118+
setExplicitlyUnknownBranchWeightsIfProfiled(
119+
*BI, *BI->getParent()->getParent(), DEBUG_TYPE);
114120
OrigTerm->eraseFromParent();
115121

116122
// The loops merge in the original exit block. This is now dominated by the

llvm/test/Transforms/LoopDistribute/basic-with-memchecks.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ target triple = "x86_64-apple-macosx10.10.0"
2828
@E = common global ptr null, align 8
2929

3030
; CHECK-LABEL: @f(
31-
define void @f() {
31+
define void @f() !prof !{!"function_entry_count", i32 10} {
3232
entry:
3333
%a = load ptr, ptr @A, align 8
3434
%b = load ptr, ptr @B, align 8
@@ -55,7 +55,7 @@ entry:
5555
; CHECK: = icmp
5656

5757
; CHECK-NOT: = icmp
58-
; CHECK: br i1 %conflict.rdx15, label %for.body.ph.lver.orig, label %for.body.ph.ldist1
58+
; CHECK: br i1 %conflict.rdx15, label %for.body.ph.lver.orig, label %for.body.ph.ldist1, !prof ![[PROF1:[0-9]]]
5959

6060
; The non-distributed loop that the memchecks fall back on.
6161

@@ -289,3 +289,4 @@ attributes #1 = { nounwind convergent }
289289

290290
!0 = distinct !{!0, !1}
291291
!1 = !{!"llvm.loop.distribute.enable", i1 true}
292+
; CHECK: ![[PROF1]] = !{!"unknown", !"loop-versioning"}

0 commit comments

Comments
 (0)