Skip to content

[MLIR]Crashes on affine loop optimization passes: Assertion `llvm::all_of(ifOp.getOperands(), [](Value v) { return isTopLevelValue(v) || isAffineForInductionVar(v); }) && "operands not composed"' #62323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BealZephyr opened this issue Apr 24, 2023 · 2 comments · Fixed by #130401
Assignees
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir:affine

Comments

@BealZephyr
Copy link

BealZephyr commented Apr 24, 2023

Test commit: 67205f9

Steps to reproduce:

mlir-opt test.mlir "-affine-loop-tile=tile-size=32 separate" -affine-parallelize -test-affine-loop-unswitch

Test case:

module {
  func.func @main(%arg0: memref<35xf32>) -> memref<35xf32> {
    %0 = llvm.mlir.constant(1.000000e+00 : f32) : f32
    %alloc = memref.alloc() {alignment = 64 : i64} : memref<35xf32>
    affine.for %arg1 = 0 to 35 {
      %1 = affine.load %arg0[%arg1] : memref<35xf32>
      %2 = llvm.fdiv %0, %1  : f32
      affine.store %2, %alloc[%arg1] : memref<35xf32>
    }
    return %alloc : memref<35xf32>
  }
}

Crash trace:

mlir-opt: /home/ty/llvm-project/mlir/lib/Dialect/Affine/Utils/Utils.cpp:438: mlir::LogicalResult mlir::affine::hoistAffineIfOp(mlir::affine::AffineIfOp, bool*): Assertion `llvm::all_of(ifOp.getOperands(), [](Value v) { return isTopLevelValue(v) || isAffineForInductionVar(v); }) && "operands not composed"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: /home/ty/llvm-project/build/bin/mlir-opt test.mlir "-affine-loop-tile=tile-size=32 separate" -affine-parallelize -test-affine-loop-unswitch
 #0 0x000055aad00e4f1a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ty/llvm-project/build/bin/mlir-opt+0xd61f1a)
 #1 0x000055aad00e208c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f667e900980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #3 0x00007f667d5b1e87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #4 0x00007f667d5b37f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
 #5 0x00007f667d5a33fa __assert_fail_base /build/glibc-CVJwZb/glibc-2.27/assert/assert.c:89:0
 #6 0x00007f667d5a3472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
 #7 0x000055aad0259d50 mlir::affine::hoistAffineIfOp(mlir::affine::AffineIfOp, bool*) (/home/ty/llvm-project/build/bin/mlir-opt+0xed6d50)
 #8 0x000055aad1adcb91 _ZN4llvm12function_refIFN4mlir10WalkResultEPNS1_9OperationEEE11callback_fnIZNS1_6detail4walkILNS1_9WalkOrderE1ENS1_15ForwardIteratorERZN12_GLOBAL__N_125TestAffineLoopUnswitching14runOnOperationEvEUlNS1_6affine10AffineIfOpEE_SF_S2_EENSt9enable_ifIXaantsrSt11disjunctionIJSt7is_sameIT2_S4_ESK_ISL_PNS1_6RegionEESK_ISL_PNS1_5BlockEEEE5valuesrSK_IT3_S2_E5valueESU_E4typeES4_OT1_EUlS4_E_EES2_lS4_ TestAffineLoopUnswitching.cpp:0:0
 #9 0x000055aad1adc5fe mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (.constprop.76) TestAffineLoopUnswitching.cpp:0:0
#10 0x000055aad1adc5fe mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (.constprop.76) TestAffineLoopUnswitching.cpp:0:0
#11 0x000055aad1adc9ea (anonymous namespace)::TestAffineLoopUnswitching::runOnOperation() TestAffineLoopUnswitching.cpp:0:0
#12 0x000055aad1f8ab2e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/ty/llvm-project/build/bin/mlir-opt+0x2c07b2e)
#13 0x000055aad1f8b983 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (.constprop.510) Pass.cpp:0:0
#14 0x000055aad1f8c00d mlir::PassManager::run(mlir::Operation*) (/home/ty/llvm-project/build/bin/mlir-opt+0x2c0900d)
#15 0x000055aad1f7ded7 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#16 0x000055aad1f7e654 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#17 0x000055aad1f7f441 mlir::LogicalResult llvm::function_ref<mlir::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&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#18 0x000055aad205e9f0 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/home/ty/llvm-project/build/bin/mlir-opt+0x2cdb9f0)
#19 0x000055aad1f784c9 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/home/ty/llvm-project/build/bin/mlir-opt+0x2bf54c9)
#20 0x000055aad1f7d0a0 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) (/home/ty/llvm-project/build/bin/mlir-opt+0x2bfa0a0)
#21 0x000055aad00a7a30 main (/home/ty/llvm-project/build/bin/mlir-opt+0xd24a30)
#22 0x00007f667d594c87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#23 0x000055aad00ba6da _start (/home/ty/llvm-project/build/bin/mlir-opt+0xd376da)
@EugeneZelenko EugeneZelenko added mlir:affine crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Apr 24, 2023
@llvmbot
Copy link
Member

llvmbot commented Apr 24, 2023

@llvm/issue-subscribers-mlir-affine

@bondhugula bondhugula self-assigned this Mar 8, 2025
bondhugula added a commit to bondhugula/llvm-project that referenced this issue Mar 8, 2025
Fix obvious crash as a result of missing affine.parallel handling. Also,
fix bug exposed in a helper method used by hoistAffineIfOp. Also, remove
the specialcasing for FuncOp's.

Fixes: llvm#62323
@bondhugula
Copy link
Contributor

Thank you reporting; this allowed fixing two bugs. Fixed now by #130401

llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this issue Mar 8, 2025
…Op (#130401)

Fix obvious crash as a result of missing affine.parallel handling. Also,
fix bug exposed in a helper method used by hoistAffineIfOp.

Fixes: llvm/llvm-project#62323
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir:affine
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants