Skip to content
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

[MLIR]-test-loop-unrolling pass: mlir::loopUnrollByFactor leads to assertion `upperBoundUnrolledCst <= ubCst' #61832

Closed
BealZephyr opened this issue Mar 30, 2023 · 1 comment · Fixed by #69028
Labels
crash Prefer [crash-on-valid] or [crash-on-invalid] mlir

Comments

@BealZephyr
Copy link

BealZephyr commented Mar 30, 2023

Test commit: c3440e2

Steps to reproduce:

mlir-opt test.mlir  -test-loop-unrolling=unroll-factor=2

Test case:

#map = affine_map<(d0)[s0] -> (2, -d0 + s0)>
module {
  func.func @main(%arg0: memref<i64>) {
    %c1 = arith.constant 1 : index
    %c2 = arith.constant 2 : index
    %c4 = arith.constant 4 : index
    scf.for %arg1 = %c1 to %c4 step %c2 {
      %0 = affine.min #map(%arg1)[%c4]
    }
    return
  }
}

crash trace:

mlir-opt: /home/ty/llvm-project/mlir/lib/Dialect/SCF/Utils/Utils.cpp:498: mlir::LogicalResult mlir::loopUnrollByFactor(mlir::scf::ForOp, uint64_t, mlir::function_ref<void(unsigned int, mlir::Operation*, mlir::OpBuilder)>): Assertion `upperBoundUnrolledCst <= ubCst' 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 "-test-loop-unrolling=unroll-factor=2 "
 #0 0x000055b9d54880da llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/ty/llvm-project/build/bin/mlir-opt+0x22b0da)
 #1 0x000055b9d548536c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f12c455d980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #3 0x00007f12c320ee87 raise /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #4 0x00007f12c32107f1 abort /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:81:0
 #5 0x00007f12c32003fa __assert_fail_base /build/glibc-CVJwZb/glibc-2.27/assert/assert.c:89:0
 #6 0x00007f12c3200472 (/lib/x86_64-linux-gnu/libc.so.6+0x30472)
 #7 0x000055b9d603824f mlir::loopUnrollByFactor(mlir::scf::ForOp, unsigned long, llvm::function_ref<void (unsigned int, mlir::Operation*, mlir::OpBuilder)>) (/home/ty/llvm-project/build/bin/mlir-opt+0xddb24f)
 #8 0x000055b9d6a14e8f (anonymous namespace)::TestLoopUnrollingPass::runOnOperation() TestLoopUnrolling.cpp:0:0
 #9 0x000055b9d6da2bee mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/ty/llvm-project/build/bin/mlir-opt+0x1b45bee)
#10 0x000055b9d6da3a43 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
#11 0x000055b9d6da40cd mlir::PassManager::run(mlir::Operation*) (/home/ty/llvm-project/build/bin/mlir-opt+0x1b470cd)
#12 0x000055b9d6d98043 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#13 0x000055b9d6d98711 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
#14 0x000055b9d6d98901 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
#15 0x000055b9d6e6a810 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+0x1c0d810)
#16 0x000055b9d6d93a23 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+0x1b36a23)
#17 0x000055b9d6d9624e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) (/home/ty/llvm-project/build/bin/mlir-opt+0x1b3924e)
#18 0x000055b9d54540c0 main (/home/ty/llvm-project/build/bin/mlir-opt+0x1f70c0)
#19 0x00007f12c31f1c87 __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:344:0
#20 0x000055b9d5466f2a _start (/home/ty/llvm-project/build/bin/mlir-opt+0x209f2a)
Aborted                 (core dumped)
@EugeneZelenko EugeneZelenko added mlir crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Mar 30, 2023
@llvmbot
Copy link
Member

llvmbot commented Mar 30, 2023

@llvm/issue-subscribers-mlir

ftynse pushed a commit that referenced this issue Oct 16, 2023
In particular, `upperBoundUnrolledCst` may be larger than `ubCst` when:

1. the step size is greater than 1;
2. `ub - lb` is not evenly divisible by the step size; and
3. the loop's trip count is evenly divisible by the unroll factor.

This is okay since the non-unit step size ensures that the unrolled loop
maintains the same trip count as the original loop. Added a test case
for this.

Fixes #61832.

Co-authored-by: Stephen Chou <[email protected]>
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
Projects
None yet
3 participants