Issue 237214
Summary [mlir] `--affine-super-vectorize` crashes due to permutation map and vector rank mismatch
Labels mlir
Assignees
Reporter frida-albrecht
    The `--affine-super-vectorize` pass crashes with an assertion failure when vectorizing nested affine loops containing `affine.load` and `affine.store` operations.

The crash occurs in `vector::createReadOrMaskedRead()` in VectorUtils.cpp, which is called from `vectorizeAffineLoad()` in SuperVectorize.cpp. The generated permutation map has a number of results that does not match the vector rank, triggering the assertion.

test commit: [7a941df](https://github.com/llvm/llvm-project/commit/7a941dfb2877a0b8cf30323fefa85ad019e0b0f5)

test case:
```mlir
module {
  func.func @main() -> tensor<1x4x4x1xf32> attributes {llvm.arm_new_za, llvm.arm_streaming} {
    %cst = arith.constant -1.000000e+00 : f32
    %cst_0 = arith.constant 1.000000e+00 : f32
 %cst_1 = arith.constant -5.000000e-01 : f32
    %alloc = memref.alloc() {alignment = 64 : i64} : memref<1x4x4x1xf32>
    affine.for %arg0 = 0 to 1 {
      affine.for %arg1 = 0 to 4 {
        affine.for %arg2 = 0 to 4 {
 affine.for %arg3 = 0 to 1 {
            affine.for %arg4 = 0 to 1 {
 affine.for %arg5 = 0 to 1 {
                affine.for %arg6 = 0 to 1 {
                  %1 = affine.load %alloc[%arg0, %arg1, %arg2, %arg3] : memref<1x4x4x1xf32>
                  %2 = llvm.fmul %cst_0, %cst : f32
                  %3 = llvm.fadd %1, %2 : f32
 affine.store %3, %alloc[%arg0, %arg1, %arg2, %arg3] : memref<1x4x4x1xf32>
 } {"test.trip-count" = 1 : i64}
              } {"test.trip-count" = 1 : i64}
            } {"test.trip-count" = 1 : i64}
          } {"test.trip-count" = 1 : i64}
        } {"test.trip-count" = 4 : i64}
      } {"test.trip-count" = 4 : i64}
 } {"test.trip-count" = 1 : i64}
    %0 = bufferization.to_tensor %alloc : memref<1x4x4x1xf32> to tensor<1x4x4x1xf32>
    return %0 : tensor<1x4x4x1xf32>
  }
}

```



Step to reproduce:
```
mlir-opt test.mlir --affine-super-vectorize="virtual-vector-size=4,8"
```

Crash backtrace:
```
mlir-opt: /home/llvm-project/llvm-project-23.1.4/mlir/lib/Dialect/Vector/Utils/VectorUtils.cpp:467: mlir::Value mlir::vector::createReadOrMaskedRead(mlir::OpBuilder&, mlir::Location, mlir::Value, const mlir::VectorType&, std::optional<mlir::Value>, bool, llvm::ArrayRef<mlir::Value>, mlir::AffineMap): Assertion `(!permutationMap || permutationMap.getNumResults() == static_cast<size_t>(vecToReadRank)) && "expected permutation map results to match vector rank."' 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: /home/llvm-project/build-23.1.4/bin/mlir-opt /home/llvm-project/results/verify_test/175.mlir --affine-super-vectorize=virtual-vector-size=4,8
 #0 0x00005652da95b529 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1e8c529)
 #1 0x00005652da957d0c llvm::sys::RunSignalHandlers() (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1e88d0c)
 #2 0x00005652da957e72 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007ff767b06520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007ff767b5a9bc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969bc)
 #5 0x00007ff767b06476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007ff767aec7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007ff767aec71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007ff767afde96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00005652e161f5d0 mlir::vector::createReadOrMaskedRead(mlir::OpBuilder&, mlir::Location, mlir::Value, mlir::VectorType const&, std::optional<mlir::Value>, bool, llvm::ArrayRef<mlir::Value>, mlir::AffineMap) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x8b505d0)
#10 0x00005652e136f8b2 vectorizeAffineLoad(mlir::affine::AffineLoadOp, (anonymous namespace)::VectorizationState&) SuperVectorize.cpp:0:0
#11 0x00005652e1372d60 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (.constprop.0) SuperVectorize.cpp:0:0
#12 0x00005652e1372dce mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (.constprop.0) SuperVectorize.cpp:0:0
#13 0x00005652e1372dce mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (.constprop.0) SuperVectorize.cpp:0:0
#14 0x00005652e1372dce mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (.constprop.0) SuperVectorize.cpp:0:0
#15 0x00005652e1373421 vectorizeLoopNest(std::vector<llvm::SmallVector<mlir::affine::AffineForOp, 2u>, std::allocator<llvm::SmallVector<mlir::affine::AffineForOp, 2u>>>&, mlir::affine::VectorizationStrategy const&) (.isra.0) SuperVectorize.cpp:0:0
#16 0x00005652e13746c4 vectorizeLoops(mlir::Operation*, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>&, llvm::ArrayRef<long>, llvm::ArrayRef<long>, llvm::DenseMap<mlir::Operation*, llvm::SmallVector<mlir::affine::LoopReduction, 2u>, llvm::DenseMapInfo<mlir::Operation*, void>, llvm::detail::DenseMapPair<mlir::Operation*, llvm::SmallVector<mlir::affine::LoopReduction, 2u>>> const&) SuperVectorize.cpp:0:0
#17 0x00005652e1375ebe mlir::affine::vectorizeChildAffineLoops(mlir::Operation*, bool, llvm::ArrayRef<long>, llvm::ArrayRef<long>) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x88a6ebe)
#18 0x00005652e13762ff (anonymous namespace)::Vectorize::runOnOperation() SuperVectorize.cpp:0:0
#19 0x00005652e2e0cd09 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa33dd09)
#20 0x00005652e2e0d074 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa33e074)
#21 0x00005652e2e0d916 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::'lambda12'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&)::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&) const Pass.cpp:0:0
#22 0x00005652e2e0bc0d mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa33cc0d)
#23 0x00005652e2e0cbe1 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa33dbe1)
#24 0x00005652e2e0d074 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa33e074)
#25 0x00005652e2e0f0f2 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa3400f2)
#26 0x00005652e2e100f9 mlir::PassManager::run(mlir::Operation*) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa3410f9)
#27 0x00005652daa1e5f7 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#28 0x00005652daa1efc7 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#29 0x00005652e31f29bd mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa7239bd)
#30 0x00005652daa19f3a mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#31 0x00005652daa1f708 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1f50708)
#32 0x00005652daa1f964 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1f50964)
#33 0x00005652da8aca5c main (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1ddda5c)
#34 0x00007ff767aedd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#35 0x00007ff767aede40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#36 0x00005652da93af65 _start (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1e6bf65)
Aborted (core dumped)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to