Changeset View
Changeset View
Standalone View
Standalone View
lib/Analysis/ValueTracking.cpp
Show First 20 Lines • Show All 1,897 Lines • ▼ Show 20 Lines | if ((BO->hasNoSignedWrap() || BO->hasNoUnsignedWrap()) && | ||||
return true; | return true; | ||||
} | } | ||||
// (C ? X : Y) != 0 if X != 0 and Y != 0. | // (C ? X : Y) != 0 if X != 0 and Y != 0. | ||||
else if (SelectInst *SI = dyn_cast<SelectInst>(V)) { | else if (SelectInst *SI = dyn_cast<SelectInst>(V)) { | ||||
if (isKnownNonZero(SI->getTrueValue(), DL, Depth, Q) && | if (isKnownNonZero(SI->getTrueValue(), DL, Depth, Q) && | ||||
isKnownNonZero(SI->getFalseValue(), DL, Depth, Q)) | isKnownNonZero(SI->getFalseValue(), DL, Depth, Q)) | ||||
return true; | return true; | ||||
} | } | ||||
// PHI | |||||
else if (PHINode *PN = dyn_cast<PHINode>(V)) { | |||||
// Try and detect a recurrence that monotonically increases from a | |||||
// starting value, as these are common as induction variables. | |||||
if (PN->getNumIncomingValues() == 2) { | |||||
Value *Start = PN->getIncomingValue(0); | |||||
reames: I find the Op1 vs Op0 naming confusing. Given this is inherently zero based indexing, mind… | |||||
Value *Induction = PN->getIncomingValue(1); | |||||
if (isa<ConstantInt>(Induction) && !isa<ConstantInt>(Start)) | |||||
std::swap(Start, Induction); | |||||
if (ConstantInt *C = dyn_cast<ConstantInt>(Start)) { | |||||
if (!C->isZero() && !C->isNegative()) { | |||||
Not Done ReplyInline ActionsMight be time to introduce a isNonNegative on ConstantInt? Could be another patch. reames: Might be time to introduce a isNonNegative on ConstantInt? Could be another patch. | |||||
ConstantInt *X; | |||||
if ((match(Induction, m_NSWAdd(m_Specific(PN), m_ConstantInt(X))) || | |||||
match(Induction, m_NUWAdd(m_Specific(PN), m_ConstantInt(X)))) && | |||||
Not Done ReplyInline ActionsGiven you're starting from zero, I think you only need the NSW check. Given INT_MAX is always less than UINT_MAX, I believe the former implies the later in this case. (But we might not yet have proved it.) reames: Given you're starting from zero, I think you only need the NSW check. Given INT_MAX is always… | |||||
!X->isNegative()) | |||||
return true; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
if (!BitWidth) return false; | if (!BitWidth) return false; | ||||
APInt KnownZero(BitWidth, 0); | APInt KnownZero(BitWidth, 0); | ||||
APInt KnownOne(BitWidth, 0); | APInt KnownOne(BitWidth, 0); | ||||
computeKnownBits(V, KnownZero, KnownOne, DL, Depth, Q); | computeKnownBits(V, KnownZero, KnownOne, DL, Depth, Q); | ||||
return KnownOne != 0; | return KnownOne != 0; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,961 Lines • Show Last 20 Lines |
I find the Op1 vs Op0 naming confusing. Given this is inherently zero based indexing, mind either using that in the Op names or picking non-index based ones?