[mlir][FoldUtils] Ensure the created constant dominates the replaced op
authorRiver Riddle <riddleriver@gmail.com>
Mon, 23 Aug 2021 18:14:18 +0000 (18:14 +0000)
committerRiver Riddle <riddleriver@gmail.com>
Mon, 23 Aug 2021 18:48:24 +0000 (18:48 +0000)
commite4635e6328c88f1f403b316bd8340fe03f9835a8
tree7a13dc4f640bad06b104d69f71a52d08cf6122b2
parent23c19395c085306cf229341523b6a8909b3b70a9
[mlir][FoldUtils] Ensure the created constant dominates the replaced op

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.

Differential Revision: https://reviews.llvm.org/D108498
mlir/lib/Transforms/Utils/FoldUtils.cpp
mlir/test/Transforms/test-operation-folder.mlir
mlir/test/lib/Dialect/Test/TestPatterns.cpp