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

    <tr>
        <th>Summary</th>
        <td>
            [mlir][affine] -lower-affine crashes in AffineToStandard/AffineToStandard.cpp:46: Value buildMinMaxReductionSeq(Location, arith::CmpIPredicate, ValueRange, OpBuilder &): Assertion `!values.empty() && "empty min/max chain"' failed.
        </td>
    </tr>

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

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

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

<pre>
    
git version: 8168088f0a9015b

system: `Ubuntu 18.04.6 LTS`

reproduce with: `mlir-opt -lower-affine a.mlir`

a.mlir:
``` 
#map = affine_map<() -> ()>
module {
  func.func private @check_type(%arg0: i64, %arg1: i64) {
    %0 = builtin.unrealized_conversion_cast %arg1 : i64 to index
    %1 = builtin.unrealized_conversion_cast %arg0 : i64 to index
    scf.for %arg2 = %1 to %0 step %0 {
      %2 = affine.min #map()
      %3 = affine.max #map()
      "test.foo"(%2) : (index) -> ()
    }
    return
  }
}
``` 
stack trace:

``` 
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/mlir/lib/Conversion/AffineToStandard/AffineToStandard.cpp:46: Value buildMinMaxReductionSeq(Location, arith::CmpIPredicate, ValueRange, OpBuilder &): Assertion `!values.empty() && "empty min/max chain"' 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 -lower-affine /data/szy/MLIR/seed/seed28/tmp.bz2QqWhPIF.mlir
 #0 0x0000560d1c2dd2c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10dc2c8)
 #1 0x0000560d1c2dadde llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10d9dde)
 #2 0x0000560d1c2ddc5d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007fd3de2a5420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007fd3dd8e200b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007fd3dd8c1859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007fd3dd8c1729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007fd3dd8c1729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007fd3dd8d2fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x0000560d1ea20e74 buildMinMaxReductionSeq(mlir::Location, mlir::arith::CmpIPredicate, mlir::ValueRange, mlir::OpBuilder&) AffineToStandard.cpp:0:0
#10 0x0000560d1ea22d41 (anonymous namespace)::AffineMinLowering::matchAndRewrite(mlir::affine::AffineMinOp, mlir::PatternRewriter&) const AffineToStandard.cpp:0:0
#11 0x0000560d21e005b1 void llvm::function_ref<void ()>::callback_fn<mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>)::$_0>(long) PatternApplicator.cpp:0:0
#12 0x0000560d21dfd26b mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x6bfc26b)
#13 0x0000560d1f463a13 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#14 0x0000560d1f462a77 mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4261a77)
#15 0x0000560d1f463c3f mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4262c3f)
#16 0x0000560d1f46b8bb mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x426a8bb)
#17 0x0000560d1ea279e6 (anonymous namespace)::LowerAffinePass::runOnOperation() AffineToStandard.cpp:0:0
#18 0x0000560d1f404156 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4203156)
#19 0x0000560d1f404ac0 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+0x4203ac0)
#20 0x0000560d1f407102 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4206102)
#21 0x0000560d1f3ff931 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#22 0x0000560d1f3ff58b 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
#23 0x0000560d1f4abf25 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+0x42aaf25)
#24 0x0000560d1f3fa9b5 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+0x41f99b5)
#25 0x0000560d1f3fac5f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f9c5f)
#26 0x0000560d1f3faf8e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41f9f8e)
#27 0x0000560d1c2bdf07 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10bcf07)
#28 0x00007fd3dd8c3083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#29 0x0000560d1c2bda8e _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x10bca8e)
``` 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWl1v2zrS_jXKDRGDo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