This is an archive of the discontinued LLVM Phabricator instance.

[mlir][FoldUtils] Ensure the created constant dominates the replaced op
ClosedPublic

Authored by rriddle on Aug 20 2021, 4:42 PM.

Details

Summary

This revision fixes a bug where an operation would get replaced with
a pre-existing constant that didn't dominate it. This can occur when
a pattern inserts operations to be folded at the beginning of the
constants insertion block. This revision fixes the bug by moving the
existing constant before the replaced operation in such cases. This is
fine because if a constant didn't already exist, a new one would have
been inserted before this operation anyways.

Diff Detail

Event Timeline

rriddle created this revision.Aug 20 2021, 4:42 PM
rriddle requested review of this revision.Aug 20 2021, 4:42 PM
bondhugula accepted this revision.Aug 20 2021, 9:36 PM
bondhugula added a subscriber: bondhugula.

Nice catch and fix!

constant before the replaced operation in such cases, something
that would happen anyways if the constant didn't already exist.

This clause isn't clear to me. Is there a typo?

mlir/lib/Transforms/Utils/FoldUtils.cpp
237

This may happen -> This may not automatically happen ... or a slight rephrasing?

mlir/test/lib/Dialect/Test/TestPatterns.cpp
102

Short comment here.

This revision is now accepted and ready to land.Aug 20 2021, 9:36 PM
rriddle updated this revision to Diff 368156.Aug 23 2021, 11:14 AM
rriddle marked 2 inline comments as done.

update

Nice catch and fix!

constant before the replaced operation in such cases, something
that would happen anyways if the constant didn't already exist.

This clause isn't clear to me. Is there a typo?

Reworded a bit.

rriddle edited the summary of this revision. (Show Details)Aug 23 2021, 11:14 AM

Thanks for the review Uday! Appreciated.

This revision was landed with ongoing or failed builds.Aug 23 2021, 11:52 AM
This revision was automatically updated to reflect the committed changes.

FYI, this bug introduced a major performance regression in canonicalize:
https://bugs.llvm.org/show_bug.cgi?id=51738

-Chris