This is an archive of the discontinued LLVM Phabricator instance.

[mlir] call target materialization more in dialect conversion
ClosedPublic

Authored by ftynse on Feb 16 2022, 5:45 AM.

Details

Summary

During dialect conversion, target materialization is triggered to create
cast-like operations when a type mismatch occurs between the value that
replaces a rewritten operation and the type that another operations expects as
operands processed by the type conversion. First, a dummy cast is inserted to
make sure the pattern application can proceed. The decision to trigger the
user-provided materialization hook is taken later based on the result of the
dummy cast having uses. However, it only has uses if other patterns constructed
new operations using the casted value as operand. If existing (legal)
operations use the replaced value, they may have not been updated to use the
casted value yet. The conversion infra would then delete the dummy cast first,
and then would replace the uses with now-invalid (null in the bast case) value.
When deciding whether to trigger cast materialization, check for liveness the
uses not only of the casted value, but also of all the values that it replaces.

This was discovered in the finalizing bufferize pass that cleans up
mutually-cancelling casts without touching other operations. It is not
impossible that there are other scenarios where the dialect converison infra
could produce invalid operand uses because of dummy casts erased too eagerly.

Diff Detail

Event Timeline

ftynse created this revision.Feb 16 2022, 5:45 AM
ftynse requested review of this revision.Feb 16 2022, 5:45 AM
ftynse updated this revision to Diff 409223.Feb 16 2022, 5:55 AM

Forgot FileCheck.

springerm accepted this revision.Feb 16 2022, 5:55 AM

Thanks for fixing this!

This revision is now accepted and ready to land.Feb 16 2022, 5:55 AM