LLVM 19.0.0git
Macros | Functions | Variables
LoopPredication.cpp File Reference
#include "llvm/Transforms/Scalar/LoopPredication.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/Analysis/GuardUtils.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/MemorySSA.h"
#include "llvm/Analysis/MemorySSAUpdater.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/ProfDataUtils.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/GuardUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"
#include <optional>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "loop-predication"
 

Functions

 STATISTIC (TotalConsidered, "Number of guards considered")
 
 STATISTIC (TotalWidened, "Number of checks widened")
 
static bool isSafeToTruncateWideIVType (const DataLayout &DL, ScalarEvolution &SE, const LoopICmp LatchCheck, Type *RangeCheckType)
 
static std::optional< LoopICmp > generateLoopLatchCheck (const DataLayout &DL, ScalarEvolution &SE, const LoopICmp LatchCheck, Type *RangeCheckType)
 
static void normalizePredicate (ScalarEvolution *SE, Loop *L, LoopICmp &RC)
 
static BranchInstFindWidenableTerminatorAboveLoop (Loop *L, LoopInfo &LI)
 If we can (cheaply) find a widenable branch which controls entry into the loop, return it.
 
static const SCEVgetMinAnalyzeableBackedgeTakenCount (ScalarEvolution &SE, DominatorTree &DT, Loop *L)
 Return the minimum of all analyzeable exit counts.
 

Variables

static cl::opt< boolEnableIVTruncation ("loop-predication-enable-iv-truncation", cl::Hidden, cl::init(true))
 
static cl::opt< boolEnableCountDownLoop ("loop-predication-enable-count-down-loop", cl::Hidden, cl::init(true))
 
static cl::opt< boolSkipProfitabilityChecks ("loop-predication-skip-profitability-checks", cl::Hidden, cl::init(false))
 
static cl::opt< float > LatchExitProbabilityScale ("loop-predication-latch-probability-scale", cl::Hidden, cl::init(2.0), cl::desc("scale factor for the latch probability. Value should be greater " "than 1. Lower values are ignored"))
 
static cl::opt< boolPredicateWidenableBranchGuards ("loop-predication-predicate-widenable-branches-to-deopt", cl::Hidden, cl::desc("Whether or not we should predicate guards " "expressed as widenable branches to deoptimize blocks"), cl::init(true))
 
static cl::opt< boolInsertAssumesOfPredicatedGuardsConditions ("loop-predication-insert-assumes-of-predicated-guards-conditions", cl::Hidden, cl::desc("Whether or not we should insert assumes of conditions of " "predicated guards"), cl::init(true))
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "loop-predication"

Definition at line 206 of file LoopPredication.cpp.

Function Documentation

◆ FindWidenableTerminatorAboveLoop()

static BranchInst * FindWidenableTerminatorAboveLoop ( Loop L,
LoopInfo LI 
)
static

If we can (cheaply) find a widenable branch which controls entry into the loop, return it.

Definition at line 974 of file LoopPredication.cpp.

References llvm::BasicBlock::getSinglePredecessor(), llvm::BasicBlock::getSingleSuccessor(), llvm::BranchInst::getSuccessor(), and llvm::isWidenableBranch().

◆ generateLoopLatchCheck()

static std::optional< LoopICmp > generateLoopLatchCheck ( const DataLayout DL,
ScalarEvolution SE,
const LoopICmp  LatchCheck,
Type RangeCheckType 
)
static

◆ getMinAnalyzeableBackedgeTakenCount()

static const SCEV * getMinAnalyzeableBackedgeTakenCount ( ScalarEvolution SE,
DominatorTree DT,
Loop L 
)
static

Return the minimum of all analyzeable exit counts.

This is an upper bound on the actual exit count. If there are not at least two analyzeable exits, returns SCEVCouldNotCompute.

Definition at line 1004 of file LoopPredication.cpp.

References assert(), llvm::DominatorTree::dominates(), llvm::ScalarEvolution::getCouldNotCompute(), llvm::ScalarEvolution::getExitCount(), llvm::ScalarEvolution::getUMinFromMismatchedTypes(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::SmallVectorBase< Size_T >::size().

◆ isSafeToTruncateWideIVType()

static bool isSafeToTruncateWideIVType ( const DataLayout DL,
ScalarEvolution SE,
const LoopICmp  LatchCheck,
Type RangeCheckType 
)
static

◆ normalizePredicate()

static void normalizePredicate ( ScalarEvolution SE,
Loop L,
LoopICmp &  RC 
)
static

◆ STATISTIC() [1/2]

STATISTIC ( TotalConsidered  ,
"Number of guards considered"   
)

◆ STATISTIC() [2/2]

STATISTIC ( TotalWidened  ,
"Number of checks widened"   
)

Variable Documentation

◆ EnableCountDownLoop

cl::opt< bool > EnableCountDownLoop("loop-predication-enable-count-down-loop", cl::Hidden, cl::init(true)) ( "loop-predication-enable-count-down-loop"  ,
cl::Hidden  ,
cl::init(true  
)
static

◆ EnableIVTruncation

cl::opt< bool > EnableIVTruncation("loop-predication-enable-iv-truncation", cl::Hidden, cl::init(true)) ( "loop-predication-enable-iv-truncation"  ,
cl::Hidden  ,
cl::init(true  
)
static

◆ InsertAssumesOfPredicatedGuardsConditions

cl::opt< bool > InsertAssumesOfPredicatedGuardsConditions("loop-predication-insert-assumes-of-predicated-guards-conditions", cl::Hidden, cl::desc("Whether or not we should insert assumes of conditions of " "predicated guards"), cl::init(true)) ( "loop-predication-insert-assumes-of-predicated-guards-conditions"  ,
cl::Hidden  ,
cl::desc("Whether or not we should insert assumes of conditions of " "predicated guards")  ,
cl::init(true  
)
static

◆ LatchExitProbabilityScale

cl::opt< float > LatchExitProbabilityScale("loop-predication-latch-probability-scale", cl::Hidden, cl::init(2.0), cl::desc("scale factor for the latch probability. Value should be greater " "than 1. Lower values are ignored")) ( "loop-predication-latch-probability-scale"  ,
cl::Hidden  ,
cl::init(2.0)  ,
cl::desc("scale factor for the latch probability. Value should be greater " "than 1. Lower values are ignored")   
)
static

◆ PredicateWidenableBranchGuards

cl::opt< bool > PredicateWidenableBranchGuards("loop-predication-predicate-widenable-branches-to-deopt", cl::Hidden, cl::desc("Whether or not we should predicate guards " "expressed as widenable branches to deoptimize blocks"), cl::init(true)) ( "loop-predication-predicate-widenable-branches-to-deopt"  ,
cl::Hidden  ,
cl::desc("Whether or not we should predicate guards " "expressed as widenable branches to deoptimize blocks")  ,
cl::init(true  
)
static

◆ SkipProfitabilityChecks

cl::opt< bool > SkipProfitabilityChecks("loop-predication-skip-profitability-checks", cl::Hidden, cl::init(false)) ( "loop-predication-skip-profitability-checks"  ,
cl::Hidden  ,
cl::init(false)   
)
static