-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[LV] Vectorize conditional scalar assignments #158088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,8 @@ bool RecurrenceDescriptor::isIntegerRecurrenceKind(RecurKind Kind) { | |
case RecurKind::FindFirstIVUMin: | ||
case RecurKind::FindLastIVSMax: | ||
case RecurKind::FindLastIVUMax: | ||
// TODO: Make type-agnostic. | ||
case RecurKind::FindLast: | ||
return true; | ||
} | ||
return false; | ||
|
@@ -426,6 +428,8 @@ bool RecurrenceDescriptor::AddReductionVar( | |
++NumCmpSelectPatternInst; | ||
if (isAnyOfRecurrenceKind(Kind) && IsASelect) | ||
++NumCmpSelectPatternInst; | ||
if (isFindLastRecurrenceKind(Kind) && IsASelect) | ||
++NumCmpSelectPatternInst; | ||
Comment on lines
+431
to
+432
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we need this? |
||
|
||
// Check whether we found a reduction operator. | ||
FoundReduxOp |= !IsAPhi && Cur != Start; | ||
|
@@ -789,6 +793,38 @@ RecurrenceDescriptor::isFindIVPattern(RecurKind Kind, Loop *TheLoop, | |
return InstDesc(false, I); | ||
} | ||
|
||
RecurrenceDescriptor::InstDesc | ||
RecurrenceDescriptor::isFindLastPattern(Instruction *I, PHINode *Phi, | ||
Loop *TheLoop) { | ||
Comment on lines
+797
to
+798
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we reuse RecurrenceDescriptor::isFindIVPattern? |
||
// Must be a scalar. | ||
Type *Type = Phi->getType(); | ||
if (!Type->isIntegerTy() && !Type->isFloatingPointTy() && | ||
!Type->isPointerTy()) | ||
return InstDesc(false, I); | ||
|
||
SelectInst *Select = dyn_cast<SelectInst>(I); | ||
if (!Select) | ||
return InstDesc(false, I); | ||
|
||
// FIXME: Support more complex patterns, including multiple selects. | ||
// Phi or Select must be used only outside the loop, | ||
// except for each other. | ||
auto IsOnlyUsedOutsideLoop = [&](Value *V, Value *Ignore) { | ||
return all_of(V->users(), [Ignore, TheLoop](User *U) { | ||
if (U == Ignore) | ||
return true; | ||
if (auto *I = dyn_cast<Instruction>(U)) | ||
return !TheLoop->contains(I); | ||
return false; | ||
}); | ||
}; | ||
if (!IsOnlyUsedOutsideLoop(Phi, Select) || | ||
!IsOnlyUsedOutsideLoop(Select, Phi)) | ||
return InstDesc(false, I); | ||
|
||
return InstDesc(I, RecurKind::FindLast); | ||
} | ||
|
||
RecurrenceDescriptor::InstDesc | ||
RecurrenceDescriptor::isMinMaxPattern(Instruction *I, RecurKind Kind, | ||
const InstDesc &Prev) { | ||
|
@@ -927,6 +963,8 @@ RecurrenceDescriptor::InstDesc RecurrenceDescriptor::isRecurrenceInstr( | |
return isConditionalRdxPattern(I); | ||
if (isFindIVRecurrenceKind(Kind) && SE) | ||
return isFindIVPattern(Kind, L, OrigPhi, I, *SE); | ||
if (isFindLastRecurrenceKind(Kind)) | ||
return isFindLastPattern(I, OrigPhi, L); | ||
[[fallthrough]]; | ||
case Instruction::FCmp: | ||
case Instruction::ICmp: | ||
|
@@ -1123,7 +1161,11 @@ bool RecurrenceDescriptor::isReductionPHI(PHINode *Phi, Loop *TheLoop, | |
<< "\n"); | ||
return true; | ||
} | ||
|
||
if (AddReductionVar(Phi, RecurKind::FindLast, TheLoop, FMF, RedDes, DB, AC, | ||
DT, SE)) { | ||
LLVM_DEBUG(dbgs() << "Found a FindLast reduction PHI." << *Phi << "\n"); | ||
return true; | ||
} | ||
// Not a reduction of known type. | ||
return false; | ||
} | ||
|
@@ -1245,6 +1287,7 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) { | |
case RecurKind::SMin: | ||
case RecurKind::UMax: | ||
case RecurKind::UMin: | ||
case RecurKind::FindLast: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #162252 |
||
return Instruction::ICmp; | ||
case RecurKind::FMax: | ||
case RecurKind::FMin: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since isIntegerRecurrenceKind returns true for FindLast, I suggest