Skip to content

Commit 8ce79f5

Browse files
committed
IVDescriptors: cut wasteful FAnyOf checking (NFC)
Checking RecurKind::FAnyOf in isRecurrenceDescriptor() is wasted work when it already checks RecurKind::IAnyOf. Affect a minor adjustment to the code to facilitate skipping the RecurKind::FAnyOf check, and strip the check. The patch has the side-effect of rewriting some flaky code, which would match an ICmp having the reduction phi as an operand with IAnyOf, and due to NumCmpSelectPatternInst != 1 (the select redux is also matched), it would have to rely on failing to match an FCmp with FAnyOf, setting NumCmpSelectPatternInst = 1, and successfully vectorizing an IAnyOf pattern with the incorrect debug output. There is a test for this already in select-cmp.ll: select_i32_from_icmp_same_inputs.
1 parent 4e8eabd commit 8ce79f5

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,9 @@ bool RecurrenceDescriptor::AddReductionVar(
415415
if (IsAPhi && Cur != Phi && !areAllUsesIn(Cur, VisitedInsts))
416416
return false;
417417

418-
if ((isIntMinMaxRecurrenceKind(Kind) || Kind == RecurKind::IAnyOf) &&
419-
(isa<ICmpInst>(Cur) || isa<SelectInst>(Cur)))
420-
++NumCmpSelectPatternInst;
421-
if ((isFPMinMaxRecurrenceKind(Kind) || Kind == RecurKind::FAnyOf) &&
422-
(isa<FCmpInst>(Cur) || isa<SelectInst>(Cur)))
423-
++NumCmpSelectPatternInst;
418+
if (isIntMinMaxRecurrenceKind(Kind) || isAnyOfRecurrenceKind(Kind))
419+
if (match(Cur, m_Select(m_Cmp(), m_Value(), m_Value())))
420+
++NumCmpSelectPatternInst;
424421

425422
// Check whether we found a reduction operator.
426423
FoundReduxOp |= !IsAPhi && Cur != Start;
@@ -500,7 +497,7 @@ bool RecurrenceDescriptor::AddReductionVar(
500497
// This means we have seen one but not the other instruction of the
501498
// pattern or more than just a select and cmp. Zero implies that we saw a
502499
// llvm.min/max intrinsic, which is always OK.
503-
if (isMinMaxRecurrenceKind(Kind) && NumCmpSelectPatternInst != 2 &&
500+
if (isMinMaxRecurrenceKind(Kind) && NumCmpSelectPatternInst != 1 &&
504501
NumCmpSelectPatternInst != 0)
505502
return false;
506503

@@ -889,8 +886,8 @@ bool RecurrenceDescriptor::isReductionPHI(PHINode *Phi, Loop *TheLoop,
889886
}
890887
if (AddReductionVar(Phi, RecurKind::IAnyOf, TheLoop, FMF, RedDes, DB, AC, DT,
891888
SE)) {
892-
LLVM_DEBUG(dbgs() << "Found an integer conditional select reduction PHI."
893-
<< *Phi << "\n");
889+
LLVM_DEBUG(dbgs() << "Found an conditional select reduction PHI." << *Phi
890+
<< "\n");
894891
return true;
895892
}
896893
if (AddReductionVar(Phi, RecurKind::FMul, TheLoop, FMF, RedDes, DB, AC, DT,
@@ -913,12 +910,6 @@ bool RecurrenceDescriptor::isReductionPHI(PHINode *Phi, Loop *TheLoop,
913910
LLVM_DEBUG(dbgs() << "Found a float MIN reduction PHI." << *Phi << "\n");
914911
return true;
915912
}
916-
if (AddReductionVar(Phi, RecurKind::FAnyOf, TheLoop, FMF, RedDes, DB, AC, DT,
917-
SE)) {
918-
LLVM_DEBUG(dbgs() << "Found a float conditional select reduction PHI."
919-
<< " PHI." << *Phi << "\n");
920-
return true;
921-
}
922913
if (AddReductionVar(Phi, RecurKind::FMulAdd, TheLoop, FMF, RedDes, DB, AC, DT,
923914
SE)) {
924915
LLVM_DEBUG(dbgs() << "Found an FMulAdd reduction PHI." << *Phi << "\n");

0 commit comments

Comments
 (0)