Skip to content

[MLIR]-affine-super-vectorize="virtual-vector-size=128 test-fastest-varying=0 vectorize-reductions=true" triggers Assertion Failure `(isTopLevelValue(val) || isAffineInductionVar(val)) && "non-terminal symbol / loop IV expected"' #116056

@xisang0

Description

@xisang0

Test on commit: 38fffa6
steps to reproduce:

mlir-opt test.mlir -affine-super-vectorize="virtual-vector-size=128 test-fastest-varying=0 vectorize-reductions=true"

test case:

module {
  func.func @main(%arg0: tensor<4xi32>, %arg1: tensor<4xi32>, %arg2: tensor<?x?xf32>, %arg3: tensor<?x?xf32>) -> () {
    %c1 = arith.constant 1 : index
    %c0 = arith.constant 0 : index
    %1 = bufferization.to_memref %arg2 : memref<?x?xf32>
    %dim = tensor.dim %arg2, %c0 : tensor<?x?xf32>
    %dim_0 = tensor.dim %arg3, %c0 : tensor<?x?xf32>
    %4 = arith.maxui %dim, %dim_0 : index
    %dim_3 = tensor.dim %arg2, %c0 : tensor<?x?xf32>
    %6 = arith.cmpi eq, %dim_3, %c1 : index
    %7 = scf.if %6 -> (tensor<?x?xf32>) {
      %dim_10 = tensor.dim %arg2, %c1 : tensor<?x?xf32>
      %alloc_11 = memref.alloc(%4, %dim_10) {alignment = 64 : i64} : memref<?x?xf32>
      %dim_12 = memref.dim %1, %c1 : memref<?x?xf32>
      affine.for %arg4 = 0 to %4 {
        affine.for %arg5 = 0 to %dim_12 {
          %20 = affine.load %1[%c0, %arg5] : memref<?x?xf32>
          affine.store %20, %alloc_11[%arg4, %arg5] : memref<?x?xf32>
        }
      }
      %19 = bufferization.to_tensor %alloc_11 : memref<?x?xf32>
      scf.yield %19 : tensor<?x?xf32>
    } else {
      scf.yield %arg2 : tensor<?x?xf32>
    }
    return
  }
}

crash trace:

mlir-opt: /home/workdir/llvm-project-19/mlir/lib/Dialect/Affine/Analysis/AffineStructures.cpp:44: void mlir::affine::FlatAffineValueConstraints::addInductionVarOrTerminalSymbol(Value): Assertion `(isTopLevelValue(val) || isAffineInductionVar(val)) && "non-terminal symbol / loop IV expected"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: ./mlir-opt /home/workdir/test.mlir "-affine-super-vectorize=virtual-vector-size=128 test-fastest-varying=0 vectorize-reductions=true"
 #0 0x000060678f2be258 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./mlir-opt+0x1068258)
 #1 0x000060678f2bbd7e llvm::sys::RunSignalHandlers() (./mlir-opt+0x1065d7e)
 #2 0x000060678f2bec68 SignalHandler(int) Signals.cpp:0:0
 #3 0x000075aa4bf62520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000075aa4bfb69fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000075aa4bf62476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000075aa4bf487f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000075aa4bf4871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x000075aa4bf59e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000060679248de2f mlir::affine::FlatAffineValueConstraints::addInductionVarOrTerminalSymbol(mlir::Value) (./mlir-opt+0x4237e2f)
#10 0x000060679248e79c mlir::affine::FlatAffineValueConstraints::addBound(mlir::presburger::BoundType, unsigned int, mlir::AffineMap, mlir::ValueRange) (./mlir-opt+0x423879c)
#11 0x000060679248e37e mlir::affine::FlatAffineValueConstraints::addAffineForOpDomain(mlir::affine::AffineForOp) (./mlir-opt+0x423837e)
#12 0x000060679248b186 mlir::affine::getIndexSet(llvm::MutableArrayRef<mlir::Operation*>, mlir::affine::FlatAffineValueConstraints*) (./mlir-opt+0x4235186)
#13 0x000060679248b40a mlir::affine::MemRefAccess::getAccessRelation(mlir::presburger::IntegerRelation&) const (./mlir-opt+0x423540a)
#14 0x000060679248a870 mlir::affine::checkMemrefAccessDependence(mlir::affine::MemRefAccess const&, mlir::affine::MemRefAccess const&, unsigned int, mlir::affine::FlatAffineValueConstraints*, llvm::SmallVector<mlir::affine::DependenceComponent, 2u>*, bool) (./mlir-opt+0x4234870)
#15 0x000060679248a553 mlir::affine::isLoopMemoryParallel(mlir::affine::AffineForOp) (./mlir-opt+0x4234553)
#16 0x000060679248a3fc mlir::affine::isLoopParallel(mlir::affine::AffineForOp, llvm::SmallVectorImpl<mlir::affine::LoopReduction>*) (./mlir-opt+0x42343fc)
#17 0x000060678f3f72e2 void llvm::function_ref<void (mlir::Operation*)>::callback_fn<std::enable_if<!llvm::is_one_of<mlir::affine::AffineForOp, mlir::Operation*, mlir::Region*, mlir::Block*>::value && std::is_same<void, void>::value, void>::type mlir::detail::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, (anonymous namespace)::Vectorize::runOnOperation()::$_1, mlir::affine::AffineForOp, void>(mlir::Operation*, (anonymous namespace)::Vectorize::runOnOperation()::$_1&&)::'lambda'(mlir::Operation*)>(long, mlir::Operation*) SuperVectorize.cpp:0:0
#18 0x000060678f3cc5be void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (./mlir-opt+0x11765be)
#19 0x000060678f3cc5be void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (./mlir-opt+0x11765be)
#20 0x000060678f3cc5be void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (./mlir-opt+0x11765be)
#21 0x000060678f3f5c2f (anonymous namespace)::Vectorize::runOnOperation() SuperVectorize.cpp:0:0
#22 0x00006067924f1b1f mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x429bb1f)
#23 0x00006067924f2302 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x429c302)
#24 0x00006067924f7a1e auto void mlir::parallelForEach<__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_0>(mlir::MLIRContext*, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_0&&)::'lambda'(__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>&&)::operator()<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&>(__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>&&) const Pass.cpp:0:0
#25 0x00006067924f3b0b mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (./mlir-opt+0x429db0b)
#26 0x00006067924f1c7c mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x429bc7c)
#27 0x00006067924f2302 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x429c302)
#28 0x00006067924f4aae mlir::PassManager::run(mlir::Operation*) (./mlir-opt+0x429eaae)
#29 0x00006067924ed5d2 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#30 0x00006067924ed23b llvm::LogicalResult llvm::function_ref<llvm::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::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#31 0x0000606792596f25 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::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (./mlir-opt+0x4340f25)
#32 0x00006067924e8432 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./mlir-opt+0x4292432)
#33 0x00006067924e86e3 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x42926e3)
#34 0x00006067924e88f2 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x42928f2)
#35 0x000060678f29d477 main (./mlir-opt+0x1047477)
#36 0x000075aa4bf49d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#37 0x000075aa4bf49e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#38 0x000060678f29cfe5 _start (./mlir-opt+0x1046fe5)
Aborted (core dumped)

It still exists in LLVM 20.1.0-rc1.

mlir-opt test.mlir -affine-super-vectorize="virtual-vector-size=128 test-fastest-varying=0 vectorize-reductions=true"

test case:

module {
  func.func @main(%arg0: tensor<4xi32>, %arg1: tensor<4xi32>, %arg2: tensor<?x?xf32>, %arg3: tensor<?x?xf32>) -> () {
    %c1 = arith.constant 1 : index
    %c0 = arith.constant 0 : index
    %1 = bufferization.to_memref %arg2 : tensor<?x?xf32> to memref<?x?xf32>
    %dim = tensor.dim %arg2, %c0 : tensor<?x?xf32>
    %dim_0 = tensor.dim %arg3, %c0 : tensor<?x?xf32>
    %4 = arith.maxui %dim, %dim_0 : index
    %dim_3 = tensor.dim %arg2, %c0 : tensor<?x?xf32>
    %6 = arith.cmpi eq, %dim_3, %c1 : index
    %7 = scf.if %6 -> (tensor<?x?xf32>) {
      %dim_10 = tensor.dim %arg2, %c1 : tensor<?x?xf32>
      %alloc_11 = memref.alloc(%4, %dim_10) {alignment = 64 : i64} : memref<?x?xf32>
      %dim_12 = memref.dim %1, %c1 : memref<?x?xf32>
      affine.for %arg4 = 0 to %4 {
        affine.for %arg5 = 0 to %dim_12 {
          %20 = affine.load %1[%c0, %arg5] : memref<?x?xf32>
          affine.store %20, %alloc_11[%arg4, %arg5] : memref<?x?xf32>
        }
      }
      %19 = bufferization.to_tensor %alloc_11 : memref<?x?xf32> to tensor<?x?xf32>
      scf.yield %19 : tensor<?x?xf32>
    } else {
      scf.yield %arg2 : tensor<?x?xf32>
    }
    return
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    crashPrefer [crash-on-valid] or [crash-on-invalid]mlir:affine

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions