-
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 4 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,30 @@ 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 CanFold = [&A](VPUser *U) { | ||||||
| return match( | ||||||
| U, m_CombineOr(m_Not(m_Specific(A)), | ||||||
| m_Select(m_Specific(A), m_VPValue(), m_VPValue()))); | ||||||
| }; | ||||||
| if (isa<VPWidenRecipe>(A) && all_of(A->users(), CanFold)) { | ||||||
|
||||||
| auto *WideCmp = cast<VPWidenRecipe>(A); | ||||||
| if (WideCmp->getOpcode() == Instruction::ICmp || | ||||||
| WideCmp->getOpcode() == Instruction::FCmp) { | ||||||
| WideCmp->setPredicate( | ||||||
| CmpInst::getInversePredicate(WideCmp->getPredicate())); | ||||||
artagnon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| Def->replaceAllUsesWith(WideCmp); | ||||||
| for (VPUser *U : to_vector(WideCmp->users())) { | ||||||
|
Contributor
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.
Contributor
Author
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
Contributor
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
Contributor
Author
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); | ||||||
| // not (icmp eq) -> icmp ne | ||||||
| if (match(R, m_Not(m_Specific(WideCmp)))) | ||||||
| R->replaceAllUsesWith(WideCmp); | ||||||
| // select (icmp eq), x, y -> select (icmp ne), y, x | ||||||
lukel97 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| else if (match(R, m_Select(m_Specific(WideCmp), m_VPValue(X), | ||||||
| m_VPValue(Y)))) { | ||||||
artagnon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| R->setOperand(1, Y); | ||||||
| R->setOperand(2, X); | ||||||
| } else | ||||||
artagnon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| llvm_unreachable("Unexpected user"); | ||||||
| } | ||||||
| // 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.