LLVM 20.0.0git
Namespaces | Macros | Functions
SimplifyIndVar.cpp File Reference
#include "llvm/Transforms/Utils/SimplifyIndVar.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
#include "llvm/Transforms/Utils/ScalarEvolutionExpander.h"

Go to the source code of this file.

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
 

Macros

#define DEBUG_TYPE   "indvars"
 

Functions

 STATISTIC (NumElimIdentity, "Number of IV identities eliminated")
 
 STATISTIC (NumElimOperand, "Number of IV operands folded into a use")
 
 STATISTIC (NumFoldedUser, "Number of IV users folded into a constant")
 
 STATISTIC (NumElimRem, "Number of IV remainder operations eliminated")
 
 STATISTIC (NumSimplifiedSDiv, "Number of IV signed division operations converted to unsigned division")
 
 STATISTIC (NumSimplifiedSRem, "Number of IV signed remainder operations converted to unsigned remainder")
 
 STATISTIC (NumElimCmp, "Number of IV comparisons eliminated")
 
static InstructionfindCommonDominator (ArrayRef< Instruction * > Instructions, DominatorTree &DT)
 Find a point in code which dominates all given instructions.
 
static InstructionGetLoopInvariantInsertPosition (Loop *L, Instruction *Hint)
 
static bool isSimpleIVUser (Instruction *I, const Loop *L, ScalarEvolution *SE)
 Return true if this instruction generates a simple SCEV expression in terms of that IV.
 
std::pair< bool, boolllvm::simplifyUsersOfIV (PHINode *CurrIV, ScalarEvolution *SE, DominatorTree *DT, LoopInfo *LI, const TargetTransformInfo *TTI, SmallVectorImpl< WeakTrackingVH > &Dead, SCEVExpander &Rewriter, IVVisitor *V=nullptr)
 simplifyUsersOfIV - Simplify instructions that use this induction variable by using ScalarEvolution to analyze the IV's recurrence.
 
bool llvm::simplifyLoopIVs (Loop *L, ScalarEvolution *SE, DominatorTree *DT, LoopInfo *LI, const TargetTransformInfo *TTI, SmallVectorImpl< WeakTrackingVH > &Dead)
 SimplifyLoopIVs - Simplify users of induction variables within this loop.
 
static InstructiongetInsertPointForUses (Instruction *User, Value *Def, DominatorTree *DT, LoopInfo *LI)
 Determine the insertion point for this user.
 
static std::optional< BinaryOp > matchBinaryOp (Instruction *Op)
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "indvars"

Definition at line 34 of file SimplifyIndVar.cpp.

Function Documentation

◆ findCommonDominator()

static Instruction * findCommonDominator ( ArrayRef< Instruction * >  Instructions,
DominatorTree DT 
)
static

Find a point in code which dominates all given instructions.

We can safely assume that, whatever fact we can prove at the found point, this fact is also true for each of the given instructions.

Definition at line 116 of file SimplifyIndVar.cpp.

References assert(), llvm::DominatorTree::findNearestCommonDominator(), and Insn.

◆ getInsertPointForUses()

static Instruction * getInsertPointForUses ( Instruction User,
Value Def,
DominatorTree DT,
LoopInfo LI 
)
static

Determine the insertion point for this user.

By default, insert immediately before the user. SCEVExpander or LICM will hoist loop invariants out of the loop. For PHI nodes, there may be multiple uses, so compute the nearest common dominator for the incoming blocks. A nullptr can be returned if no viable location is found: it may happen if User is a PHI and Def only comes to this PHI from unreachable blocks.

Definition at line 1180 of file SimplifyIndVar.cpp.

References assert(), llvm::DominatorTree::dominates(), llvm::DominatorTree::findNearestCommonDominator(), llvm::LoopInfoBase< BlockT, LoopT >::getLoopFor(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::BasicBlock::getTerminator(), llvm::DominatorTree::isReachableFromEntry(), llvm_unreachable, and PHI.

◆ GetLoopInvariantInsertPosition()

static Instruction * GetLoopInvariantInsertPosition ( Loop L,
Instruction Hint 
)
static

Definition at line 629 of file SimplifyIndVar.cpp.

◆ isSimpleIVUser()

static bool isSimpleIVUser ( Instruction I,
const Loop L,
ScalarEvolution SE 
)
static

Return true if this instruction generates a simple SCEV expression in terms of that IV.

This is similar to IVUsers' isInteresting() but processes each instruction non-recursively when the operand is already known to be a simpleIVUser.

Definition at line 884 of file SimplifyIndVar.cpp.

References llvm::SCEVAddRecExpr::getLoop(), llvm::ScalarEvolution::getSCEV(), I, and llvm::ScalarEvolution::isSCEVable().

◆ matchBinaryOp()

static std::optional< BinaryOp > matchBinaryOp ( Instruction Op)
static

Definition at line 1426 of file SimplifyIndVar.cpp.

References llvm::BitWidth, llvm::APInt::getOneBitSet(), and X.

◆ STATISTIC() [1/7]

STATISTIC ( NumElimCmp  ,
"Number of IV comparisons eliminated"   
)

References Rewriter.

◆ STATISTIC() [2/7]

STATISTIC ( NumElimIdentity  ,
"Number of IV identities eliminated"   
)

◆ STATISTIC() [3/7]

STATISTIC ( NumElimOperand  ,
"Number of IV operands folded into a use"   
)

◆ STATISTIC() [4/7]

STATISTIC ( NumElimRem  ,
"Number of IV remainder operations eliminated"   
)

◆ STATISTIC() [5/7]

STATISTIC ( NumFoldedUser  ,
"Number of IV users folded into a constant"   
)

◆ STATISTIC() [6/7]

STATISTIC ( NumSimplifiedSDiv  ,
"Number of IV signed division operations converted to unsigned division"   
)

◆ STATISTIC() [7/7]

STATISTIC ( NumSimplifiedSRem  ,
"Number of IV signed remainder operations converted to unsigned remainder"   
)