LoopUnroller: Also handle > exit condition

This commit is contained in:
Arnold Schwaighofer
2017-04-22 17:32:30 -07:00
parent 533044d4c4
commit cafe58251e
2 changed files with 49 additions and 3 deletions

View File

@@ -126,13 +126,23 @@ static Optional<uint64_t> getMaxLoopTripCount(SILLoop *Loop,
IntegerLiteralInst *End;
SILValue RecNext;
unsigned Adjust = 0;
if (!match(CondBr->getCondition(),
m_BuiltinInst(BuiltinValueKind::ICMP_EQ, m_SILValue(RecNext),
m_IntegerLiteralInst(End))) &&
!match(CondBr->getCondition(),
m_BuiltinInst(BuiltinValueKind::ICMP_SGE, m_SILValue(RecNext),
m_IntegerLiteralInst(End))))
return None;
m_IntegerLiteralInst(End)))) {
if (!match(CondBr->getCondition(),
m_BuiltinInst(BuiltinValueKind::ICMP_SGT, m_SILValue(RecNext),
m_IntegerLiteralInst(End))))
return None;
// Otherwise, we have a greater than comparison.
else
Adjust = 1;
}
if (!match(RecNext,
m_TupleExtractInst(m_ApplyInst(BuiltinValueKind::SAddOver,
m_SILPHIArgument(RecArg), m_One()),
@@ -162,7 +172,7 @@ static Optional<uint64_t> getMaxLoopTripCount(SILLoop *Loop,
if (Dist == 0)
return None;
return Dist.getZExtValue();
return Dist.getZExtValue() + Adjust;
}
/// Check whether we can duplicate the instructions in the loop and use a