From 8bbcd0e3e67882c314ee478e6be563b1bb178c26 Mon Sep 17 00:00:00 2001 From: Philip Reames Date: Fri, 10 Feb 2017 06:12:06 +0000 Subject: [PATCH] [LoopUnswitch] Remove BFI usage (dead code) Chandler mentioned at the last social that the need for BFI in the new pass manager was causing a slight hiccup for this pass. Given this code has been checked in, but off for over a year, it makes sense to just remove it for now. Note that there's nothing wrong with the general idea - it's actually a quite good one - and once we have the infrastructure in place to implement this without the full recompuation on every loop, we absolutely should. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294715 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/LoopUnswitch.cpp | 43 ------------------- test/Transforms/LoopUnswitch/cold-loop.ll | 52 ----------------------- 2 files changed, 95 deletions(-) delete mode 100644 test/Transforms/LoopUnswitch/cold-loop.ll diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index d7daab4c666..d42119df3dc 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -77,19 +77,6 @@ static cl::opt Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden); -static cl::opt -LoopUnswitchWithBlockFrequency("loop-unswitch-with-block-frequency", - cl::init(false), cl::Hidden, - cl::desc("Enable the use of the block frequency analysis to access PGO " - "heuristics to minimize code growth in cold regions.")); - -static cl::opt -ColdnessThreshold("loop-unswitch-coldness-threshold", cl::init(1), cl::Hidden, - cl::desc("Coldness threshold in percentage. The loop header frequency " - "(relative to the entry frequency) is compared with this " - "threshold to determine if non-trivial unswitching should be " - "enabled.")); - namespace { class LUAnalysisCache { @@ -174,13 +161,6 @@ namespace { LUAnalysisCache BranchesInfo; - bool EnabledPGO; - - // BFI and ColdEntryFreq are only used when PGO and - // LoopUnswitchWithBlockFrequency are enabled. - BlockFrequencyInfo BFI; - BlockFrequency ColdEntryFreq; - bool OptimizeForSize; bool redoLoop; @@ -457,19 +437,6 @@ bool LoopUnswitch::runOnLoop(Loop *L, LPPassManager &LPM_Ref) { if (SanitizeMemory) computeLoopSafetyInfo(&SafetyInfo, L); - EnabledPGO = F->getEntryCount().hasValue(); - - if (LoopUnswitchWithBlockFrequency && EnabledPGO) { - BranchProbabilityInfo BPI(*F, *LI); - BFI.calculate(*L->getHeader()->getParent(), BPI, *LI); - - // Use BranchProbability to compute a minimum frequency based on - // function entry baseline frequency. Loops with headers below this - // frequency are considered as cold. - const BranchProbability ColdProb(ColdnessThreshold, 100); - ColdEntryFreq = BlockFrequency(BFI.getEntryFreq()) * ColdProb; - } - bool Changed = false; do { assert(currentLoop->isLCSSAForm(*DT)); @@ -581,16 +548,6 @@ bool LoopUnswitch::processCurrentLoop() { loopHeader->getParent()->hasFnAttribute(Attribute::OptimizeForSize)) return false; - if (LoopUnswitchWithBlockFrequency && EnabledPGO) { - // Compute the weighted frequency of the hottest block in the - // loop (loopHeader in this case since inner loops should be - // processed before outer loop). If it is less than ColdFrequency, - // we should not unswitch. - BlockFrequency LoopEntryFreq = BFI.getBlockFreq(loopHeader); - if (LoopEntryFreq < ColdEntryFreq) - return false; - } - for (IntrinsicInst *Guard : Guards) { Value *LoopCond = FindLIVLoopCondition(Guard->getOperand(0), currentLoop, Changed); diff --git a/test/Transforms/LoopUnswitch/cold-loop.ll b/test/Transforms/LoopUnswitch/cold-loop.ll deleted file mode 100644 index 1fbc08038bb..00000000000 --- a/test/Transforms/LoopUnswitch/cold-loop.ll +++ /dev/null @@ -1,52 +0,0 @@ -; RUN: opt < %s -loop-unswitch -loop-unswitch-with-block-frequency -S 2>&1 | FileCheck %s - -;; trivial condition should be unswithed regardless of coldness. -define i32 @test1(i1 %cond1, i1 %cond2) !prof !1 { - br i1 %cond1, label %loop_begin, label %loop_exit, !prof !0 - -loop_begin: -; CHECK: br i1 true, label %continue, label %loop_exit.loopexit - br i1 %cond2, label %continue, label %loop_exit ; trivial condition - -continue: - call void @some_func1() noreturn nounwind - br label %loop_begin - -loop_exit: - ret i32 0 -} - -;; cold non-trivial condition should not be unswitched. -define i32 @test2(i32* %var, i1 %cond1, i1 %cond2) !prof !1 { - br i1 %cond1, label %loop_begin, label %loop_exit, !prof !0 - -loop_begin: - store i32 1, i32* %var -; CHECK: br i1 %cond2, label %continue1, label %continue2 - br i1 %cond2, label %continue1, label %continue2 ; non-trivial condition - -continue1: - call void @some_func1() noreturn nounwind - br label %joint - -continue2: - call void @some_func2() noreturn nounwind - br label %joint - -joint: -;; unswitching will duplicate these calls. - call void @some_func3() noreturn nounwind - call void @some_func4() noreturn nounwind - br label %loop_begin - -loop_exit: - ret i32 0 -} - -declare void @some_func1() noreturn -declare void @some_func2() noreturn -declare void @some_func3() noreturn -declare void @some_func4() noreturn - -!0 = !{!"branch_weights", i32 1, i32 100000000} -!1 = !{!"function_entry_count", i64 100} -- 2.50.1