llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[mlir] Canonicalizer crashed in mlir::simplifyAffineExpr with Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

Open kig9981 opened this issue 1 year ago • 4 comments

git version: 30725ef

system: Ubuntu 22.04.5 LTS

reproduced with: mlir-opt -canonicalize a.mlir

a.mlir:

func.func @test(%arg0: tensor<?x256xf32>) -> index {
    %c0 = arith.constant 0 : index
    %c1 = arith.constant 1 : index
    %c3 = arith.constant 3 : index
    %c12345 = arith.constant 12345 : index
    %dim = tensor.dim %arg0, %c0 : tensor<?x256xf32>
    %0 = arith.cmpi sge, %dim, %c12345 : index
    %1 = arith.index_castui %0 : i1 to index
    %2 = affine.apply affine_map<()[s0] -> (s0 * 2 + (-s0 + 1) * s0)>()[%1]
    %3 = arith.cmpi sgt, %2, %c3 : index
    %4 = arith.index_castui %3 : i1 to index
    %5 = arith.cmpi eq, %2, %c3 : index
    %6 = arith.index_castui %5 : i1 to index
    %7 = affine.apply affine_map<()[s0, s1, s2, s3] -> (s0 floordiv (s1 + (-s1 + 1) * (-s2 + s2 * s3 + 1)))>()[%c12345, %4, %6, %c1]
    return %7 : index
}

trace:

mlir-opt: /home/lawali/llvm-project/llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From &) [To = mlir::AffineBinaryOpExpr, From = mlir::AffineExpr]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' 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/lawali/llvm-project/build/bin/mlir-opt -canonicalize a.mlir
 #0 0x00005648d119064d llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/lawali/llvm-project/llvm/lib/Support/Unix/Signals.inc:804:11
 #1 0x00005648d1190bcb PrintStackTraceSignalHandler(void*) /home/lawali/llvm-project/llvm/lib/Support/Unix/Signals.inc:888:1
 #2 0x00005648d118ec56 llvm::sys::RunSignalHandlers() /home/lawali/llvm-project/llvm/lib/Support/Signals.cpp:105:5
 #3 0x00005648d119131d SignalHandler(int, siginfo_t*, void*) /home/lawali/llvm-project/llvm/lib/Support/Unix/Signals.inc:418:7
 #4 0x00007fa729dc7520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007fa729e1b9fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #6 0x00007fa729dc7476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #7 0x00007fa729dad7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #8 0x00007fa729dad71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #9 0x00007fa729dbee96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x00005648d1388df8 decltype(auto) llvm::cast<mlir::AffineBinaryOpExpr, mlir::AffineExpr>(mlir::AffineExpr&) /home/lawali/llvm-project/llvm/include/llvm/Support/Casting.h:573:37
#11 0x00005648d71d1fd7 getSemiAffineExprFromFlatForm(llvm::ArrayRef<long>, unsigned int, unsigned int, llvm::ArrayRef<mlir::AffineExpr>, mlir::MLIRContext*) /home/lawali/llvm-project/mlir/lib/IR/AffineExpr.cpp:1180:22
#12 0x00005648d71d1819 mlir::simplifyAffineExpr(mlir::AffineExpr, unsigned int, unsigned int) /home/lawali/llvm-project/mlir/lib/IR/AffineExpr.cpp:1590:13
#13 0x00005648d71e18f2 mlir::simplifyAffineMap(mlir::AffineMap) /home/lawali/llvm-project/mlir/lib/IR/AffineMap.cpp:774:9
#14 0x00005648d1294fcc composeAffineMapAndOperands(mlir::AffineMap*, llvm::SmallVectorImpl<mlir::Value>*) /home/lawali/llvm-project/mlir/lib/Dialect/Affine/IR/AffineOps.cpp:1162:10
#15 0x00005648d12ddef8 (anonymous namespace)::SimplifyAffineOp<mlir::affine::AffineApplyOp>::matchAndRewrite(mlir::affine::AffineApplyOp, mlir::PatternRewriter&) const /home/lawali/llvm-project/mlir/lib/Dialect/Affine/IR/AffineOps.cpp:1552:38
#16 0x00005648d137743b mlir::detail::OpOrInterfaceRewritePatternBase<mlir::affine::AffineApplyOp>::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /home/lawali/llvm-project/mlir/include/mlir/IR/PatternMatch.h:299:12
#17 0x00005648dc904be6 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&)>)::$_1::operator()() const /home/lawali/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:212:31
#18 0x00005648dc904a25 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&)>)::$_1>(long) /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
#19 0x00005648d11b6de9 llvm::function_ref<void ()>::operator()() const /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
#20 0x00005648dc9064dd void mlir::MLIRContext::executeAction<mlir::ApplyPatternAction, mlir::Pattern const&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pattern const&) /home/lawali/llvm-project/mlir/include/mlir/IR/MLIRContext.h:281:3
#21 0x00005648dc90339a 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&)>) /home/lawali/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:233:9
#22 0x00005648d716249d (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() /home/lawali/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:616:17
#23 0x00005648d71616b1 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::$_8::operator()() const /home/lawali/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:875:30
#24 0x00005648d7161685 void llvm::function_ref<void ()>::callback_fn<(anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::$_8>(long) /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
#25 0x00005648d11b6de9 llvm::function_ref<void ()>::operator()() const /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
#26 0x00005648d7160d4d void mlir::MLIRContext::executeAction<(anonymous namespace)::GreedyPatternRewriteIteration, long&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, long&) /home/lawali/llvm-project/mlir/include/mlir/IR/MLIRContext.h:281:3
#27 0x00005648d715f1ed (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) && /home/lawali/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:888:3
#28 0x00005648d715ee94 mlir::applyPatternsGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/lawali/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:920:47
#29 0x00005648d13cdc00 mlir::applyPatternsGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/lawali/llvm-project/mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h:224:15
#30 0x00005648d7091632 (anonymous namespace)::Canonicalizer::runOnOperation() /home/lawali/llvm-project/mlir/lib/Transforms/Canonicalizer.cpp:64:9
#31 0x00005648d703971b mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7::operator()() const /home/lawali/llvm-project/mlir/lib/Pass/Pass.cpp:0:17
#32 0x00005648d70396b5 void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7>(long) /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
#33 0x00005648d11b6de9 llvm::function_ref<void ()>::operator()() const /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
#34 0x00005648d703da0d void mlir::MLIRContext::executeAction<mlir::PassExecutionAction, mlir::Pass&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pass&) /home/lawali/llvm-project/mlir/include/mlir/IR/MLIRContext.h:281:3
#35 0x00005648d7034c8a mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/lawali/llvm-project/mlir/lib/Pass/Pass.cpp:563:17
#36 0x00005648d7035244 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/lawali/llvm-project/mlir/lib/Pass/Pass.cpp:623:16
#37 0x00005648d7036d4c mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/lawali/llvm-project/mlir/lib/Pass/Pass.cpp:937:10
#38 0x00005648d7036c6f mlir::PassManager::run(mlir::Operation*) /home/lawali/llvm-project/mlir/lib/Pass/Pass.cpp:917:60
#39 0x00005648d702560a performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:484:17
#40 0x00005648d70251bd processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:552:12
#41 0x00005648d7024f7b mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_3::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:636:12
#42 0x00005648d7024efd 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&)::$_3>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#43 0x00005648d71c9ab9 llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:12
#44 0x00005648d71c9060 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) /home/lawali/llvm-project/mlir/lib/Support/ToolUtilities.cpp:27:12
#45 0x00005648d7020f76 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:639:10
#46 0x00005648d7021341 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:680:14
#47 0x00005648d7021518 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:696:10
#48 0x00005648d10f184f main /home/lawali/llvm-project/mlir/tools/mlir-opt/mlir-opt.cpp:339:33
#49 0x00007fa729daed90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#50 0x00007fa729daee40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#51 0x00005648d10f1435 _start (/home/lawali/llvm-project/build/bin/mlir-opt+0x3644435)

kig9981 avatar Jun 13 '25 15:06 kig9981

@llvm/issue-subscribers-mlir

Author: Ingu Kang (kig9981)

git version: [30725ef](https://github.com/llvm/llvm-project/commit/30725efe671bc82bf9095a575aece60fc40fbef5)

system: Ubuntu 22.04.5 LTS

reproduced with: mlir-opt -canonicalize a.mlir

a.mlir:

func.func @<!-- -->test(%arg0: tensor&lt;?x256xf32&gt;) -&gt; index {
    %c0 = arith.constant 0 : index
    %c1 = arith.constant 1 : index
    %c3 = arith.constant 3 : index
    %c12345 = arith.constant 12345 : index
    %dim = tensor.dim %arg0, %c0 : tensor&lt;?x256xf32&gt;
    %0 = arith.cmpi sge, %dim, %c12345 : index
    %1 = arith.index_castui %0 : i1 to index
    %2 = affine.apply affine_map&lt;()[s0] -&gt; (s0 * 2 + (-s0 + 1) * s0)&gt;()[%1]
    %3 = arith.cmpi sgt, %2, %c3 : index
    %4 = arith.index_castui %3 : i1 to index
    %5 = arith.cmpi eq, %2, %c3 : index
    %6 = arith.index_castui %5 : i1 to index
    %7 = affine.apply affine_map&lt;()[s0, s1, s2, s3] -&gt; (s0 floordiv (s1 + (-s1 + 1) * (-s2 + s2 * s3 + 1)))&gt;()[%c12345, %4, %6, %c1]
    return %7 : index
}

trace:

mlir-opt: /home/lawali/llvm-project/llvm/include/llvm/Support/Casting.h:572: decltype(auto) llvm::cast(From &amp;) [To = mlir::AffineBinaryOpExpr, From = mlir::AffineExpr]: Assertion `isa&lt;To&gt;(Val) &amp;&amp; "cast&lt;Ty&gt;() argument of incompatible type!"' 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/lawali/llvm-project/build/bin/mlir-opt -canonicalize a.mlir
 #<!-- -->0 0x00005648d119064d llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) /home/lawali/llvm-project/llvm/lib/Support/Unix/Signals.inc:804:11
 #<!-- -->1 0x00005648d1190bcb PrintStackTraceSignalHandler(void*) /home/lawali/llvm-project/llvm/lib/Support/Unix/Signals.inc:888:1
 #<!-- -->2 0x00005648d118ec56 llvm::sys::RunSignalHandlers() /home/lawali/llvm-project/llvm/lib/Support/Signals.cpp:105:5
 #<!-- -->3 0x00005648d119131d SignalHandler(int, siginfo_t*, void*) /home/lawali/llvm-project/llvm/lib/Support/Unix/Signals.inc:418:7
 #<!-- -->4 0x00007fa729dc7520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #<!-- -->5 0x00007fa729e1b9fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #<!-- -->6 0x00007fa729dc7476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #<!-- -->7 0x00007fa729dad7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #<!-- -->8 0x00007fa729dad71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #<!-- -->9 0x00007fa729dbee96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#<!-- -->10 0x00005648d1388df8 decltype(auto) llvm::cast&lt;mlir::AffineBinaryOpExpr, mlir::AffineExpr&gt;(mlir::AffineExpr&amp;) /home/lawali/llvm-project/llvm/include/llvm/Support/Casting.h:573:37
#<!-- -->11 0x00005648d71d1fd7 getSemiAffineExprFromFlatForm(llvm::ArrayRef&lt;long&gt;, unsigned int, unsigned int, llvm::ArrayRef&lt;mlir::AffineExpr&gt;, mlir::MLIRContext*) /home/lawali/llvm-project/mlir/lib/IR/AffineExpr.cpp:1180:22
#<!-- -->12 0x00005648d71d1819 mlir::simplifyAffineExpr(mlir::AffineExpr, unsigned int, unsigned int) /home/lawali/llvm-project/mlir/lib/IR/AffineExpr.cpp:1590:13
#<!-- -->13 0x00005648d71e18f2 mlir::simplifyAffineMap(mlir::AffineMap) /home/lawali/llvm-project/mlir/lib/IR/AffineMap.cpp:774:9
#<!-- -->14 0x00005648d1294fcc composeAffineMapAndOperands(mlir::AffineMap*, llvm::SmallVectorImpl&lt;mlir::Value&gt;*) /home/lawali/llvm-project/mlir/lib/Dialect/Affine/IR/AffineOps.cpp:1162:10
#<!-- -->15 0x00005648d12ddef8 (anonymous namespace)::SimplifyAffineOp&lt;mlir::affine::AffineApplyOp&gt;::matchAndRewrite(mlir::affine::AffineApplyOp, mlir::PatternRewriter&amp;) const /home/lawali/llvm-project/mlir/lib/Dialect/Affine/IR/AffineOps.cpp:1552:38
#<!-- -->16 0x00005648d137743b mlir::detail::OpOrInterfaceRewritePatternBase&lt;mlir::affine::AffineApplyOp&gt;::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&amp;) const /home/lawali/llvm-project/mlir/include/mlir/IR/PatternMatch.h:299:12
#<!-- -->17 0x00005648dc904be6 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&amp;, llvm::function_ref&lt;bool (mlir::Pattern const&amp;)&gt;, llvm::function_ref&lt;void (mlir::Pattern const&amp;)&gt;, llvm::function_ref&lt;llvm::LogicalResult (mlir::Pattern const&amp;)&gt;)::$_1::operator()() const /home/lawali/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:212:31
#<!-- -->18 0x00005648dc904a25 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&amp;, llvm::function_ref&lt;bool (mlir::Pattern const&amp;)&gt;, llvm::function_ref&lt;void (mlir::Pattern const&amp;)&gt;, llvm::function_ref&lt;llvm::LogicalResult (mlir::Pattern const&amp;)&gt;)::$_1&gt;(long) /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
#<!-- -->19 0x00005648d11b6de9 llvm::function_ref&lt;void ()&gt;::operator()() const /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
#<!-- -->20 0x00005648dc9064dd void mlir::MLIRContext::executeAction&lt;mlir::ApplyPatternAction, mlir::Pattern const&amp;&gt;(llvm::function_ref&lt;void ()&gt;, llvm::ArrayRef&lt;mlir::IRUnit&gt;, mlir::Pattern const&amp;) /home/lawali/llvm-project/mlir/include/mlir/IR/MLIRContext.h:281:3
#<!-- -->21 0x00005648dc90339a mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&amp;, llvm::function_ref&lt;bool (mlir::Pattern const&amp;)&gt;, llvm::function_ref&lt;void (mlir::Pattern const&amp;)&gt;, llvm::function_ref&lt;llvm::LogicalResult (mlir::Pattern const&amp;)&gt;) /home/lawali/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:233:9
#<!-- -->22 0x00005648d716249d (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() /home/lawali/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:616:17
#<!-- -->23 0x00005648d71616b1 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &amp;&amp;::$_8::operator()() const /home/lawali/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:875:30
#<!-- -->24 0x00005648d7161685 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;(anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &amp;&amp;::$_8&gt;(long) /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
#<!-- -->25 0x00005648d11b6de9 llvm::function_ref&lt;void ()&gt;::operator()() const /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
#<!-- -->26 0x00005648d7160d4d void mlir::MLIRContext::executeAction&lt;(anonymous namespace)::GreedyPatternRewriteIteration, long&amp;&gt;(llvm::function_ref&lt;void ()&gt;, llvm::ArrayRef&lt;mlir::IRUnit&gt;, long&amp;) /home/lawali/llvm-project/mlir/include/mlir/IR/MLIRContext.h:281:3
#<!-- -->27 0x00005648d715f1ed (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &amp;&amp; /home/lawali/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:888:3
#<!-- -->28 0x00005648d715ee94 mlir::applyPatternsGreedily(mlir::Region&amp;, mlir::FrozenRewritePatternSet const&amp;, mlir::GreedyRewriteConfig, bool*) /home/lawali/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:920:47
#<!-- -->29 0x00005648d13cdc00 mlir::applyPatternsGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&amp;, mlir::GreedyRewriteConfig, bool*) /home/lawali/llvm-project/mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h:224:15
#<!-- -->30 0x00005648d7091632 (anonymous namespace)::Canonicalizer::runOnOperation() /home/lawali/llvm-project/mlir/lib/Transforms/Canonicalizer.cpp:64:9
#<!-- -->31 0x00005648d703971b mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7::operator()() const /home/lawali/llvm-project/mlir/lib/Pass/Pass.cpp:0:17
#<!-- -->32 0x00005648d70396b5 void llvm::function_ref&lt;void ()&gt;::callback_fn&lt;mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_7&gt;(long) /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
#<!-- -->33 0x00005648d11b6de9 llvm::function_ref&lt;void ()&gt;::operator()() const /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
#<!-- -->34 0x00005648d703da0d void mlir::MLIRContext::executeAction&lt;mlir::PassExecutionAction, mlir::Pass&amp;&gt;(llvm::function_ref&lt;void ()&gt;, llvm::ArrayRef&lt;mlir::IRUnit&gt;, mlir::Pass&amp;) /home/lawali/llvm-project/mlir/include/mlir/IR/MLIRContext.h:281:3
#<!-- -->35 0x00005648d7034c8a mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/lawali/llvm-project/mlir/lib/Pass/Pass.cpp:563:17
#<!-- -->36 0x00005648d7035244 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&amp;, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/lawali/llvm-project/mlir/lib/Pass/Pass.cpp:623:16
#<!-- -->37 0x00005648d7036d4c mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/lawali/llvm-project/mlir/lib/Pass/Pass.cpp:937:10
#<!-- -->38 0x00005648d7036c6f mlir::PassManager::run(mlir::Operation*) /home/lawali/llvm-project/mlir/lib/Pass/Pass.cpp:917:60
#<!-- -->39 0x00005648d702560a performActions(llvm::raw_ostream&amp;, std::shared_ptr&lt;llvm::SourceMgr&gt; const&amp;, mlir::MLIRContext*, mlir::MlirOptMainConfig const&amp;) /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:484:17
#<!-- -->40 0x00005648d70251bd processBuffer(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::MlirOptMainConfig const&amp;, mlir::DialectRegistry&amp;, llvm::ThreadPoolInterface*) /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:552:12
#<!-- -->41 0x00005648d7024f7b mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;)::$_3::operator()(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;) const /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:636:12
#<!-- -->42 0x00005648d7024efd llvm::LogicalResult llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;)&gt;::callback_fn&lt;mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;)::$_3&gt;(long, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;) /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#<!-- -->43 0x00005648d71c9ab9 llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;)&gt;::operator()(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;) const /home/lawali/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:12
#<!-- -->44 0x00005648d71c9060 mlir::splitAndProcessBuffer(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::raw_ostream&amp;)&gt;, llvm::raw_ostream&amp;, llvm::StringRef, llvm::StringRef) /home/lawali/llvm-project/mlir/lib/Support/ToolUtilities.cpp:27:12
#<!-- -->45 0x00005648d7020f76 mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;) /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:639:10
#<!-- -->46 0x00005648d7021341 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&amp;) /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:680:14
#<!-- -->47 0x00005648d7021518 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&amp;) /home/lawali/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:696:10
#<!-- -->48 0x00005648d10f184f main /home/lawali/llvm-project/mlir/tools/mlir-opt/mlir-opt.cpp:339:33
#<!-- -->49 0x00007fa729daed90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->50 0x00007fa729daee40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->51 0x00005648d10f1435 _start (/home/lawali/llvm-project/build/bin/mlir-opt+0x3644435)

llvmbot avatar Jun 13 '25 15:06 llvmbot

The code assumes that localExprs are all AffineBinaryOpExpr.

https://github.com/llvm/llvm-project/blob/30725efe671bc82bf9095a575aece60fc40fbef5/mlir/lib/IR/AffineExpr.cpp#L1172-L1181

It seems that line 1480 returns constExpr when both a and b are constant, by simplifyFloorDiv.

https://github.com/llvm/llvm-project/blob/30725efe671bc82bf9095a575aece60fc40fbef5/mlir/lib/IR/AffineExpr.cpp#L1449-L1482

kig9981 avatar Jun 13 '25 16:06 kig9981

Is anyone working on this issue?

Ameya674 avatar Jun 19 '25 05:06 Ameya674

Yes, I'll open a PR later.

CoTinker avatar Jun 20 '25 01:06 CoTinker