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
10 changes: 6 additions & 4 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2106,16 +2106,18 @@ class GeneratedRTChecks {
BestTripCount = *EstimatedTC;
}

BestTripCount = std::max(BestTripCount, 1U);
InstructionCost NewMemCheckCost = MemCheckCost / BestTripCount;

// Let's ensure the cost is always at least 1.
NewMemCheckCost = std::max(*NewMemCheckCost.getValue(),
(InstructionCost::CostType)1);

LLVM_DEBUG(dbgs()
<< "We expect runtime memory checks to be hoisted "
<< "out of the outer loop. Cost reduced from "
<< MemCheckCost << " to " << NewMemCheckCost << '\n');
if (BestTripCount > 1)
LLVM_DEBUG(dbgs()
<< "We expect runtime memory checks to be hoisted "
<< "out of the outer loop. Cost reduced from "
<< MemCheckCost << " to " << NewMemCheckCost << '\n');

MemCheckCost = NewMemCheckCost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,43 @@ outer.exit:
}


define void @outer_pgo_minus1(ptr nocapture noundef %a, ptr nocapture noundef readonly %b, i64 noundef %m, i64 noundef %n) {
; CHECK-LABEL: LV: Checking a loop in 'outer_pgo_minus1'
; CHECK: Calculating cost of runtime checks:
; CHECK-NOT: We expect runtime memory checks to be hoisted out of the outer loop. Cost reduced
; CHECK: Total cost of runtime checks: 6
; CHECK-NEXT: LV: Minimum required TC for runtime checks to be profitable:16
entry:
br label %outer.loop

outer.loop:
%outer.iv = phi i64 [ %outer.iv.next, %inner.exit ], [ 0, %entry ]
%mul.us = mul nsw i64 %outer.iv, %n
br label %inner.loop

inner.loop:
%inner.iv = phi i64 [ 0, %outer.loop ], [ %inner.iv.next, %inner.loop ]
%add.us = add nuw nsw i64 %inner.iv, %mul.us
%arrayidx.us = getelementptr inbounds i8, ptr %b, i64 %add.us
%0 = load i8, ptr %arrayidx.us, align 1
%arrayidx7.us = getelementptr inbounds i8, ptr %a, i64 %add.us
%1 = load i8, ptr %arrayidx7.us, align 1
%add9.us = add i8 %1, %0
store i8 %add9.us, ptr %arrayidx7.us, align 1
%inner.iv.next = add nuw nsw i64 %inner.iv, 1
%exitcond.not = icmp eq i64 %inner.iv.next, %n
br i1 %exitcond.not, label %inner.exit, label %inner.loop

inner.exit:
%outer.iv.next = add nuw nsw i64 %outer.iv, 1
%exitcond26.not = icmp eq i64 %outer.iv.next, %m
br i1 %exitcond26.not, label %outer.exit, label %outer.loop, !prof !1

outer.exit:
ret void
}


define void @outer_known_tc3_full_range_checks(ptr nocapture noundef %dst, ptr nocapture noundef readonly %src, i64 noundef %n) {
; CHECK-LABEL: LV: Checking a loop in 'outer_known_tc3_full_range_checks'
; CHECK: Calculating cost of runtime checks:
Expand Down Expand Up @@ -215,3 +252,4 @@ outer.exit:


!0 = !{!"branch_weights", i32 10, i32 20}
!1 = !{!"branch_weights", i32 1, i32 -1}