This is an archive of the discontinued LLVM Phabricator instance.

[Canonicalizer] Process regions top-down instead of bottom up & reuse existing constants.
ClosedPublic

Authored by lattner on Mar 14 2021, 1:15 PM.

Details

Summary

Two changes:

  1. Change the canonicalizer to walk the function in top-down order instead of bottom-up order. This composes well with the "top down" nature of constant folding and simplification, reducing iterations and re-evaluation of ops in simple cases.
  2. Explicitly enter existing constants into the OperationFolder table before canonicalizing. Previously we would "constant fold" them and rematerialize them, wastefully recreating a bunch fo constants, which lead to pointless memory traffic.

Both changes together provide a 33% speedup for canonicalize on some mid-size
CIRCT examples.

One artifact of this change is that the constants generated in normal pattern
application get inserted at the top of the function as the patterns are applied.
Because of this, we get "inverted" constants more often, which is an aethetic
change to the IR but does permute some testcases.

Diff Detail

Event Timeline

lattner created this revision.Mar 14 2021, 1:15 PM
lattner requested review of this revision.Mar 14 2021, 1:15 PM

I'll also note that changing the order of visitation did also expose two "bugs", one is that vector.shape_cast canonicalization depends on ordering too much, I filed as https://bugs.llvm.org/show_bug.cgi?id=49590

The other is in the mlir-tblgen/pattern.mlir example, where the test was depending on ambiguous folding order of the two canonicalizations:

def TestNamedPatternRule : Pat<(OpA $input, $attr), (OpB $input, $attr)>;
def : Pat<(OpA (OpA $input, $attr), $bttr), (OpB $input, $bttr)>;

This seemed like a really weird test, so I just changed the testcase to match the expected output. Alternate suggestions on how to fix this are welcome!

bondhugula added inline comments.
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
149

int -> unsigned while at this?

156–164

Instead of adding them in pre-order and reversing, what happens if used post order while iterating over the ops of each block in reverse? Even for pre-order, we could have an option to traverse the ops of a block in reverse so that the contents of the vector won't have to be moved around later?

bondhugula added inline comments.Mar 14 2021, 1:40 PM
mlir/include/mlir/Transforms/FoldUtils.h
36

This comment doesn't appear to shed much light. Trivially, any constant op that isn't dead could be used for folding. Also, it doesn't say where its discovery/results go.

rriddle added inline comments.Mar 14 2021, 1:41 PM
mlir/include/mlir/Transforms/FoldUtils.h
37

nit: What about naming this something like: processExistingConstants? When I originally read the discover part, I wasn't sure if this also moved the constants to the insertion region. (I don't feel that strongly either way).

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

nit: Spell out auto here.

97

nit: Block?

103

nit: Spell out auto here.

131

Can we just move these first two checks to m_Constant? They are faster than checking the trait.

155

nit: Spell out auto here and below?

mlir/test/Transforms/single-parallel-loop-collapsing.mlir
16–17

Can you just update these(and the other newly broken cases) to CHECK-DAG?

rriddle accepted this revision.Mar 14 2021, 1:44 PM

LGTM after resolving comments.

This revision is now accepted and ready to land.Mar 14 2021, 1:44 PM
lattner updated this revision to Diff 330546.Mar 14 2021, 6:20 PM
lattner marked 9 inline comments as done.

Incorporate feedback from River and Uday

mlir/include/mlir/Transforms/FoldUtils.h
36

improved, thanks.

37

Sounds good, also improved the comment.

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

I don't typically spell it out when it is encoded into the name, but sure. Done.

131

Yes, but I'll do that as a separate patch so I can measure it.

mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
149

I'm not sure who is changing this, but this whole "max iterations" thing is probably a bad idea. it is apparently defaulting to 10 also, which seems a bit excessive to me. I'm going to walk cautiously away from this one :-)

156–164

I don't think that the microoptimization will do anything to help performance, and I like the simplicity of the code. It is very clear and direct.

This revision was landed with ongoing or failed builds.Mar 14 2021, 6:25 PM
This revision was automatically updated to reflect the committed changes.

Committed in b5d9a3c92358, thank you for the review! I'll change m_Constant now.

ftynse added a subscriber: ftynse.Mar 15 2021, 2:30 AM

This introduced a memory error and had to be rolled back. The error is visible under ASAN on several tests, here's mlir-opt -split-input-file -convert-linalg-to-spirv -canonicalize -verify-diagnostics mlir/test/Conversion/LinalgToSPIRV/linalg-to-spirv.mlir for example.

==2856919==ERROR: AddressSanitizer: heap-use-after-free on address 0x607000002128 at pc 0x000006cdb377 bp 0x7ffefa776480 sp 0x7ffefa776478
READ of size 4 at 0x607000002128 thread T0
    #0 0x6cdb376 in mlir::Operation::numTrailingObjects(llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<mlir::BlockOperand>) const /home/zinenko/llvm-project/mlir/include/mlir/IR/Operation.h:747:12
    #1 0x6cdb2f4 in unsigned long llvm::TrailingObjects<mlir::Operation, mlir::BlockOperand, mlir::Region, mlir::detail::OperandStorage>::callNumTrailingObjects<mlir::BlockOperand>(mlir::Operation const*, llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<mlir::BlockOperand>) /home/zinenko/llvm-project/llvm/include/llvm/Support/TrailingObjects.h:268:17
    #2 0x6cdb261 in llvm::trailing_objects_internal::TrailingObjectsImpl<8, mlir::Operation, llvm::TrailingObjects<mlir::Operation, mlir::BlockOperand, mlir::Region, mlir::detail::OperandStorage>, mlir::BlockOperand, mlir::Region, mlir::detail::OperandStorage>::getTrailingObjectsImpl(mlir::Operation*, llvm::trailing_objects_internal::TrailingObjectsBase::OverloadToken<mlir::Region>) /home/zinenko/llvm-project/llvm/include/llvm/Support/TrailingObjects.h:164:17
    #3 0x6ce8dd4 in mlir::Region* llvm::TrailingObjects<mlir::Operation, mlir::BlockOperand, mlir::Region, mlir::detail::OperandStorage>::getTrailingObjects<mlir::Region>() /home/zinenko/llvm-project/llvm/include/llvm/Support/TrailingObjects.h:301:12
    #4 0x6cbcc18 in mlir::Operation::getRegions() /home/zinenko/llvm-project/mlir/include/mlir/IR/Operation.h:430:21
    #5 0xe2d49c8 in mlir::detail::walk(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) /home/zinenko/llvm-project/mlir/lib/IR/Visitors.cpp:146:27
    #6 0xdc5a2af in std::enable_if<llvm::is_one_of<mlir::Operation*, mlir::Operation*, mlir::Region*, mlir::Block*>::value, mlir::WalkResult>::type mlir::detail::walk<(mlir::WalkOrder)0, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&, mlir::Operation*, mlir::WalkResult>(mlir::Operation*, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&) /home/zinenko/llvm-project/mlir/include/mlir/IR/Visitors.h:134:10
    #7 0xdc59e8e in std::enable_if<std::is_same<mlir::WalkResult, mlir::WalkResult>::value, mlir::WalkResult>::type mlir::Block::walk<(mlir::WalkOrder)0, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&, mlir::WalkResult>(llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, false, false, void>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, false, false, void>, false, false>, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&) /home/zinenko/llvm-project/mlir/include/mlir/IR/Block.h:305:11
    #8 0xdc5987b in mlir::WalkResult mlir::Block::walk<(mlir::WalkOrder)0, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&, mlir::WalkResult>(mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&) /home/zinenko/llvm-project/mlir/include/mlir/IR/Block.h:268:12
    #9 0xdc54738 in std::enable_if<std::is_same<mlir::WalkResult, mlir::WalkResult>::value, mlir::WalkResult>::type mlir::Region::walk<(mlir::WalkOrder)0, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0, mlir::WalkResult>(mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&&) /home/zinenko/llvm-project/mlir/include/mlir/IR/Region.h:278:17
    #10 0xdc5405b in mlir::OperationFolder::processExistingConstants(mlir::Region&) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/FoldUtils.cpp:130:10
    #11 0xdc5425a in mlir::OperationFolder::processExistingConstants(mlir::Region&) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/FoldUtils.cpp:158:7
    #12 0xdc6f0fd in (anonymous namespace)::GreedyPatternRewriteDriver::simplify(llvm::MutableArrayRef<mlir::Region>, int) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:146:12
    #13 0xdc6e662 in mlir::applyPatternsAndFoldGreedily(llvm::MutableArrayRef<mlir::Region>, mlir::FrozenRewritePatternList const&, unsigned int) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:273:27
    #14 0xdc6ea94 in mlir::applyPatternsAndFoldGreedily(llvm::MutableArrayRef<mlir::Region>, mlir::FrozenRewritePatternList const&) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:251:10
    #15 0xda2e2b7 in (anonymous namespace)::Canonicalizer::runOnOperation() /home/zinenko/llvm-project/mlir/lib/Transforms/Canonicalizer.cpp:34:11
    #16 0xd8c9792 in mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/zinenko/llvm-project/mlir/lib/Pass/Pass.cpp:402:11
    #17 0xd8cad54 in mlir::detail::OpToOpPassAdaptor::runPipeline(llvm::iterator_range<llvm::pointee_iterator<std::unique_ptr<mlir::Pass, std::default_delete<mlir::Pass> >*, mlir::Pass> >, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/zinenko/llvm-project/mlir/lib/Pass/Pass.cpp:444:16
    #18 0xd8d2fbe in mlir::PassManager::run(mlir::Operation*) /home/zinenko/llvm-project/mlir/lib/Pass/Pass.cpp:895:13
    #19 0xd7ec818 in performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext*, mlir::PassPipelineCLParser const&) /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:76:17
    #20 0xd7e8b83 in processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, bool, bool, bool, bool, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&) /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:119:9
    #21 0xd7ed824 in mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool)::$_0::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&) const /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:140:18
    #22 0xd7ed304 in mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&) /home/zinenko/llvm-project/llvm/include/llvm/ADT/STLExtras.h:185:12
    #23 0xddb46a9 in llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&) const /home/zinenko/llvm-project/llvm/include/llvm/ADT/STLExtras.h:209:12
    #24 0xddb41fd in mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&)>, llvm::raw_ostream&) /home/zinenko/llvm-project/mlir/lib/Support/ToolUtilities.cpp:43:16
    #25 0xd7e82ec in mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool) /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:137:12
    #26 0xd7eb5fc in mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:251:14
    #27 0x602a4f0 in main /home/zinenko/llvm-project/mlir/tools/mlir-opt/mlir-opt.cpp:189:17
    #28 0x7f5c74a60d09 in __libc_start_main csu/../csu/libc-start.c:308:16
    #29 0x5f7df79 in _start (/home/zinenko/llvm-project/build2/bin/mlir-opt+0x5f7df79)

0x607000002128 is located 56 bytes inside of 80-byte region [0x6070000020f0,0x607000002140)
freed by thread T0 here:
    #0 0x5ff741d in free llvm/compiler-rt/lib/asan/asan_malloc_linux.cpp:123:3
    #1 0xe1e38c7 in mlir::Operation::destroy() /home/zinenko/llvm-project/mlir/lib/IR/Operation.cpp:206:3
    #2 0xe1e62e4 in llvm::ilist_traits<mlir::Operation>::deleteNode(mlir::Operation*) /home/zinenko/llvm-project/mlir/lib/IR/Operation.cpp:429:7
    #3 0x9c23f60 in llvm::iplist_impl<llvm::simple_ilist<mlir::Operation>, llvm::ilist_traits<mlir::Operation> >::erase(llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, false, false, void>, false, false>) /home/zinenko/llvm-project/llvm/include/llvm/ADT/ilist.h:268:5
    #4 0xe20c96e in llvm::iplist_impl<llvm::simple_ilist<mlir::Operation>, llvm::ilist_traits<mlir::Operation> >::erase(mlir::Operation*) /home/zinenko/llvm-project/llvm/include/llvm/ADT/ilist.h:272:39
    #5 0xe1e68c3 in mlir::Operation::erase() /home/zinenko/llvm-project/mlir/lib/IR/Operation.cpp:478:29
    #6 0xdc5b5f3 in mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_2::operator()(mlir::Operation*, mlir::Attribute) const /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/FoldUtils.cpp:114:11
    #7 0xdc5a9bd in mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0::operator()(mlir::Operation*) const /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/FoldUtils.cpp:134:7
    #8 0xdc5a58b in mlir::WalkResult llvm::function_ref<mlir::WalkResult (mlir::Operation*)>::callback_fn<mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0>(long, mlir::Operation*) /home/zinenko/llvm-project/llvm/include/llvm/ADT/STLExtras.h:185:12
    #9 0xe2d5d2a in llvm::function_ref<mlir::WalkResult (mlir::Operation*)>::operator()(mlir::Operation*) const /home/zinenko/llvm-project/llvm/include/llvm/ADT/STLExtras.h:209:12
    #10 0xe2d4801 in mlir::detail::walk(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) /home/zinenko/llvm-project/mlir/lib/IR/Visitors.cpp:137:25
    #11 0xdc5a2af in std::enable_if<llvm::is_one_of<mlir::Operation*, mlir::Operation*, mlir::Region*, mlir::Block*>::value, mlir::WalkResult>::type mlir::detail::walk<(mlir::WalkOrder)0, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&, mlir::Operation*, mlir::WalkResult>(mlir::Operation*, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&) /home/zinenko/llvm-project/mlir/include/mlir/IR/Visitors.h:134:10
    #12 0xdc59e8e in std::enable_if<std::is_same<mlir::WalkResult, mlir::WalkResult>::value, mlir::WalkResult>::type mlir::Block::walk<(mlir::WalkOrder)0, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&, mlir::WalkResult>(llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, false, false, void>, false, false>, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, false, false, void>, false, false>, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&) /home/zinenko/llvm-project/mlir/include/mlir/IR/Block.h:305:11
    #13 0xdc5987b in mlir::WalkResult mlir::Block::walk<(mlir::WalkOrder)0, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&, mlir::WalkResult>(mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&) /home/zinenko/llvm-project/mlir/include/mlir/IR/Block.h:268:12
    #14 0xdc54738 in std::enable_if<std::is_same<mlir::WalkResult, mlir::WalkResult>::value, mlir::WalkResult>::type mlir::Region::walk<(mlir::WalkOrder)0, mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0, mlir::WalkResult>(mlir::OperationFolder::processExistingConstants(mlir::Region&)::$_0&&) /home/zinenko/llvm-project/mlir/include/mlir/IR/Region.h:278:17
    #15 0xdc5405b in mlir::OperationFolder::processExistingConstants(mlir::Region&) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/FoldUtils.cpp:130:10
    #16 0xdc5425a in mlir::OperationFolder::processExistingConstants(mlir::Region&) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/FoldUtils.cpp:158:7
    #17 0xdc6f0fd in (anonymous namespace)::GreedyPatternRewriteDriver::simplify(llvm::MutableArrayRef<mlir::Region>, int) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:146:12
    #18 0xdc6e662 in mlir::applyPatternsAndFoldGreedily(llvm::MutableArrayRef<mlir::Region>, mlir::FrozenRewritePatternList const&, unsigned int) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:273:27
    #19 0xdc6ea94 in mlir::applyPatternsAndFoldGreedily(llvm::MutableArrayRef<mlir::Region>, mlir::FrozenRewritePatternList const&) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:251:10
    #20 0xda2e2b7 in (anonymous namespace)::Canonicalizer::runOnOperation() /home/zinenko/llvm-project/mlir/lib/Transforms/Canonicalizer.cpp:34:11
    #21 0xd8c9792 in mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/zinenko/llvm-project/mlir/lib/Pass/Pass.cpp:402:11
    #22 0xd8cad54 in mlir::detail::OpToOpPassAdaptor::runPipeline(llvm::iterator_range<llvm::pointee_iterator<std::unique_ptr<mlir::Pass, std::default_delete<mlir::Pass> >*, mlir::Pass> >, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/zinenko/llvm-project/mlir/lib/Pass/Pass.cpp:444:16
    #23 0xd8d2fbe in mlir::PassManager::run(mlir::Operation*) /home/zinenko/llvm-project/mlir/lib/Pass/Pass.cpp:895:13
    #24 0xd7ec818 in performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext*, mlir::PassPipelineCLParser const&) /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:76:17
    #25 0xd7e8b83 in processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, bool, bool, bool, bool, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&) /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:119:9
    #26 0xd7ed824 in mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool)::$_0::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&) const /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:140:18
    #27 0xd7ed304 in mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&) /home/zinenko/llvm-project/llvm/include/llvm/ADT/STLExtras.h:185:12
    #28 0xddb46a9 in llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&) const /home/zinenko/llvm-project/llvm/include/llvm/ADT/STLExtras.h:209:12
    #29 0xddb41fd in mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&)>, llvm::raw_ostream&) /home/zinenko/llvm-project/mlir/lib/Support/ToolUtilities.cpp:43:16

previously allocated by thread T0 here:
    #0 0x5ff769d in malloc llvm/compiler-rt/lib/asan/asan_malloc_linux.cpp:145:3
    #1 0xe1e153f in mlir::Operation::create(mlir::Location, mlir::OperationName, mlir::TypeRange, mlir::ValueRange, mlir::DictionaryAttr, mlir::BlockRange, unsigned int) /home/zinenko/llvm-project/mlir/lib/IR/Operation.cpp:136:46
    #2 0xe1e292f in mlir::Operation::create(mlir::Location, mlir::OperationName, mlir::TypeRange, mlir::ValueRange, mlir::DictionaryAttr, mlir::BlockRange, mlir::RegionRange) /home/zinenko/llvm-project/mlir/lib/IR/Operation.cpp:94:19
    #3 0xe1e214c in mlir::Operation::create(mlir::OperationState const&) /home/zinenko/llvm-project/mlir/lib/IR/Operation.cpp:83:10
    #4 0xdeb9363 in mlir::OpBuilder::createOperation(mlir::OperationState const&) /home/zinenko/llvm-project/mlir/lib/IR/Builders.cpp:393:17
    #5 0xaa6b047 in mlir::spirv::ConstantOp mlir::OpBuilder::create<mlir::spirv::ConstantOp, mlir::Type&, mlir::IntegerAttr>(mlir::Location, mlir::Type&, mlir::IntegerAttr&&) /home/zinenko/llvm-project/mlir/include/mlir/IR/Builders.h:399:16
    #6 0xab24765 in mlir::spirv::linearizeIndex(mlir::ValueRange, llvm::ArrayRef<long>, long, mlir::Location, mlir::OpBuilder&) /home/zinenko/llvm-project/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp:623:35
    #7 0xab25a50 in mlir::spirv::getElementPtr(mlir::SPIRVTypeConverter&, mlir::MemRefType, mlir::Value, mlir::ValueRange, mlir::Location, mlir::OpBuilder&) /home/zinenko/llvm-project/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp:660:9
    #8 0xbd11b6b in (anonymous namespace)::SingleWorkgroupReduction::matchAndRewrite(mlir::linalg::GenericOp, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const /home/zinenko/llvm-project/mlir/lib/Conversion/LinalgToSPIRV/LinalgToSPIRV.cpp:148:27
    #9 0x8798d65 in mlir::OpConversionPattern<mlir::linalg::GenericOp>::matchAndRewrite(mlir::Operation*, llvm::ArrayRef<mlir::Value>, mlir::ConversionPatternRewriter&) const /home/zinenko/llvm-project/mlir/include/mlir/Transforms/DialectConversion.h:398:12
    #10 0xdbb350b in mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:1490:10
    #11 0x1494adb0 in mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) /home/zinenko/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:168:22
    #12 0xdbd5020 in (anonymous namespace)::OperationLegalizer::legalizeWithPattern(mlir::Operation*, mlir::ConversionPatternRewriter&) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:1766:21
    #13 0xdbd2d48 in (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:1683:17
    #14 0xdbd040b in (anonymous namespace)::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2178:26
    #15 0xdbbb00d in (anonymous namespace)::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2223:16
    #16 0xdbbbaf7 in mlir::applyFullConversion(llvm::ArrayRef<mlir::Operation*>, mlir::ConversionTarget&, mlir::FrozenRewritePatternList const&) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2778:22
    #17 0xdbbbe8f in mlir::applyFullConversion(mlir::Operation*, mlir::ConversionTarget&, mlir::FrozenRewritePatternList const&) /home/zinenko/llvm-project/mlir/lib/Transforms/Utils/DialectConversion.cpp:2783:10
    #18 0xbd0cdeb in (anonymous namespace)::LinalgToSPIRVPass::runOnOperation() /home/zinenko/llvm-project/mlir/lib/Conversion/LinalgToSPIRV/LinalgToSPIRVPass.cpp:44:14
    #19 0xd8c9792 in mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/zinenko/llvm-project/mlir/lib/Pass/Pass.cpp:402:11
    #20 0xd8cad54 in mlir::detail::OpToOpPassAdaptor::runPipeline(llvm::iterator_range<llvm::pointee_iterator<std::unique_ptr<mlir::Pass, std::default_delete<mlir::Pass> >*, mlir::Pass> >, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/zinenko/llvm-project/mlir/lib/Pass/Pass.cpp:444:16
    #21 0xd8d2fbe in mlir::PassManager::run(mlir::Operation*) /home/zinenko/llvm-project/mlir/lib/Pass/Pass.cpp:895:13
    #22 0xd7ec818 in performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext*, mlir::PassPipelineCLParser const&) /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:76:17
    #23 0xd7e8b83 in processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, bool, bool, bool, bool, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&) /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:119:9
    #24 0xd7ed824 in mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool)::$_0::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&) const /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:140:18
    #25 0xd7ed304 in mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&) /home/zinenko/llvm-project/llvm/include/llvm/ADT/STLExtras.h:185:12
    #26 0xddb46a9 in llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&) const /home/zinenko/llvm-project/llvm/include/llvm/ADT/STLExtras.h:209:12
    #27 0xddb41fd in mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, llvm::raw_ostream&)>, llvm::raw_ostream&) /home/zinenko/llvm-project/mlir/lib/Support/ToolUtilities.cpp:43:16
    #28 0xd7e82ec in mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer> >, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool) /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:137:12
    #29 0xd7eb5fc in mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) /home/zinenko/llvm-project/mlir/lib/Support/MlirOptMain.cpp:251:14

SUMMARY: AddressSanitizer: heap-use-after-free

Here's the list of broken tests

mlir/test/Conversion/LinalgToSPIRV/linalg-to-spirv.mlir
mlir/test/Conversion/StandardToSPIRV/alloc.mlir
mlir/test/Dialect/Linalg/bufferize.mlir
mlir/test/Dialect/Linalg/fusion-2-level.mlir
mlir/test/Dialect/Linalg/fusion-sequence.mlir
mlir/test/Dialect/Linalg/fusion.mlir
mlir/test/Dialect/Linalg/tile-and-fuse-tensors.mlir
mlir/test/Dialect/Quant/convert-const.mlir
mlir/test/Dialect/SPIRV/Transforms/canonicalize.mlir
mlir/test/Dialect/Shape/canonicalize.mlir
mlir/test/Integration/Dialect/Async/CPU/microbench-linalg-async-parallel-for.mlir
mlir/test/Integration/Dialect/Async/CPU/test-async-parallel-for-2d.mlir
mlir/test/Integration/Dialect/Linalg/CPU/benchmark_matmul.mlir
mlir/test/Integration/Dialect/Linalg/CPU/benchmark_matmul_column_major.mlir
mlir/test/Integration/Dialect/Linalg/CPU/benchmark_matmul_column_major_as_row_major.mlir
mlir/test/Integration/Dialect/Linalg/CPU/benchmark_matmul_i8_i8_i32.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-1d-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-1d-input-ncw-filter-wcf-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-1d-input-nwc-filter-wcf-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-1d-ncw-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-1d-nwc-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-2d-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-2d-input-nchw-filter-hwcf-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-2d-input-nhwc-filter-hwcf-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-2d-nchw-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-2d-nhwc-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-3d-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-3d-input-ncdhw-filter-dhwcf-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-3d-input-ndhwc-filter-dhwcf-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-3d-ncdhw-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-conv-3d-ndhwc-call.mlir
mlir/test/Integration/Dialect/Linalg/CPU/test-tensor-matmul.mlir
mlir/test/Integration/Dialect/Standard/CPU/test-ceil-floor-pos-neg.mlir
mlir/test/Integration/Dialect/Vector/CPU/test-transfer-read-2d.mlir
mlir/test/Integration/Dialect/Vector/CPU/test-transfer-to-loops.mlir
mlir/test/Integration/Dialect/Vector/CPU/test-vector-distribute.mlir
mlir/test/Integration/Sparse/CPU/matrix-market-example.mlir
mlir/test/Integration/Sparse/CPU/sparse_sampled_matmul.mlir
mlir/test/Integration/Sparse/CPU/sparse_sum.mlir
mlir/test/Transforms/canonicalize.mlir
mlir/test/Transforms/parallel-loop-collapsing.mlir
mlir/test/Transforms/scf-loop-unroll.mlir
mlir/test/Transforms/single-parallel-loop-collapsing.mlir
mlir/test/Transforms/test-canonicalize.mlir
mlir/test/mlir-cpu-runner/async-value.mlir
mlir/test/mlir-cpu-runner/async.mlir
mlir/test/mlir-cpu-runner/sgemm_naive_codegen.mlir

Huh ok, thank you for the revert Alex, i'll take a look at some point when I get a chance.