llvm / llvm/llvm-project

[MLIR] --test-legalize-patterns crashes on spirv.func when pattern rollback is disabled

Open
#222,539 1 comment 0 reactions 0 assignees View on GitHub
crash mlir
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 `spirv.func` operation.

The failure occurs after the `AnyFunctionOpInterfaceSignatureConversion` pattern modifies the `spirv.func`, but the resulting IR cannot be legalized:

```text
notifyOperationModified: spirv.func
LLVM ERROR: pattern '{anonymous}::AnyFunctionOpInterfaceSignatureConversion' produced IR that could not be legalized. new ops: {}, modified ops: {spirv.func}
```

### Tested commit

[llvmorg-23.1.1](https://github.com/llvm/llvm-project/releases/tag/llvmorg-23.1.1)

### Reproducer

```mlir
#map = affine_map<(d0) -> (d0)>

module {
spirv.func @main(%arg0: !spirv.array<4 x f32>) -> !spirv.array<4 x f32> "None" {
%cst = arith.constant 1.000000e+00 : f16
%0 = builtin.unrealized_conversion_cast %arg0 : !spirv.array<4 x f32> to tensor<4xf16>
%1 = tensor.empty() : tensor<4xf16>
%2 = linalg.generic {
indexing_maps = [#map, #map],
iterator_types = ["parallel"]
} ins(%0 : tensor<4xf16>) outs(%1 : tensor<4xf16>) {
^bb0(%in: f16, %out: f16):
%4 = arith.negf %in : f16
%5 = arith.extf %4 fastmath : f16 to f32
%6 = math.exp %5 : f32
%7 = arith.truncf %6 fastmath : f32 to f16
%8 = arith.addf %7, %cst : f16
%9 = arith.divf %cst, %8 : f16
linalg.yield %9 : f16
} -> tensor<4xf16>
%3 = builtin.unrealized_conversion_cast %2 : tensor<4xf16> to !spirv.array<4 x f32>
spirv.ReturnValue %3 : !spirv.array<4 x f32>
}
}
```

### Steps to reproduce

```bash
mlir-opt test.mlir --test-legalize-patterns="allow-pattern-rollback=0"
```

### stack trace

```text
notifyOperationModified: spirv.func
LLVM ERROR: pattern '{anonymous}::AnyFunctionOpInterfaceSignatureConversion' produced IR that could not be legalized. new ops: {}, modified ops: {spirv.func}
Stack dump:
0. Program arguments: /home/llvm-project/llvm-project/build/bin/mlir-opt /home/MLIR-Smith/results/verify_test/5.mlir --test-legalize-patterns=allow-pattern-rollback=0
#0 0x0000563b190d5f09 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x204bf09)
#1 0x0000563b190d26ec llvm::sys::RunSignalHandlers() (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x20486ec)
#2 0x0000563b190d2852 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007fe66bbc3520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007fe66bc179fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007fe66bbc3476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007fe66bba97f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x0000563b18fe5845 llvm::ConvertUTF8toUTF16(unsigned char const**, unsigned char const*, unsigned short**, unsigned short*, llvm::ConversionFlags) (.cold) ConvertUTF.cpp:0:0
#8 0x0000563b190b65f4 (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x202c5f4)
#9 0x0000563b231dad21 llvm::LogicalResult llvm::function_ref::callback_fn<(anonymous namespace)::OperationLegalizer::legalizeWithPattern(mlir::Operation*)::'lambda1'(mlir::Pattern const&)>(long, mlir::Pattern const&) DialectConversion.cpp:0:0
#10 0x0000563b232265c5 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref)::'lambda'()::operator()() const PatternApplicator.cpp:0:0
#11 0x0000563b23227dcf mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc19ddcf)
#12 0x0000563b231d98eb (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) DialectConversion.cpp:0:0
#13 0x0000563b231d9da4 mlir::OperationConverter::convert(mlir::Operation*, bool) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc14fda4)
#14 0x0000563b231e3976 mlir::OperationConverter::applyConversion(llvm::ArrayRef) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc159976)
#15 0x0000563b231e4faf applyConversion(llvm::ArrayRef, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode) DialectConversion.cpp:0:0
#16 0x0000563b231e5166 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc15b166)
#17 0x0000563b19315954 (anonymous namespace)::TestLegalizePatternDriver::runOnOperation() TestPatterns.cpp:0:0
#18 0x0000563b232918d9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc2078d9)
#19 0x0000563b23291c44 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)
#20 0x0000563b23293cc2 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc209cc2)
#21 0x0000563b23294cc9 mlir::PassManager::run(mlir::Operation*) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0xc20acc9)
#22 0x0000563b19198fd7 performActions(llvm::raw_ostream&, std::shared_ptr const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#23 0x0000563b191999a7 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
#24 0x0000563b2366a3fd 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)
#25 0x0000563b1919491a mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#26 0x0000563b1919a0e8 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x21100e8)
#27 0x0000563b1919a344 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x2110344)
#28 0x0000563b18ff136c main (/home/llvm-project/llvm-project/build/bin/mlir-opt+0x1f6736c)
#29 0x00007fe66bbaad90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#30 0x00007fe66bbaae40 __libc_start_main (/lib/x86_6
```

Contributor guide

Open the contributing guide

Research direction

Start with the reproducer using mlir-opt and --test-legalize-patterns="allow-pattern-rollback=0". Read TestPatterns.cpp, DialectConversion.cpp, and the AnyFunctionOpInterfaceSignatureConversion path shown in the failure. Done means this spirv.func case no longer crashes when pattern rollback is disabled, with regression coverage for the reproducer.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.