This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Ignore effects on allocated results when checking whether the op is trivially dead.
ClosedPublic

Authored by zero9178 on Jul 15 2022, 7:11 AM.

Details

Summary

In the current state, this is only special cased for Allocation effects, but any effects on results allocated by the operation may be ignored when checking whether the op may be removed, as none of them are possible to be observed if the result is unused.

A use case for this is for IRs for languages which always initialize on allocation. To correctly model such operations, a Write as well as an Allocation effect should be placed on the result. This would prevent the Op from being deleted if unused however. This patch fixes that issue.

Diff Detail

Event Timeline

zero9178 created this revision.Jul 15 2022, 7:11 AM
zero9178 requested review of this revision.Jul 15 2022, 7:11 AM
Mogball accepted this revision.Jul 15 2022, 9:48 AM

This makes sense to me, but you might want someone else's opinion.

mlir/lib/Interfaces/SideEffectInterfaces.cpp
66–67
This revision is now accepted and ready to land.Jul 15 2022, 9:48 AM
rriddle requested changes to this revision.Jul 15 2022, 10:01 AM
rriddle added inline comments.
mlir/lib/Interfaces/SideEffectInterfaces.cpp
67–81

This by itself isn't safe, because it's also making an assumption about aliasing. It's assuming that the op has properly deduced what effects should be placed on inputs/etc., which may not necessarily be the case. I think the driving example should be fine though, i.e. if the value is also known to be an alloc, it should be fine regardless of what other effects were placed on it (given that it's a newly constructed value).

This revision now requires changes to proceed.Jul 15 2022, 10:01 AM
zero9178 updated this revision to Diff 445150.Jul 15 2022, 3:24 PM

Change the logic to only apply to results that are also allocated

zero9178 retitled this revision from [mlir] Ignore effects on results when checking whether the op is trivially dead. to [mlir] Ignore effects on allocated results when checking whether the op is trivially dead. .Jul 15 2022, 3:25 PM
zero9178 edited the summary of this revision. (Show Details)
mehdi_amini added inline comments.Jul 18 2022, 4:53 AM
mlir/lib/Interfaces/SideEffectInterfaces.cpp
72

Why are you precomputing this in allocResults instead of doing it directly at the point of checking?

mehdi_amini accepted this revision.Jul 18 2022, 4:54 AM
mehdi_amini added inline comments.
mlir/lib/Interfaces/SideEffectInterfaces.cpp
72

Forget it, I figured: when we have an effect on a result, we don't know if this particular result is also allocated otherwise. The issue is that effects aren't grouped...

mlir/test/Transforms/canonicalize-dce.mlir
180

The comment is outdated

zero9178 added inline comments.Jul 18 2022, 4:58 AM
mlir/test/Transforms/canonicalize-dce.mlir
180

In the previous diff the comment read "Delete ops that only have side-effects on an result.".

I have since updated it and added "allocated result", which is the current state of the patch and accurate I believe.

rriddle accepted this revision.Jul 18 2022, 4:16 PM
This revision is now accepted and ready to land.Jul 18 2022, 4:16 PM