Skip to content
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
9 changes: 7 additions & 2 deletions llvm/lib/Transforms/Utils/LoopVersioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "llvm/IR/Dominators.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Cloning.h"
Expand Down Expand Up @@ -109,8 +110,12 @@ void LoopVersioning::versionLoop(
// Insert the conditional branch based on the result of the memchecks.
Instruction *OrigTerm = RuntimeCheckBB->getTerminator();
Builder.SetInsertPoint(OrigTerm);
Builder.CreateCondBr(RuntimeCheck, NonVersionedLoop->getLoopPreheader(),
VersionedLoop->getLoopPreheader());
auto *BI =
Builder.CreateCondBr(RuntimeCheck, NonVersionedLoop->getLoopPreheader(),
VersionedLoop->getLoopPreheader());
// We don't know what the probability of executing the versioned vs the
// unversioned variants is.
setExplicitlyUnknownBranchWeightsIfProfiled(*BI, DEBUG_TYPE);
OrigTerm->eraseFromParent();

// The loops merge in the original exit block. This is now dominated by the
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/Transforms/LoopDistribute/basic-with-memchecks.ll
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ target triple = "x86_64-apple-macosx10.10.0"
@E = common global ptr null, align 8

; CHECK-LABEL: @f(
define void @f() {
define void @f() !prof !{!"function_entry_count", i32 10} {
entry:
%a = load ptr, ptr @A, align 8
%b = load ptr, ptr @B, align 8
Expand All @@ -55,7 +55,7 @@ entry:
; CHECK: = icmp

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

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

Expand Down Expand Up @@ -289,3 +289,4 @@ attributes #1 = { nounwind convergent }

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