@@ -664,9 +664,9 @@ RecurrenceDescriptor::isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
664664// if (src[i] > 3)
665665// r = i;
666666// }
667- // The reduction value (r) is derived from either the values of an increasing
668- // induction variable (i) sequence, or from the start value (0).
669- // The LLVM IR generated for such loops would be as follows:
667+ // The reduction value (r) is derived from either the values of an induction
668+ // variable (i) sequence, or from the start value (0). The LLVM IR generated for
669+ // such loops would be as follows:
670670// for.body:
671671// %r = phi i32 [ %spec.select, %for.body ], [ 0, %entry ]
672672// %i = phi i32 [ %inc, %for.body ], [ 0, %entry ]
@@ -675,13 +675,13 @@ RecurrenceDescriptor::isAnyOfPattern(Loop *Loop, PHINode *OrigPhi,
675675// %spec.select = select i1 %cmp, i32 %i, i32 %r
676676// %inc = add nsw i32 %i, 1
677677// ...
678- // Since 'i' is an increasing induction variable, the reduction value after the
679- // loop will be the maximum value of 'i' that the condition (src[i] > 3) is
680- // satisfied, or the start value (0 in the example above). When the start value
681- // of the increasing induction variable 'i' is greater than the minimum value of
682- // the data type, we can use the minimum value of the data type as a sentinel
683- // value to replace the start value. This allows us to perform a single
684- // reduction max operation to obtain the final reduction result.
678+ // Since 'i' is an induction variable, the reduction value after the loop will
679+ // be the maximum value of 'i' that the condition (src[i] > 3) is satisfied, or
680+ // the start value (0 in the example above). When the start value of the
681+ // induction variable 'i' is greater than the minimum value of the data type, we
682+ // can use the minimum value of the data type as a sentinel value to replace the
683+ // start value. This allows us to perform a single reduction max operation to
684+ // obtain the final reduction result.
685685// TODO: It is possible to solve the case where the start value is the minimum
686686// value of the data type or a non-constant value by using mask and multiple
687687// reduction operations.
@@ -696,6 +696,9 @@ RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop,
696696 if (!OrigPhi->hasOneUse ())
697697 return InstDesc (false , I);
698698
699+ // We are looking for selects of the form:
700+ // select(cmp(), phi, loop_induction) or
701+ // select(cmp(), loop_induction, phi)
699702 // TODO: Match selects with multi-use cmp conditions.
700703 Value *NonRdxPhi = nullptr ;
701704 if (!match (I, m_CombineOr (m_Select (m_OneUse (m_Cmp ()), m_Value (NonRdxPhi),
@@ -704,8 +707,8 @@ RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop,
704707 m_Value (NonRdxPhi)))))
705708 return InstDesc (false , I);
706709
707- // Returns a non-nullopt boolean indicating the signedness of the recurrence
708- // when a valid FindLastIV pattern is found .
710+ // Returns either FindFirstIV/FindLastIV, if such a pattern is found, or
711+ // std::nullopt .
709712 auto GetRecurKind = [&](Value *V) -> std::optional<RecurKind> {
710713 Type *Ty = V->getType ();
711714 if (!SE.isSCEVable (Ty))
@@ -775,9 +778,6 @@ RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop,
775778 return std::nullopt ;
776779 };
777780
778- // We are looking for selects of the form:
779- // select(cmp(), phi, loop_induction) or
780- // select(cmp(), loop_induction, phi)
781781 if (auto RK = GetRecurKind (NonRdxPhi))
782782 return InstDesc (I, *RK);
783783
0 commit comments