-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstCombine] Re-queue users of phi when nsw/nuw flags of add are inferred #113933
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
60e6592
d2a5040
890632e
faeb757
a8c1198
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 |
---|---|---|
|
@@ -1868,6 +1868,15 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) { | |
if (Instruction *Res = foldBinOpOfSelectAndCastOfSelectCondition(I)) | ||
return Res; | ||
|
||
// Re-enqueue users of the induction variable of add recurrence if we infer | ||
// new nuw/nsw flags. | ||
if (Changed) { | ||
PHINode *PHI; | ||
Value *Start, *Step; | ||
if (matchSimpleRecurrence(&I, PHI, Start, Step)) | ||
Worklist.pushUsersToWorkList(*PHI); | ||
} | ||
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. This obviously has a positive effect, but I don't quite understand why this isn't already handled by 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.
Take the above case as an example. If the add instruction is updated, 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. Oh yeah duh |
||
|
||
return Changed ? &I : nullptr; | ||
} | ||
|
||
|
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.
We're only interested in recurrence phis here, right? So can we check first if an add operand is a phi, and then whether it is in the user list? That way we can avoid the full users scan in most cases.
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.
Sorry for not mentioning it earlier, but I think the cleanest way to do this is to use matchSimpleRecurrence to get the PHINode. If it's not a simple recurrence we're unlikely to get anything useful out of it anyway.
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.
Done.