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

    <tr>
        <th>Summary</th>
        <td>
            MLIR mlir::affine::getForInductionVarOwner segfault
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          alex-s168
      </td>
    </tr>
</table>

<pre>
    https://godbolt.org/z/bj4Pbndbd
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/mlir-trunk/bin/mlir-opt -o /app/example.out.mlir --convert-scf-to-cf -convert-bufferization-to-memref -memref-expand --expand-strided-metadata -reconcile-unrealized-casts --convert-to-llvm -reconcile-unrealized-casts --convert-index-to-llvm --lower-affine <source>
 #0 0x00000000014e4988 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x14e4988)
 #1 0x00000000014e22dc SignalHandler(int) Signals.cpp:0:0
 #2 0x00007284b5c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x0000000001587e7d mlir::affine::getForInductionVarOwner(mlir::Value) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x1587e7d)
 #4 0x000000000159ec1b simplifyMinOrMaxExprWithOperands(mlir::AffineMap&, llvm::ArrayRef<mlir::Value>, bool) AffineOps.cpp:0:0
 #5 0x00000000015b8eba mlir::affine::AffineForOp::fold(mlir::affine::AffineForOpGenericAdaptor<llvm::ArrayRef<mlir::Attribute>>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x15b8eba)
 #6 0x00000000015b931d mlir::LogicalResult llvm::detail::UniqueFunctionBase<mlir::LogicalResult, mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&>::CallImpl<mlir::Op<mlir::affine::AffineForOp, mlir::OpTrait::OneRegion, mlir::OpTrait::VariadicResults, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::VariadicOperands, mlir::OpTrait::AttrSizedOperandSegments, mlir::OpTrait::SingleBlock, mlir::OpTrait::SingleBlockImplicitTerminator<mlir::affine::AffineYieldOp>::Impl, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::OpTrait::AutomaticAllocationScope, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::HasRecursiveMemoryEffects, mlir::LoopLikeOpInterface::Trait, mlir::RegionBranchOpInterface::Trait>::getFoldHookFn()::'lambda'(mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) const>(void*, mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x15b931d)
 #7 0x0000000001583cb3 mlir::RegisteredOperationName::Model<mlir::affine::AffineForOp>::foldHook(mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x1583cb3)
 #8 0x0000000003e5cc10 mlir::Operation::fold(llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3e5cc10)
 #9 0x0000000003e5d316 mlir::Operation::fold(llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3e5d316)
#10 0x0000000003db3917 mlir::OpBuilder::tryFold(mlir::Operation*, llvm::SmallVectorImpl<mlir::Value>&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3db3917)
#11 0x0000000003d1d93d (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#12 0x0000000003d1e0c5 mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3d1e0c5)
#13 0x0000000003d20f7b mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3d20f7b)
#14 0x0000000003d214a6 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3d214a6)
#15 0x0000000003418de0 (anonymous namespace)::ConvertToLLVMPass::runOnOperation() ConvertToLLVMPass.cpp:0:0
#16 0x0000000003c7e161 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3c7e161)
#17 0x0000000003c7e5f9 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3c7e5f9)
#18 0x0000000003c7f129 mlir::PassManager::run(mlir::Operation*) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3c7f129)
#19 0x0000000003c700b3 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#20 0x0000000003c70e03 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#21 0x0000000003c70ee3 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
#22 0x0000000003d723be 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&, llvm::StringRef, llvm::StringRef) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3d723be)
#23 0x0000000003c6d16c mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3c6d16c)
#24 0x0000000003c70ffc mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3c70ffc)
#25 0x0000000003c7148f mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x3c7148f)
#26 0x00000000013fe5d7 main (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x13fe5d7)
#27 0x00007284b5c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#28 0x00007284b5c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#29 0x00000000014bae7e _start (/opt/compiler-explorer/mlir-trunk/bin/mlir-opt+0x14bae7e)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWt9T4zgS_mvMiyopR05i-4GHwJAZquCgCMfV3QslS21Hiyz5JJkh89dfyXZIZEgIu6mZ2dvaKWK71fq-r1utHzYxhhcS4DSYnAWTLyektkulT4mAl4EZTZOTTLHV6dLaygTRLMDzAM8LxTIl7FDpIsDzHwGeZ3-MbzPJMhaEX4JwFkzD7v_m8vbqYra4QKbOSm4RQVldIA2V0hZZhXq-uV3W2ZCqMsBzIZ7XfwaVVn8AtQGec2NqMAGeIyIZ4pKKmgGyS0BUE7NEGaFPVhMKw7b7hSX0CbG6rFwvza1wGITprVaFJiUiuqhLkNaBQAGeq8r1QlVZcQF6AC-VUBp0gOel4HpgdS2fHGcu17dUZdFAubakqgI8hxdSVgKGqrZDZ4AGA6rkM2g7MDQfWDWgOXq9ldV5Dpr_IJYr6R6WUGrIUffXAXBEB92PgbGaM2CDEixhxBI00ECVpFzAoJYaiOA_gA0oMdZs9WzVwAl5oDWXDF42bQZCfQc9IHnOJaAgOjeq1hSC6KIVFAU4ClH4Eq7_G41hnCYJakIYzYJoZlam_XGrubRNUO5dlAKcbIw0-f6ojNVAygBPA3yOuLQBTlGAkz8bmgCfhS8dngCnG8CjHmCMGUULXkgivhHJhHOcdP23t82QVi6LwubfqyPcOYpxMs4mdIwnOOwQC54FeP6STB-n44Hgsn4ZFLJuH9ChUcNpA69p4oGLPHCTJIaYIUepFaqNRPu7ADtX-lKymroUeiD65rtswG_sH4io4ShCtlA8rGMfawp0lCHDy0rwfHXN5Y2-Ji8XL5X-F7fLmwo0kcx48GYNnWtSdVHfZMRMa7K6gzyIzvtsogtnmiklHLHWxU21I0YTH2OWQEZ26Nl6mit9U7U3ciWYB3eH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