27 #define DEBUG_TYPE "indvars"
53 STATISTIC(NumWidened ,
"Number of indvars widened");
54 STATISTIC(NumReplaced ,
"Number of exit values replaced");
55 STATISTIC(NumLFTR ,
"Number of loop exit tests replaced");
56 STATISTIC(NumElimExt ,
"Number of IV sign/zero extends eliminated");
57 STATISTIC(NumElimIV ,
"Number of congruent IVs eliminated");
64 cl::desc(
"Verify the ScalarEvolution result after running indvars"));
67 class IndVarSimplify :
public LoopPass {
99 virtual void releaseMemory() {
103 bool isValidRewrite(
Value *FromVal,
Value *ToVal);
106 void RewriteNonIntegerIVs(
Loop *L);
112 Value *LinearFunctionTestReplace(
Loop *L,
const SCEV *BackedgeTakenCount,
115 void SinkUnusedInvariants(
Loop *L);
121 "Induction Variable Simplification",
false,
false)
131 return new IndVarSimplify();
138 bool IndVarSimplify::isValidRewrite(
Value *FromVal,
Value *ToVal) {
149 Value *FromPtr = FromVal;
150 Value *ToPtr = ToVal;
151 if (
GEPOperator *GEP = dyn_cast<GEPOperator>(FromVal)) {
152 FromPtr = GEP->getPointerOperand();
154 if (
GEPOperator *GEP = dyn_cast<GEPOperator>(ToVal)) {
155 ToPtr = GEP->getPointerOperand();
157 if (FromPtr != FromVal || ToPtr != ToVal) {
159 if (FromPtr == ToPtr)
173 const SCEV *FromBase = SE->getPointerBase(SE->getSCEV(FromPtr));
174 const SCEV *ToBase = SE->getPointerBase(SE->getSCEV(ToPtr));
175 if (FromBase == ToBase)
178 DEBUG(
dbgs() <<
"INDVARS: GEP rewrite bail out "
179 << *FromBase <<
" != " << *ToBase <<
"\n");
209 assert(InsertPt &&
"Missing phi operand");
210 assert((!isa<Instruction>(Def) ||
211 DT->
dominates(cast<Instruction>(Def), InsertPt)) &&
212 "def does not dominate all uses");
222 bool isExact =
false;
241 void IndVarSimplify::HandleFloatingPointIV(
Loop *L,
PHINode *PN) {
243 unsigned BackEdge = IncomingEdge^1;
257 if (Incr == 0 || Incr->
getOpcode() != Instruction::FAdd)
return;
263 if (IncValueVal == 0 || Incr->
getOperand(0) != PN ||
271 if (IncrUse == Incr->
use_end())
return;
273 if (IncrUse != Incr->
use_end())
return;
280 if (Compare == 0 || !Compare->
hasOneUse() ||
281 !isa<BranchInst>(Compare->
use_back()))
290 assert(TheBr->
isConditional() &&
"Can't use fcmp if not conditional");
301 if (ExitValueVal == 0 ||
341 if (InitValue >= ExitValue)
344 uint32_t Range = uint32_t(ExitValue-InitValue);
348 if (++Range == 0)
return;
351 unsigned Leftover = Range % uint32_t(IncValue);
362 if (Leftover != 0 && int32_t(ExitValue+IncValue) < ExitValue)
368 if (InitValue <= ExitValue)
371 uint32_t Range = uint32_t(InitValue-ExitValue);
375 if (++Range == 0)
return;
378 unsigned Leftover = Range % uint32_t(-IncValue);
389 if (Leftover != 0 && int32_t(ExitValue+IncValue) > ExitValue)
439 void IndVarSimplify::RewriteNonIntegerIVs(
Loop *L) {
451 for (
unsigned i = 0, e = PHIs.
size(); i != e; ++i)
452 if (
PHINode *PN = dyn_cast_or_null<PHINode>(&*PHIs[i]))
453 HandleFloatingPointIV(L, PN);
487 for (
unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
499 while ((PN = dyn_cast<PHINode>(BBI++))) {
515 for (
unsigned i = 0; i != NumPreds; ++i) {
519 if (!isa<Instruction>(InVal))
535 if (!SE->isLoopInvariant(ExitValue, L) ||
545 unsigned NumHardInternalUses = 0;
546 unsigned NumSoftExternalUses = 0;
547 unsigned NumUses = 0;
549 IB!=
IE && NumUses<=6 ; ++IB) {
555 NumHardInternalUses++;
563 PB!=PE && NumUses<=6 ; ++PB, ++NumUses) {
564 unsigned PhiOpc = cast<Instruction>(*PB)->getOpcode();
566 NumSoftExternalUses++;
571 NumSoftExternalUses++;
574 if (NumUses <= 6 && NumHardInternalUses && !NumSoftExternalUses)
580 DEBUG(
dbgs() <<
"INDVARS: RLEV: AfterLoopVal = " << *ExitVal <<
'\n'
581 <<
" LoopVal = " << *Inst <<
"\n");
583 if (!isValidRewrite(Inst, ExitVal)) {
584 DeadInsts.push_back(ExitVal);
595 DeadInsts.push_back(Inst);
632 Type *WidestNativeType;
635 WideIVInfo() : NarrowIV(0), WidestNativeType(0), IsSigned(
false) {}
647 SE(SCEV),
TD(TData) { WI.NarrowIV = NarrowIV; }
650 virtual void visitCast(
CastInst *Cast);
657 void WideIVVisitor::visitCast(
CastInst *Cast) {
658 bool IsSigned = Cast->
getOpcode() == Instruction::SExt;
659 if (!IsSigned && Cast->
getOpcode() != Instruction::ZExt)
663 uint64_t Width = SE->getTypeSizeInBits(Ty);
664 if (
TD && !
TD->isLegalInteger(Width))
667 if (!WI.WidestNativeType) {
668 WI.WidestNativeType = SE->getEffectiveSCEVType(Ty);
669 WI.IsSigned = IsSigned;
674 if (WI.IsSigned != IsSigned)
677 if (Width > SE->getTypeSizeInBits(WI.WidestNativeType))
678 WI.WidestNativeType = SE->getEffectiveSCEVType(Ty);
686 struct NarrowIVDefUse {
691 NarrowIVDefUse(): NarrowDef(0), NarrowUse(0), WideDef(0) {}
694 NarrowDef(ND), NarrowUse(NU), WideDef(WD) {}
717 const SCEV *WideIncExpr;
724 WidenIV(
const WideIVInfo &WI,
LoopInfo *LInfo,
727 OrigPhi(WI.NarrowIV),
728 WideType(WI.WidestNativeType),
729 IsSigned(WI.IsSigned),
738 assert(L->
getHeader() == OrigPhi->getParent() &&
"Phi must be an IV");
744 Value *getExtend(
Value *NarrowOper,
Type *WideType,
bool IsSigned,
751 const SCEVAddRecExpr* GetExtendedOperandRecurrence(NarrowIVDefUse DU);
770 Value *WidenIV::getExtend(
Value *NarrowOper,
Type *WideType,
bool IsSigned,
780 return IsSigned ? Builder.CreateSExt(NarrowOper, WideType) :
781 Builder.CreateZExt(NarrowOper, WideType);
787 Instruction *WidenIV::CloneIVUser(NarrowIVDefUse DU) {
788 unsigned Opcode = DU.NarrowUse->getOpcode();
792 case Instruction::Add:
793 case Instruction::Mul:
794 case Instruction::UDiv:
795 case Instruction::Sub:
799 case Instruction::Shl:
800 case Instruction::LShr:
801 case Instruction::AShr:
802 DEBUG(
dbgs() <<
"Cloning IVUser: " << *DU.NarrowUse <<
"\n");
809 Value *LHS = (DU.NarrowUse->getOperand(0) == DU.NarrowDef) ? DU.WideDef :
810 getExtend(DU.NarrowUse->getOperand(0), WideType, IsSigned, DU.NarrowUse);
811 Value *RHS = (DU.NarrowUse->getOperand(1) == DU.NarrowDef) ? DU.WideDef :
812 getExtend(DU.NarrowUse->getOperand(1), WideType, IsSigned, DU.NarrowUse);
819 Builder.Insert(WideBO);
821 dyn_cast<OverflowingBinaryOperator>(NarrowBO)) {
822 if (OBO->hasNoUnsignedWrap()) WideBO->setHasNoUnsignedWrap();
823 if (OBO->hasNoSignedWrap()) WideBO->setHasNoSignedWrap();
833 const SCEVAddRecExpr* WidenIV::GetExtendedOperandRecurrence(NarrowIVDefUse DU) {
835 if (DU.NarrowUse->getOpcode() != Instruction::Add)
840 unsigned ExtendOperIdx = DU.NarrowUse->getOperand(0) == DU.NarrowDef ? 1 : 0;
841 assert(DU.NarrowUse->getOperand(1-ExtendOperIdx) == DU.NarrowDef &&
"bad DU");
843 const SCEV *ExtendOperExpr = 0;
845 cast<OverflowingBinaryOperator>(DU.NarrowUse);
847 ExtendOperExpr = SE->getSignExtendExpr(
848 SE->getSCEV(DU.NarrowUse->getOperand(ExtendOperIdx)), WideType);
850 ExtendOperExpr = SE->getZeroExtendExpr(
851 SE->getSCEV(DU.NarrowUse->getOperand(ExtendOperIdx)), WideType);
861 SE->getAddExpr(SE->getSCEV(DU.WideDef), ExtendOperExpr));
863 if (!AddRec || AddRec->
getLoop() != L)
874 if (!SE->isSCEVable(NarrowUse->
getType()))
877 const SCEV *NarrowExpr = SE->getSCEV(NarrowUse);
878 if (SE->getTypeSizeInBits(NarrowExpr->
getType())
879 >= SE->getTypeSizeInBits(WideType)) {
885 const SCEV *WideExpr = IsSigned ?
886 SE->getSignExtendExpr(NarrowExpr, WideType) :
887 SE->getZeroExtendExpr(NarrowExpr, WideType);
889 if (!AddRec || AddRec->
getLoop() != L)
899 if (isa<PHINode>(DU.NarrowUse) &&
900 LI->getLoopFor(DU.NarrowUse->getParent()) != L)
904 if (IsSigned ? isa<SExtInst>(DU.NarrowUse) : isa<ZExtInst>(DU.NarrowUse)) {
905 Value *NewDef = DU.WideDef;
906 if (DU.NarrowUse->getType() != WideType) {
907 unsigned CastWidth = SE->getTypeSizeInBits(DU.NarrowUse->getType());
908 unsigned IVWidth = SE->getTypeSizeInBits(WideType);
909 if (CastWidth < IVWidth) {
912 NewDef = Builder.CreateTrunc(DU.WideDef, DU.NarrowUse->getType());
918 DEBUG(
dbgs() <<
"INDVARS: New IV " << *WidePhi
919 <<
" not wide enough to subsume " << *DU.NarrowUse <<
"\n");
920 DU.NarrowUse->replaceUsesOfWith(DU.NarrowDef, DU.WideDef);
921 NewDef = DU.NarrowUse;
924 if (NewDef != DU.NarrowUse) {
925 DEBUG(
dbgs() <<
"INDVARS: eliminating " << *DU.NarrowUse
926 <<
" replaced by " << *DU.WideDef <<
"\n");
928 DU.NarrowUse->replaceAllUsesWith(NewDef);
929 DeadInsts.push_back(DU.NarrowUse);
942 const SCEVAddRecExpr *WideAddRec = GetWideRecurrence(DU.NarrowUse);
944 WideAddRec = GetExtendedOperandRecurrence(DU);
951 Value *Trunc = Builder.CreateTrunc(DU.WideDef, DU.NarrowDef->getType());
952 DU.NarrowUse->replaceUsesOfWith(DU.NarrowDef, Trunc);
957 assert(DU.NarrowUse != DU.NarrowUse->getParent()->getTerminator() &&
958 "SCEV is not expected to evaluate a block terminator");
963 if (WideAddRec == WideIncExpr
964 && Rewriter.
hoistIVInc(WideInc, DU.NarrowUse))
967 WideUse = CloneIVUser(DU);
976 if (WideAddRec != SE->getSCEV(WideUse)) {
977 DEBUG(
dbgs() <<
"Wide use expression mismatch: " << *WideUse
978 <<
": " << *SE->getSCEV(WideUse) <<
" != " << *WideAddRec <<
"\n");
979 DeadInsts.push_back(WideUse);
991 UE = NarrowDef->
use_end(); UI != UE; ++UI) {
995 if (!Widened.insert(NarrowUse))
998 NarrowIVUsers.push_back(NarrowIVDefUse(NarrowDef, NarrowUse, WideDef));
1019 const SCEV *WideIVExpr = IsSigned ?
1020 SE->getSignExtendExpr(AddRec, WideType) :
1021 SE->getZeroExtendExpr(AddRec, WideType);
1023 assert(SE->getEffectiveSCEVType(WideIVExpr->
getType()) == WideType &&
1024 "Expect the new IV expression to preserve its type");
1028 if (!AddRec || AddRec->
getLoop() != L)
1036 &&
"Loop header phi recurrence inputs do not dominate the loop");
1043 WidePhi = cast<PHINode>(Rewriter.
expandCodeFor(AddRec, WideType, InsertPt));
1051 cast<Instruction>(WidePhi->getIncomingValueForBlock(LatchBlock));
1052 WideIncExpr = SE->getSCEV(WideInc);
1055 DEBUG(
dbgs() <<
"Wide IV: " << *WidePhi <<
"\n");
1059 assert(Widened.empty() && NarrowIVUsers.empty() &&
"expect initial state" );
1061 Widened.insert(OrigPhi);
1062 pushNarrowIVUsers(OrigPhi, WidePhi);
1064 while (!NarrowIVUsers.empty()) {
1065 NarrowIVDefUse DU = NarrowIVUsers.pop_back_val();
1073 pushNarrowIVUsers(DU.NarrowUse, WideUse);
1076 if (DU.NarrowDef->use_empty())
1077 DeadInsts.push_back(DU.NarrowDef);
1093 void IndVarSimplify::SimplifyAndExtend(
Loop *L,
1106 while (!LoopPhis.
empty()) {
1117 WideIVVisitor WIV(CurrIV, SE,
TD);
1121 if (WIV.WI.WidestNativeType) {
1124 }
while(!LoopPhis.
empty());
1127 WidenIV Widener(WideIVs.
back(),
LI, SE, DT, DeadInsts);
1128 if (
PHINode *WidePhi = Widener.CreateWideIV(Rewriter)) {
1146 if (!Processed.
insert(S))
1154 if (isa<SCEVUDivExpr>(S)) {
1156 if (!OrigCond)
return true;
1170 if (
const SCEVAddExpr *Add = dyn_cast<SCEVAddExpr>(S)) {
1181 if (isa<SCEVSMaxExpr>(S) || isa<SCEVUMaxExpr>(S))
1204 if (isa<SCEVCouldNotCompute>(BackedgeTakenCount) ||
1205 BackedgeTakenCount->
isZero())
1231 case Instruction::Add:
1232 case Instruction::Sub:
1234 case Instruction::GetElementPtr:
1248 if (IncI->
getOpcode() == Instruction::GetElementPtr)
1270 assert(BI &&
"expected exit branch");
1319 if (isa<Constant>(V))
1320 return !isa<UndefValue>(V);
1337 if (!Visited.
insert(*OI))
1364 if (*UI != Cond && *UI != IncV)
return false;
1369 if (*UI != Cond && *UI != Phi)
return false;
1393 cast<BranchInst>(L->
getExitingBlock()->getTerminator())->getCondition();
1397 const SCEV *BestInit = 0;
1399 assert(LatchBlock &&
"needsLFTR should guarantee a loop latch");
1422 if (!Step || !Step->
isOne())
1445 if (BestPhi && !
AlmostDeadIV(BestPhi, LatchBlock, Cond)) {
1459 else if (PhiWidth <= SE->getTypeSizeInBits(BestPhi->
getType()))
1473 assert(AR && AR->
getLoop() == L && AR->
isAffine() &&
"bad loop counter");
1494 "Computed iteration count is not loop invariant!");
1503 cast<PointerType>(GEPBase->
getType())->getElementType())->isOne()
1504 &&
"unit stride pointer IV must be i8*");
1507 return Builder.
CreateGEP(GEPBase, GEPOffset,
"lftr.limit");
1521 const SCEV *IVLimit = 0;
1541 "Computed iteration count is not loop invariant!");
1556 Value *IndVarSimplify::
1557 LinearFunctionTestReplace(
Loop *L,
1558 const SCEV *BackedgeTakenCount,
1564 Value *CmpIndVar = IndVar;
1565 const SCEV *IVCount = BackedgeTakenCount;
1574 IVCount = SE->getAddExpr(BackedgeTakenCount,
1575 SE->getConstant(BackedgeTakenCount->
getType(), 1));
1584 &&
"genLoopLimit missed a cast");
1589 if (L->
contains(BI->getSuccessor(0)))
1594 DEBUG(
dbgs() <<
"INDVARS: Rewriting loop exit condition to:\n"
1595 <<
" LHS:" << *CmpIndVar <<
'\n'
1598 <<
" RHS:\t" << *ExitCnt <<
"\n"
1599 <<
" IVCount:\t" << *IVCount <<
"\n");
1605 unsigned CmpIndVarSize = SE->getTypeSizeInBits(CmpIndVar->
getType());
1606 unsigned ExitCntSize = SE->getTypeSizeInBits(ExitCnt->
getType());
1607 if (CmpIndVarSize > ExitCntSize) {
1608 const SCEVAddRecExpr *AR = cast<SCEVAddRecExpr>(SE->getSCEV(IndVar));
1612 if (isa<SCEVConstant>(ARStart) && isa<SCEVConstant>(IVCount)) {
1613 const APInt &Start = cast<SCEVConstant>(ARStart)->getValue()->getValue();
1614 APInt Count = cast<SCEVConstant>(IVCount)->getValue()->getValue();
1617 if (IVCount != BackedgeTakenCount && Count == 0) {
1622 Count = Count.
zext(CmpIndVarSize);
1624 if (cast<SCEVConstant>(ARStep)->getValue()->isNegative())
1625 NewLimit = Start - Count;
1627 NewLimit = Start + Count;
1630 DEBUG(
dbgs() <<
" Widen RHS:\t" << *ExitCnt <<
"\n");
1632 CmpIndVar = Builder.CreateTrunc(CmpIndVar, ExitCnt->
getType(),
1636 Value *Cond = Builder.CreateICmp(P, CmpIndVar, ExitCnt,
"exitcond");
1637 Value *OrigCond = BI->getCondition();
1643 BI->setCondition(Cond);
1644 DeadInsts.push_back(OrigCond);
1658 void IndVarSimplify::SinkUnusedInvariants(
Loop *L) {
1660 if (!ExitBlock)
return;
1663 if (!Preheader)
return;
1667 while (I != Preheader->
begin()) {
1670 if (isa<PHINode>(I))
1679 if (I->mayHaveSideEffects() || I->mayReadFromMemory())
1683 if (isa<DbgInfoIntrinsic>(I))
1687 if (isa<LandingPadInst>(I))
1694 if (isa<AllocaInst>(I))
1699 bool UsedInLoop =
false;
1704 if (
PHINode *P = dyn_cast<PHINode>(U)) {
1707 UseBB = P->getIncomingBlock(i);
1709 if (UseBB == Preheader || L->
contains(UseBB)) {
1723 if (I != Preheader->
begin()) {
1727 }
while (isa<DbgInfoIntrinsic>(I) && I != Preheader->
begin());
1729 if (isa<DbgInfoIntrinsic>(I) && I == Preheader->
begin())
1757 LI = &getAnalysis<LoopInfo>();
1758 SE = &getAnalysis<ScalarEvolution>();
1759 DT = &getAnalysis<DominatorTree>();
1760 TD = getAnalysisIfAvailable<DataLayout>();
1761 TLI = getAnalysisIfAvailable<TargetLibraryInfo>();
1768 RewriteNonIntegerIVs(L);
1770 const SCEV *BackedgeTakenCount = SE->getBackedgeTakenCount(L);
1785 SimplifyAndExtend(L, Rewriter, LPM);
1793 if (!isa<SCEVCouldNotCompute>(BackedgeTakenCount))
1794 RewriteLoopExitValues(L, Rewriter);
1814 (
void)LinearFunctionTestReplace(L, BackedgeTakenCount, IndVar,
1825 while (!DeadInsts.empty())
1827 dyn_cast_or_null<Instruction>(&*DeadInsts.pop_back_val()))
1834 SinkUnusedInvariants(L);
1840 "Indvars did not leave the loop in lcssa form!");
1845 if (
VerifyIndvars && !isa<SCEVCouldNotCompute>(BackedgeTakenCount)) {
1847 const SCEV *NewBECount = SE->getBackedgeTakenCount(L);
1848 if (SE->getTypeSizeInBits(BackedgeTakenCount->
getType()) <
1849 SE->getTypeSizeInBits(NewBECount->
getType()))
1850 NewBECount = SE->getTruncateOrNoop(NewBECount,
1851 BackedgeTakenCount->
getType());
1853 BackedgeTakenCount = SE->getTruncateOrNoop(BackedgeTakenCount,
1855 assert(BackedgeTakenCount == NewBECount &&
"indvars must preserve SCEV");
bool isInt< 32 >(int64_t x)
Value * CreateGEP(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
void push_back(const T &Elt)
bool hoistIVInc(Instruction *IncV, Instruction *InsertPos)
hoistIVInc - Utility for hoisting an IV increment.
Induction Variable Simplification
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
AnalysisUsage & addPreserved()
void addIncoming(Value *V, BasicBlock *BB)
static PassRegistry * getPassRegistry()
static bool isLoopInvariant(Value *V, const Loop *L, const DominatorTree *DT)
const SCEV * getConstant(ConstantInt *V)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getNumOperands() const
bool hasNoSignedWrap() const
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=0)
static Instruction * getInsertPointForUses(Instruction *User, Value *Def, DominatorTree *DT)
0 1 0 0 True if ordered and less than
bool properlyDominates(const DomTreeNode *A, const DomTreeNode *B) const
const SCEV * getStepRecurrence(ScalarEvolution &SE) const
1 1 1 0 True if unordered or not equal
void setDebugType(const char *s)
bool isLoopInvariant(const SCEV *S, const Loop *L)
LoopT * getParentLoop() const
static IntegerType * getInt64Ty(LLVMContext &C)
static bool canExpandBackedgeTakenCount(Loop *L, ScalarEvolution *SE)
BlockT * getExitBlock() const
static bool hasConcreteDef(Value *V)
static bool hasConcreteDefImpl(Value *V, SmallPtrSet< Value *, 8 > &Visited, unsigned Depth)
BlockT * getHeader() const
LoopInfoBase< BlockT, LoopT > * LI
const SCEV * getStart() const
StringRef getName() const
BlockT * getLoopLatch() const
1 0 0 1 True if unordered or equal
static Value * genLoopLimit(PHINode *IndVar, const SCEV *IVCount, Loop *L, SCEVExpander &Rewriter, ScalarEvolution *SE)
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Base class of casting instructions.
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
opStatus convertToInteger(integerPart *, unsigned int, bool, roundingMode, bool *) const
static bool ConvertToSInt(const APFloat &APF, int64_t &IntVal)
ConvertToSInt - Convert APF to an integer, if possible.
const SCEV *const * op_iterator
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static bool isHighCostExpansion(const SCEV *S, BranchInst *BI, SmallPtrSet< const SCEV *, 8 > &Processed, ScalarEvolution *SE)
0 1 0 1 True if ordered and less than or equal
uint64_t getTypeSizeInBits(Type *Ty) const
ID
LLVM Calling Convention Representation.
Instruction * clone() const
bool isLoopSimplifyForm() const
bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, LPPassManager *LPM, SmallVectorImpl< WeakVH > &Dead, IVVisitor *V=NULL)
bool mayReadFromMemory() const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
Represents a floating point comparison operator.
static cl::opt< bool > VerifyIndvars("verify-indvars", cl::Hidden, cl::desc("Verify the ScalarEvolution result after running indvars"))
BasicBlock * getSuccessor(unsigned i) const
const SCEV * getSizeOfExpr(Type *IntTy, Type *AllocTy)
AnalysisUsage & addPreservedID(const void *ID)
void replaceAllUsesWith(Value *V)
Type * getEffectiveSCEVType(Type *Ty) const
unsigned getNumIncomingValues() const
STATISTIC(NumWidened,"Number of indvars widened")
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
bool isSCEVable(Type *Ty) const
BlockT * getLoopPreheader() const
void insertBefore(Instruction *InsertPos)
LLVM Basic Block Representation.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=0)
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=0)
BasicBlock * getIncomingBlock(unsigned i) const
bool contains(const LoopT *L) const
Represent an integer comparison operator.
const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
getMinusSCEV - Return LHS-RHS. Minus is represented in SCEV as A+B*-1.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Value * expandCodeFor(const SCEV *SH, Type *Ty, Instruction *I)
BlockT * getExitingBlock() const
Value * getOperand(unsigned i) const
Integer representation type.
Predicate getPredicate() const
Return the predicate for this instruction.
bool dominates(const DomTreeNode *A, const DomTreeNode *B) const
static UndefValue * get(Type *T)
void getUniqueExitBlocks(SmallVectorImpl< BasicBlock * > &ExitBlocks) const
LLVMContext & getContext() const
All values hold a context through their type.
static unsigned getIncomingValueNumForOperand(unsigned i)
static ICmpInst * getLoopTest(Loop *L)
Return the compare guarding the loop latch, or NULL for unrecognized tests.
1 1 0 1 True if unordered, less than, or equal
unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT, SmallVectorImpl< WeakVH > &DeadInsts, const TargetTransformInfo *TTI=NULL)
bool isConditional() const
0 0 1 0 True if ordered and greater than
INITIALIZE_PASS_BEGIN(IndVarSimplify,"indvars","Induction Variable Simplification", false, false) INITIALIZE_PASS_END(IndVarSimplify
BinaryOps getOpcode() const
Value * getIncomingValue(unsigned i) const
const SCEV * getTruncateExpr(const SCEV *Op, Type *Ty)
AnalysisUsage & addRequiredID(const void *ID)
bool isLCSSAForm(DominatorTree &DT) const
isLCSSAForm - Return true if the Loop is in LCSSA form
1 1 0 0 True if unordered or less than
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
static PHINode * getLoopPhiForCounter(Value *IncV, Loop *L, DominatorTree *DT)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Class for arbitrary precision integers.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
void initializeIndVarSimplifyPass(PassRegistry &)
const SCEV * getAddExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
static APInt getMaxValue(unsigned numBits)
Gets maximum unsigned value of APInt for specific bit width.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
Virtual Register Rewriter
static PHINode * FindLoopCounter(Loop *L, const SCEV *BECount, ScalarEvolution *SE, DominatorTree *DT, const DataLayout *TD)
Value * getCondition() const
static IntegerType * getInt32Ty(LLVMContext &C)
bool isLegalInteger(unsigned Width) const
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
0 1 1 0 True if ordered and operands are unequal
static bool needsLFTR(Loop *L, DominatorTree *DT)
BasicBlock * findNearestCommonDominator(BasicBlock *A, BasicBlock *B)
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=0)
const Loop * getLoop() const
1 0 1 0 True if unordered or greater than
const APFloat & getValueAPF() const
const SCEV * getBackedgeTakenCount(const Loop *L)
This class represents a cast from signed integer to floating point.
unsigned getSCEVType() const
0 0 0 1 True if ordered and equal
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
const SCEV * getSCEV(Value *V)
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
static bool AlmostDeadIV(PHINode *Phi, BasicBlock *LatchBlock, Value *Cond)
static const Function * getParent(const Value *V)
void moveBefore(Instruction *MovePos)
bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI=0)
void disableCanonicalMode()
APInt LLVM_ATTRIBUTE_UNUSED_RESULT zext(unsigned width) const
Zero extend to a new width.
const SCEV * getTruncateOrZeroExtend(const SCEV *V, Type *Ty)
iterator getFirstInsertionPt()
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
void setIncomingValue(unsigned i, Value *V)
bool isSafeToExpand(const SCEV *S, ScalarEvolution &SE)
0 0 1 1 True if ordered and greater than or equal
int getBasicBlockIndex(const BasicBlock *BB) const
const BasicBlock * getParent() const
INITIALIZE_PASS(GlobalMerge,"global-merge","Global Merge", false, false) bool GlobalMerge const DataLayout * TD
Pass * createIndVarSimplifyPass()
bool hasNoUnsignedWrap() const