This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][analysis] Fix error in the sparse backward dataflow analysis
ClosedPublic

Authored by srishti-pm on Jul 26 2023, 2:54 PM.

Details

Summary

Earlier, in the sparse backward dataflow analysis, data from the results
of an op implementing RegionBranchOpInterface was considered to flow
into the operands of every op that did not implement the
RegionBranchTerminatorOpInterface but was return-like and present
in a region of the former. It was thus also expected that the number of
results of the former be equal to the number of operands in the latter.

This understanding of dataflow is incorrect and thus this expectation is
also not justified. This commit fixes this incorrect understanding.

This commit ensures that these return-like ops are handled just like the
ops implementing the RegionBranchTerminatorOpInterface, which means
that, if this op has a region A whose successors are regions B, C,
and D, then data flows from the arguments (successor inputs) of B,
C, and D to the corresponding successor operands of this op.

This fix is also propagated to liveness analysis that earlier relied on
this incorrect implementation of the sparse backward dataflow analysis
framework and corrects some incorrect assumptions made in it.

Also cleaned up some unnecessary comments from the test file.

Issue: https://github.com/llvm/llvm-project/issues/64139.

Signed-off-by: Srishti Srivastava <srishtisrivastava.ai@gmail.com>

Diff Detail

Event Timeline

srishti-pm created this revision.Jul 26 2023, 2:54 PM
Herald added a project: Restricted Project. · View Herald Transcript
srishti-pm requested review of this revision.Jul 26 2023, 2:54 PM
srishti-pm edited the summary of this revision. (Show Details)Jul 26 2023, 4:13 PM
srishti-pm edited the summary of this revision. (Show Details)
mehdi_amini retitled this revision from [MLIR][ANALYSIS] Fix error in the sparse backward dataflow analysis to [MLIR][analysis] Fix error in the sparse backward dataflow analysis.Jul 26 2023, 9:02 PM
mehdi_amini added a reviewer: Mogball.
matthiaskramm accepted this revision.Jul 28 2023, 11:45 AM
This revision is now accepted and ready to land.Jul 28 2023, 11:45 AM
Mogball accepted this revision.Jul 28 2023, 11:47 AM

LGTM thanks!

Rebased to main.

Fix commit email id

srishti-pm edited the summary of this revision. (Show Details)Jul 28 2023, 2:07 PM

Fix typo in commit summary

srishti-pm edited the summary of this revision. (Show Details)Jul 28 2023, 4:31 PM
jcai19 accepted this revision.Jul 28 2023, 4:43 PM

nit: we could consider adding definition of "successor operand" in the comments, as this might not be clear to readers who are not familiar with terminology in MLIR dataflow analysis. I think even something as brief as "A successor operand is an operand that is forwarded to a region successor's input. There are two types of successor operands: the operands of the scf.while op itself and the operands of the terminators of the regions of the scf.while op" would go a long way helping people understand this change.

nit: we could consider adding definition of "successor operand" in the comments, as this might not be clear to readers who are not familiar with terminology in MLIR dataflow analysis. I think even something as brief as "A successor operand is an operand that is forwarded to a region successor's input. There are two types of successor operands: the operands of the scf.while op itself and the operands of the terminators of the regions of the scf.while op" would go a long way helping people understand this change.

Sure, I'll do this.

Add a comment explaining "successor operands".