From 82ce118743cbd8f8261b6fb38fe0b0ec08d2030b Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 17 Jul 2024 21:23:34 +0200 Subject: [PATCH] JIT: Check return value of `InitializeCursors` (#105017) We were missing checking the return value of `InitializeCursors`. Typically this would just cause us to end up with an empty set of cursors as we abort the search as soon as we fail to create one cursor, and the cursor we would typically fail to create is always the first one. Running the next logic with an empty set of cursors causes no ill effects, so this has no diffs. --- src/coreclr/jit/inductionvariableopts.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/inductionvariableopts.cpp b/src/coreclr/jit/inductionvariableopts.cpp index 417632ad79f06..52258326ef5cb 100644 --- a/src/coreclr/jit/inductionvariableopts.cpp +++ b/src/coreclr/jit/inductionvariableopts.cpp @@ -1339,7 +1339,10 @@ bool StrengthReductionContext::TryStrengthReduce() ScevAddRec* primaryIV = static_cast(candidate); - InitializeCursors(primaryIVLcl, primaryIV); + if (!InitializeCursors(primaryIVLcl, primaryIV)) + { + continue; + } ArrayStack* cursors = &m_cursors1; ArrayStack* nextCursors = &m_cursors2; @@ -1517,7 +1520,7 @@ bool StrengthReductionContext::InitializeCursors(GenTreeLclVarCommon* primaryIVL if (!m_loopLocals.VisitOccurrences(m_loop, primaryIVLcl->GetLclNum(), visitor) || (m_cursors1.Height() <= 0)) { - JITDUMP(" Could not create cursors for all loop uses of primary IV"); + JITDUMP(" Could not create cursors for all loop uses of primary IV\n"); return false; }