[MLIR][TOSA] --test-legalize-patterns crashes when folding tosa.add with pattern rollback disabled
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
### Description
`mlir-opt` crashes with an `LLVM ERROR` when running `--test-legalize-patterns="allow-pattern-rollback=0"` on a module containing a `tosa.add` operation.
The failure occurs while legalizing the operation through folding. The conversion driver requests rollback of IR modifications even though pattern rollback is disabled:
```text
LLVM ERROR: op 'tosa.add' folder rollback of IR modifications requested
```
### Tested commit
[llvmorg-23.1.1](https://github.com/llvm/llvm-project/releases/tag/llvmorg-23.1.1)
### Reproducer
```mlir
"builtin.module"() ({
"func.func"() <{function_type = (tensor<2x4xf16>, tensor<1x1xf16>) -> tensor<1x8x8x3xf32>, sym_name = "main"}> ({
^bb0(%arg0: tensor<2x4xf16>, %arg1: tensor<1x1xf16>):
%0 = "tosa.const"() {values = dense<2.000000e+00> : tensor<1x8x8x3xf32>} : () -> tensor<1x8x8x3xf32>
%1 = "tosa.add"(%0, %0) : (tensor<1x8x8x3xf32>, tensor<1x8x8x3xf32>) -> tensor<1x8x8x3xf32>
"func.return"(%1) : (tensor<1x8x8x3xf32>) -> ()
}) : () -> ()
}) : () -> ()
```
### Steps to reproduce
```bash
mlir-opt test.mlir --test-legalize-patterns="allow-pattern-rollback=0"
```
### stack trace
```text
notifyOperationInserted: tosa.const, was unlinked
notifyOperationModified: tosa.add
notifyOperationReplaced: tosa.add
notifyOperationModified: func.return
notifyOperationErased: tosa.add
LLVM ERROR: op 'tosa.add' folder rollback of IR modifications requested
Stack dump:
0. Program arguments: /home/llvm-project/llvm-project/build/bin/mlir-opt /home/MLIR-Smith/results/verify_test/39.mlir --test-legalize-patterns=allow-pattern-rollback=0
#0 0x000055abd2640f09 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x204bf09)
#1 0x000055abd263d6ec llvm::sys::RunSignalHandlers() (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x20486ec)
#2 0x000055abd263d852 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f24fbe7c520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f24fbed09fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007f24fbe7c476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007f24fbe627f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000055abd2550845 llvm::ConvertUTF8toUTF16(unsigned char const**, unsigned char const*, unsigned short**, unsigned short*, llvm::ConversionFlags) (.cold) ConvertUTF.cpp:0:0
#8 0x000055abd26215f4 (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x202c5f4)
#9 0x000055abdc74439f (anonymous namespace)::OperationLegalizer::legalizeWithFold(mlir::Operation*) DialectConversion.cpp:0:0
#10 0x000055abdc74493b (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) DialectConversion.cpp:0:0
#11 0x000055abdc744da4 mlir::OperationConverter::convert(mlir::Operation*, bool) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc14fda4)
#12 0x000055abdc74e976 mlir::OperationConverter::applyConversion(llvm::ArrayRef) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc159976)
#13 0x000055abdc74ffaf applyConversion(llvm::ArrayRef, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode) DialectConversion.cpp:0:0
#14 0x000055abdc750166 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc15b166)
#15 0x000055abd2880954 (anonymous namespace)::TestLegalizePatternDriver::runOnOperation() TestPatterns.cpp:0:0
#16 0x000055abdc7fc8d9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc2078d9)
#17 0x000055abdc7fcc44 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc207c44)
#18 0x000055abdc7fecc2 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc209cc2)
#19 0x000055abdc7ffcc9 mlir::PassManager::run(mlir::Operation*) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc20acc9)
#20 0x000055abd2703fd7 performActions(llvm::raw_ostream&, std::shared_ptr const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#21 0x000055abd27049a7 llvm::LogicalResult llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr>, llvm::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#22 0x000055abdcbd53fd mlir::splitAndProcessBuffer(std::unique_ptr>, llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc5e03fd)
#23 0x000055abd26ff91a mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#24 0x000055abd27050e8 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x21100e8)
#25 0x000055abd2705344 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x2110344)
#26 0x000055abd255c36c main (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x1f6736c)
#27 0x00007f24fbe63d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#28 0x00007f24fbe63e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#29 0x000055abd2620945 _start (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x202b945)
Aborted (core dumped)
```
Contributor guide
Research direction
Start by running the supplied mlir-opt reproducer with --test-legalize-patterns="allow-pattern-rollback=0" and inspect TestPatterns.cpp and the legalizeWithFold path in DialectConversion.cpp. Trace how folding requests rollback when pattern rollback is disabled. Done means the reproducer no longer aborts with the LLVM ERROR.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 64/100