-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[VPlan] Allow folding not (cmp eq) -> icmp ne with other select users #154497
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
Changes from all commits
e481816
9734853
576f634
0fbd1bd
8073742
edc5fb2
a7df17e
7503131
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 | ||||
---|---|---|---|---|---|---|
|
@@ -1107,13 +1107,29 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) { | |||||
return Def->replaceAllUsesWith(A); | ||||||
|
||||||
// Try to fold Not into compares by adjusting the predicate in-place. | ||||||
if (isa<VPWidenRecipe>(A) && A->getNumUsers() == 1) { | ||||||
auto *WideCmp = cast<VPWidenRecipe>(A); | ||||||
if (WideCmp->getOpcode() == Instruction::ICmp || | ||||||
WideCmp->getOpcode() == Instruction::FCmp) { | ||||||
if (auto *WideCmp = dyn_cast<VPWidenRecipe>(A)) { | ||||||
if ((WideCmp->getOpcode() == Instruction::ICmp || | ||||||
WideCmp->getOpcode() == Instruction::FCmp) && | ||||||
all_of(WideCmp->users(), [&WideCmp](VPUser *U) { | ||||||
return match(U, m_CombineOr(m_Not(m_Specific(WideCmp)), | ||||||
m_Select(m_Specific(WideCmp), | ||||||
m_VPValue(), m_VPValue()))); | ||||||
})) { | ||||||
WideCmp->setPredicate( | ||||||
CmpInst::getInversePredicate(WideCmp->getPredicate())); | ||||||
Def->replaceAllUsesWith(WideCmp); | ||||||
for (VPUser *U : to_vector(WideCmp->users())) { | ||||||
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.
Suggested change
Not sure if the to_vector is necessary, as RAUW/setOperand doesn't invalidate the iterator. 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. The replaceAllUsesWith on line 1131 invalidates it though 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. Isn't there a problem here with 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.
Yeah, that's what the |
||||||
auto *R = cast<VPSingleDefRecipe>(U); | ||||||
if (match(R, m_Select(m_Specific(WideCmp), m_VPValue(X), | ||||||
m_VPValue(Y)))) { | ||||||
// select (cmp pred), x, y -> select (cmp inv_pred), y, x | ||||||
R->setOperand(1, Y); | ||||||
R->setOperand(2, X); | ||||||
} else { | ||||||
// not (cmp pred) -> cmp inv_pred | ||||||
assert(match(R, m_Not(m_Specific(WideCmp))) && "Unexpected user"); | ||||||
artagnon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
R->replaceAllUsesWith(WideCmp); | ||||||
} | ||||||
} | ||||||
// If WideCmp doesn't have a debug location, use the one from the | ||||||
// negation, to preserve the location. | ||||||
if (!WideCmp->getDebugLoc() && R.getDebugLoc()) | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.