<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/119525>119525</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [mlir] --affine-loop-fusion crashes in IR/AffineOps.cpp
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Emilyaxe
      </td>
    </tr>
</table>

<pre>
    git version: 953838dceaf

system: `Ubuntu 18.04.6 LTS`

reproduce with: `mlir-opt --affine-loop-fusion a.mlir`


a.mlir: 
``` 
#map = affine_map<(d0) -> (d0)>
#map1 = affine_map<(d0) -> (d0 + 1)>
module {
 func.func @func4(%arg0: memref<1x8x26xi32, strided<[?, ?, ?], offset: ?>>, %arg1: memref<1x8x26xi32, strided<[?, ?, ?], offset: ?>>, %arg2: memref<1x8x26xi32, strided<[?, ?, ?], offset: ?>>) {
    %alloc_14 = memref.alloc() : memref<1x8x26xi32>
    %alloc_15 = memref.alloc() : memref<1x26xi32>
    affine.for %arg3 = 0 to 1 {
      affine.for %arg4 = 0 to 8 {
        affine.for %arg5 = 0 to 26 {
          affine.for %arg6 = #map(%arg3) to #map1(%arg3) {
            affine.for %arg7 = #map(%arg4) to #map1(%arg4) {
              affine.for %arg8 = #map(%arg5) to #map1(%arg5) {
                %61 = affine.load %alloc_14[%arg6, %arg7, %arg8] : memref<1x8x26xi32>
                %62 = affine.load %alloc_15[%arg6, %arg8] : memref<1x26xi32>
                %63 = llvm.intr.smin(%61, %62) : (i32, i32) -> i32
                affine.store %63, %alloc_15[%arg6, %arg8] : memref<1x26xi32>
              }
            }
          }
        }
 }
    }
    affine.for %arg3 = 0 to 26 {
      %61 = affine.load %alloc_15[0, %arg3] : memref<1x26xi32>
    }
    memref.dealloc %alloc_15 : memref<1x26xi32>
    memref.dealloc %alloc_14 : memref<1x8x26xi32>
 return 
  }
}


``` 
stack trace:

``` 
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/mlir/lib/Dialect/Affine/IR/AffineOps.cpp:2404: void mlir::affine::AffineForOp::setLowerBound(ValueRange, AffineMap): Assertion `map.getNumResults() >= 1 && "bound map has at least one result"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt a.mlir --affine-loop-fusion
 #0 0x000055c096253158 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1136158)
 #1 0x000055c096250c6e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1133c6e)
 #2 0x000055c096253aed SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fa03b178420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fa03a7b500b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007fa03a794859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007fa03a794729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007fa03a794729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007fa03a7a5fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x000055c0962f380f (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11d680f)
#10 0x000055c0963a3f66 mlir::affine::fuseLoops(mlir::affine::AffineForOp, mlir::affine::AffineForOp, mlir::affine::ComputationSliceState const&, bool) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1286f66)
#11 0x000055c096379f60 (anonymous namespace)::GreedyFusion::performFusionsIntoDest(unsigned int, unsigned int) LoopFusion.cpp:0:0
#12 0x000055c096377c95 (anonymous namespace)::GreedyFusion::fuseProducerConsumerNodes(unsigned int) LoopFusion.cpp:0:0
#13 0x000055c096377729 void llvm::function_ref<void (mlir::Operation*)>::callback_fn<(anonymous namespace)::LoopFusion::runOnOperation()::$_0>(long, mlir::Operation*) LoopFusion.cpp:0:0
#14 0x000055c09636913e void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x124c13e)
#15 0x000055c096374aba (anonymous namespace)::LoopFusion::runOnOperation() LoopFusion.cpp:0:0
#16 0x000055c0996942b6 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45772b6)
#17 0x000055c099694be0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4577be0)
#18 0x000055c0996971b2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x457a1b2)
#19 0x000055c09968fa5a performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#20 0x000055c09968f6ad 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
#21 0x000055c09973bb25 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) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x461eb25)
#22 0x000055c099689695 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x456c695)
#23 0x000055c09968993f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x456c93f)
#24 0x000055c099689c6e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x456cc6e)
#25 0x000055c096233c47 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1116c47)
#26 0x00007fa03a796083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#27 0x000055c0962337be _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11167be)

``` 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWl9T47oV_zTiRUNGlvz3gYcQSMsMXBjYto8Z2ZaNurbkSjIL_fQdSU4cmwTYezdz285AYktH55zf-SvLoVrzWjB2AaJLEF2d0d48S3Vx3fLmjb6ys1yWbxc1N_CFKc2lAGQJs4ikJC0LRiu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