@@ -2000,7 +2000,7 @@ static bool isRemOfLoopIncrementWithLoopInvariant(
2000
2000
AddOrSub = std::nullopt;
2001
2001
AddOrSubOffset = nullptr ;
2002
2002
} else {
2003
- // Search through a NUW add/sub.
2003
+ // Search through a NUW add/sub on top of the loop increment .
2004
2004
Value *V0, *V1;
2005
2005
if (match (Incr, m_NUWAddLike (m_Value (V0), m_Value (V1))))
2006
2006
AddOrSub = true ;
@@ -2045,6 +2045,7 @@ static bool isRemOfLoopIncrementWithLoopInvariant(
2045
2045
if (!match (LoopIncrInfo->first , m_NUWAdd (m_Value (), m_Value ())))
2046
2046
return false ;
2047
2047
2048
+ // Need unique loop preheader and latch.
2048
2049
if (PN->getBasicBlockIndex (L->getLoopLatch ()) < 0 ||
2049
2050
PN->getBasicBlockIndex (L->getLoopPreheader ()) < 0 )
2050
2051
return false ;
@@ -2080,12 +2081,16 @@ static bool foldURemOfLoopIncrement(Instruction *Rem, const LoopInfo *LI,
2080
2081
AddOrSubOffset, LoopIncrPN))
2081
2082
return false ;
2082
2083
2083
- // Only non-constant remainder as the extra IV is is probably not profitable
2084
+ // Only non-constant remainder as the extra IV is probably not profitable
2084
2085
// in that case. Further, since remainder amount is non-constant, only handle
2085
2086
// case where `IncrLoopInvariant` and `Start` are 0 to entirely eliminate the
2086
2087
// rem (as opposed to just hoisting it outside of the loop).
2087
2088
//
2088
- // Potential TODO: Should we have a check for how "nested" this remainder
2089
+ // Potential TODO(1): `urem` of a const ends up as `mul` + `shift` + `add`. If
2090
+ // we can rule out register pressure and ensure this `urem` is executed each
2091
+ // iteration, its probably profitable to handle the const case as well.
2092
+ //
2093
+ // Potential TODO(2): Should we have a check for how "nested" this remainder
2089
2094
// operation is? The new code runs every iteration so if the remainder is
2090
2095
// guarded behind unlikely conditions this might not be worth it.
2091
2096
if (AddOrSub.has_value () || match (RemAmt, m_ImmConstant ()))
0 commit comments