llvm / llvm/llvm-project

[mlir] Crash when handling `memref.load` with vector element type

Open
#224,811 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

crash mlir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Description

`--test-emulate-narrow-int` crashes when processing a `memref.load` with a vector element type (`vector<1xi1>`).

### Tested commit

[3b8ee89](https://github.com/llvm/llvm-project/commit/3b8ee89006f5a228fce75528f8dd80b4229abcc1)

### Test case

```mlir
#map = affine_map<(d0, d1) -> (d0 + d1)>
module {
func.func @outlined_then2(%arg0: memref<4xvector<1x1x1xi1>, #spirv.storage_class>, %arg1: index, %arg2: index, %arg3: index, %arg4: memref<1x8x8x3xi1, #spirv.storage_class>, %arg5: index, %arg6: index, %arg7: index, %arg8: index) {
%c1 = arith.constant 1 : index
%c0 = arith.constant 0 : index
%0 = vector.type_cast %arg0 : memref<4xvector<1x1x1xi1>, #spirv.storage_class> to memref<4x1xvector<1x1xi1>, #spirv.storage_class>
scf.for %arg9 = %c0 to %c1 step %c1 {
%1 = affine.apply #map(%arg1, %arg9)
%2 = vector.type_cast %0 : memref<4x1xvector<1x1xi1>, #spirv.storage_class> to memref<4x1x1xvector<1xi1>, #spirv.storage_class>
scf.for %arg10 = %c0 to %c1 step %c1 {
%3 = affine.apply #map(%arg2, %arg10)
%4 = memref.load %2[%arg3, %arg9, %arg10] : memref<4x1x1xvector<1xi1>, #spirv.storage_class>
}
}
return
}
}
```

### Steps to reproduce

```
mlir-opt test.mlir --test-emulate-narrow-int
```

### stack trace

```
mlir-opt: /home/workdir/llvm-project-latest/mlir/lib/IR/Types.cpp:125: unsigned int mlir::Type::getIntOrFloatBitWidth() const: Assertion `isIntOrFloat() && "only integers and floats have a bitwidth"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. Program arguments: mlir-opt test.mlir --test-emulate-narrow-int
#0 0x0000562280d01d0b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../llvm-project-latest/build/bin/mlir-opt+0x1fc2d0b)
#1 0x0000562280cfeb11 llvm::sys::RunSignalHandlers() (../llvm-project-latest/build/bin/mlir-opt+0x1fbfb11)
#2 0x0000562280d02a3b SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x00007f28da44c520 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f28da4a09fc pthread_kill (/usr/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x00007f28da44c476 gsignal (/usr/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x00007f28da4327f3 abort (/usr/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x00007f28da43271b (/usr/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x00007f28da443e96 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000562289243bd0 mlir::Type::getIntOrFloatBitWidth() const (../llvm-project-latest/build/bin/mlir-opt+0xa504bd0)
#10 0x00005622871d621d (anonymous namespace)::ConvertMemRefLoad::matchAndRewrite(mlir::memref::LoadOp, mlir::memref::LoadOpAdaptor, mlir::ConversionPatternRewriter&) const EmulateNarrowType.cpp:0:0
#11 0x000056228239630b llvm::LogicalResult mlir::ConversionPattern::dispatchTo1To1, mlir::memref::LoadOp>(mlir::OpConversionPattern const&, mlir::memref::LoadOp, mlir::memref::LoadOp::GenericAdaptor>, mlir::ConversionPatternRewriter&) (../llvm-project-latest/build/bin/mlir-opt+0x365730b)
#12 0x0000562282395a17 mlir::OpConversionPattern::matchAndRewrite(mlir::Operation*, llvm::ArrayRef, mlir::ConversionPatternRewriter&) const (../llvm-project-latest/build/bin/mlir-opt+0x3656a17)
#13 0x0000562288e57224 mlir::ConversionPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (../llvm-project-latest/build/bin/mlir-opt+0xa118224)
#14 0x0000562288ea66c8 void llvm::function_ref::callback_fn, llvm::function_ref, llvm::function_ref)::$_0>(long) PatternApplicator.cpp:0:0
#15 0x0000562288ea2e2a mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref) (../llvm-project-latest/build/bin/mlir-opt+0xa163e2a)
#16 0x0000562288e58f62 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*) DialectConversion.cpp:0:0
#17 0x0000562288e58750 mlir::OperationConverter::convert(mlir::Operation*, bool) (../llvm-project-latest/build/bin/mlir-opt+0xa119750)
#18 0x0000562288e59c5e mlir::OperationConverter::applyConversion(llvm::ArrayRef) (../llvm-project-latest/build/bin/mlir-opt+0xa11ac5e)
#19 0x0000562288e684c9 void llvm::function_ref::callback_fn, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode)::$_0>(long) DialectConversion.cpp:0:0
#20 0x0000562288e5f927 applyConversion(llvm::ArrayRef, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig, (anonymous namespace)::OpConversionMode) DialectConversion.cpp:0:0
#21 0x0000562288e5fa0b mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (../llvm-project-latest/build/bin/mlir-opt+0xa120a0b)
#22 0x0000562280debb15 (anonymous namespace)::TestEmulateNarrowTypePass::runOnOperation() TestEmulateNarrowType.cpp:0:0
#23 0x0000562288f013ee mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (../llvm-project-latest/build/bin/mlir-opt+0xa1c23ee)
#24 0x0000562288f02364 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (../llvm-project-latest/build/bin/mlir-opt+0xa1c3364)
#25 0x0000562288f0cf3e auto void mlir::parallelForEach<__gnu_cxx::__normal_iterator>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_12>(mlir::MLIRContext*, __gnu_cxx::__normal_iterator>>, __gnu_cxx::__normal_iterator>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_12&&)::'lambda'(__gnu_cxx::__normal_iterator>>&&)::operator()(__gnu_cxx::__normal_iterator>>&&) const Pass.cpp:0:0
#26 0x0000562288f04f38 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (../llvm-project-latest/build/bin/mlir-opt+0xa1c5f38)
#27 0x0000562288f01744 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (../llvm-project-latest/build/bin/mlir-opt+0xa1c2744)
#28 0x0000562288f02364 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (../llvm-project-latest/build/bin/mlir-opt+0xa1c3364)
#29 0x0000562288f090fa mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (../llvm-project-latest/build/bin/mlir-opt+0xa1ca0fa)
#30 0x0000562288f08a5d mlir::PassManager::run(mlir::Operation*) (../llvm-project-latest/build/bin/mlir-opt+0xa1c9a5d)
#31 0x0000562280dad58f performActions(llvm::raw_ostream&, std::shared_ptr const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#32 0x0000562280dac761 llvm::LogicalResult llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#33 0x000056228925bec6 mlir::splitAndProcessBuffer(std::unique_ptr>, llvm::function_ref>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (../llvm-project-latest/build/bin/mlir-opt+0xa51cec6)
#34 0x0000562280da2ba6 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (../llvm-project-latest/build/bin/mlir-opt+0x2063ba6)
#35 0x0000562280da2f7a mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (../llvm-project-latest/build/bin/mlir-opt+0x2063f7a)
#36 0x0000562280da31eb mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (../llvm-project-latest/build/bin/mlir-opt+0x20641eb)
#37 0x0000562280ce77cd main (../llvm-project-latest/build/bin/mlir-opt+0x1fa87cd)
#38 0x00007f28da433d90 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#39 0x00007f28da433e40 __libc_start_main (/usr/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#40 0x0000562280ce7325 _start (../llvm-project-latest/build/bin/mlir-opt+0x1fa8325)
Aborted (core dumped)
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the crash with mlir-opt test.mlir --test-emulate-narrow-int, then inspect ConvertMemRefLoad in EmulateNarrowType.cpp, identified by the stack trace. Trace how the memref.load result type is handled for vector elements and add coverage for the supplied MLIR case. Done means the command no longer hits the getIntOrFloatBitWidth assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.