Skip to content

Commit 400f6ed

Browse files
author
Serguei Katkov
committed
[IRCE] Use the same min runtime iteration threshold for BPI and BFI checks
In the last change to IRCE the BPI is ignored if BFI is present, however BFI and BPI have a different thresholds. Specifically BPI approach checks only latch exit probability so it is expected if the loop has only one exit block (latch) the behavior with BFI and BPI should be the same, BPI approach by default uses threshold 10, so it considers the loop with estimated number of iterations less then 10 should not be considered for IRCE optimization. BFI approach uses the default value 3 and this is inconsistent. The CL modifies the code to use the same threshold for both approaches.. The test is updated due to it has two side-exits (except latch) and each of them has a probability 1/16, so BFI estimates the number of runtime iteration is about to 7 (1/16 + 1/16 + some for latch) and test fails. Reviewers: mkazantsev, ebrevnov Reviewed By: mkazantsev Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D91230
1 parent c22dc71 commit 400f6ed

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,11 @@ static cl::opt<bool> PrintChangedLoops("irce-print-changed-loops", cl::Hidden,
110110
static cl::opt<bool> PrintRangeChecks("irce-print-range-checks", cl::Hidden,
111111
cl::init(false));
112112

113-
static cl::opt<int> MaxExitProbReciprocal("irce-max-exit-prob-reciprocal",
114-
cl::Hidden, cl::init(10));
115-
116113
static cl::opt<bool> SkipProfitabilityChecks("irce-skip-profitability-checks",
117114
cl::Hidden, cl::init(false));
118115

119-
static cl::opt<unsigned> MinRuntimeIterations("min-runtime-iterations",
120-
cl::Hidden, cl::init(3));
116+
static cl::opt<unsigned> MinRuntimeIterations("irce-min-runtime-iterations",
117+
cl::Hidden, cl::init(10));
121118

122119
static cl::opt<bool> AllowUnsignedLatchCondition("irce-allow-unsigned-latch",
123120
cl::Hidden, cl::init(true));
@@ -1871,7 +1868,7 @@ InductiveRangeCheckElimination::isProfitableToTransform(const Loop &L,
18711868
return true;
18721869
BranchProbability ExitProbability =
18731870
BPI->getEdgeProbability(LS.Latch, LS.LatchBrExitIdx);
1874-
if (ExitProbability > BranchProbability(1, MaxExitProbReciprocal)) {
1871+
if (ExitProbability > BranchProbability(1, MinRuntimeIterations)) {
18751872
LLVM_DEBUG(dbgs() << "irce: could not prove profitability: "
18761873
<< "the exit probability is too big " << ExitProbability
18771874
<< "\n";);

llvm/test/Transforms/IRCE/low-iterations.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
; RUN: opt -verify-loop-info -irce-print-changed-loops -passes=irce -min-runtime-iterations=3 < %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO
2-
; RUN: opt -verify-loop-info -irce-print-changed-loops -passes=irce -min-runtime-iterations=0 < %s 2>&1 | FileCheck %s --check-prefixes=CHECK-YES
1+
; RUN: opt -verify-loop-info -irce-print-changed-loops -passes=irce -irce-min-runtime-iterations=3 < %s 2>&1 | FileCheck %s --check-prefixes=CHECK-NO
2+
; RUN: opt -verify-loop-info -irce-print-changed-loops -passes=irce -irce-min-runtime-iterations=0 < %s 2>&1 | FileCheck %s --check-prefixes=CHECK-YES
33

44
; CHECK-YES: constrained Loop
55
; CHECK-NO-NOT: constrained Loop

llvm/test/Transforms/IRCE/multiple-access-no-preloop.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ define void @multiple_access_no_preloop(
6060
; CHECK: br i1 %next.postloop, label %loop.postloop, label %exit.loopexit
6161

6262
!0 = !{i32 0, i32 2147483647}
63-
!1 = !{!"branch_weights", i32 64, i32 4}
63+
!1 = !{!"branch_weights", i32 128, i32 4}

0 commit comments

Comments
 (0)