-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[LVA] Support access instructions in DCE. #31133
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
Conversation
0c80a1f
to
167d992
Compare
|
||
if (isa<EndAccessInst>(I)) | ||
return I->getOperand(0)->getSingleUse() == 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.
This will work.
But a better approach would be to add an end_access with a reverse dependency to begin_access.
Usually an instruction is dead of all its uses are dead. With a reverse dependency an instruction is dead if it's operand is dead. And that's what we want for end_access: it should be removed if the its operand (= the begin_access) is dead.
See the handling of cond_fail and fix_lifetime in DCE as examples.
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.
Yes, you're right, that would be better. Will do.
} | ||
continue; | ||
} | ||
if (auto access = dyn_cast<BeginAccessInst>(&I)) { |
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.
begin_access is marked as having side effects so, I still have to have this bit of logic.
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.
That logic looks wrong. It should be sufficient to exclude begin_access in seemsUseful().
If there is a use (other than end_access), the begin_access will be marked as life in propagateLiveness().
@@ -258,6 +258,19 @@ void DCE::markLive(SILFunction &F) { | |||
} | |||
continue; | |||
} | |||
if (isa<EndAccessInst>(&I)) { | |||
if (auto *access = dyn_cast<BeginAccessInst>(I.getOperand(0))) { |
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.
The operand of an end_access must be a begin_access. You can use EndAccessInst::getBeginAccess() to get it.
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.
Good to know. My thinking was that there could be a phi argument or something. Is that not valid?
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.
No, it must be a begin_access
} | ||
continue; | ||
} | ||
if (auto access = dyn_cast<BeginAccessInst>(&I)) { |
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.
That logic looks wrong. It should be sufficient to exclude begin_access in seemsUseful().
If there is a use (other than end_access), the begin_access will be marked as life in propagateLiveness().
6d08cb9
to
4d4771f
Compare
@@ -40,6 +40,11 @@ namespace { | |||
// FIXME: Reconcile the similarities between this and | |||
// isInstructionTriviallyDead. | |||
static bool seemsUseful(SILInstruction *I) { | |||
// We have a reverse dependency for end_access. If there are no uses of a | |||
// begin_access, both will be removed. |
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.
nitpick: Can you change this comment to something like: "begin_access is defined to have side effects, but this is not relevant for DCE."
Because this is the reason why you have to handle begin_access here.
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.
Fair enough. Done.
Simple check for the following pattern: x = begin_access end_access x
4d4771f
to
e22e7bc
Compare
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.
LGTM, thanks!
@swift-ci please smoke test and merge |
A simple check for the following pattern: