llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.69k stars 11.86k forks source link

[mlir] `mlir::isValidSymbol` verifier crashes with assertion violation : index.has_value() && "expect only `dim` operations with a constant index" #59993

Closed Colloportus0 closed 1 year ago

Colloportus0 commented 1 year ago

MLIR built at commit https://github.com/llvm/llvm-project/commit/a0138390 Reproduced with:
mlir-opt --convert-func-to-llvm temp.mlir

temp.mlir:

#map = affine_map<()[s0] -> (s0)> 
module {
  func.func @func(%arg0: memref<?x?xf32>, %0: index) { 
    %dim = memref.dim %arg0, %0 : memref<?x?xf32> 
    %1 = affine.apply #map()[%dim] 
    affine.for %arg1 = 0 to %1 {  
    }
    return
  }
}

trace:

Assertion failed: (index.has_value() && "expect only `dim` operations with a constant index"), function isDimOpValidSymbol, file AffineOps.cpp, line 340.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: mlir-opt --convert-func-to-llvm temp.mlir
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  mlir-opt                 0x0000000104ef45bc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  mlir-opt                 0x0000000104ef3624 llvm::sys::RunSignalHandlers() + 112
2  mlir-opt                 0x0000000104ef4c54 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x00000001a56894c4 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001a5671ee0 pthread_kill + 288
5  libsystem_c.dylib        0x00000001a55ac340 abort + 168
6  libsystem_c.dylib        0x00000001a55ab754 err + 0
7  mlir-opt                 0x000000010643d42c mlir::isValidSymbol(mlir::Value, mlir::Region*) (.cold.3) + 0
8  mlir-opt                 0x0000000104f10004 mlir::isValidSymbol(mlir::Value, mlir::Region*) + 716
9  mlir-opt                 0x0000000104f17cb0 mlir::LogicalResult verifyDimAndSymbolIdentifiers<mlir::AffineForOp>(mlir::AffineForOp&, mlir::OperandRange, unsigned int) + 244
10 mlir-opt                 0x0000000104f17a24 mlir::AffineForOp::verifyRegions() + 524
11 mlir-opt                 0x0000000104f3680c mlir::Op<mlir::AffineForOp, mlir::OpTrait::OneRegion, mlir::OpTrait::VariadicResults, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::VariadicOperands, mlir::OpTrait::SingleBlockImplicitTerminator<mlir::AffineYieldOp>::Impl, mlir::OpTrait::OpInvariants, mlir::OpTrait::AutomaticAllocationScope, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::HasRecursiveMemoryEffects, mlir::LoopLikeOpInterface::Trait, mlir::RegionBranchOpInterface::Trait>::verifyRegionInvariants(mlir::Operation*) + 72
12 mlir-opt                 0x0000000106221c94 (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) + 2336
13 mlir-opt                 0x0000000106221694 (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) + 800
14 mlir-opt                 0x000000010622274c mlir::LogicalResult mlir::failableParallelForEach<mlir::Operation**, (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&)::$_0>(mlir::MLIRContext*, mlir::Operation**, mlir::Operation**, (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&)::$_0&&) + 352
15 mlir-opt                 0x0000000106221c68 (anonymous namespace)::OperationVerifier::verifyOperation(mlir::Operation&) + 2292
16 mlir-opt                 0x000000010622130c mlir::verify(mlir::Operation*, bool) + 36
17 mlir-opt                 0x00000001060ff674 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) + 828
18 mlir-opt                 0x00000001060ffa0c mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) + 320
19 mlir-opt                 0x0000000106101388 mlir::PassManager::run(mlir::Operation*) + 1148
20 mlir-opt                 0x00000001060fa840 performActions(llvm::raw_ostream&, bool, bool, std::__1::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, bool, bool) + 504
21 mlir-opt                 0x00000001060fa410 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::$_0>(long, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) + 704
22 mlir-opt                 0x000000010616502c mlir::splitAndProcessBuffer(std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) + 656
23 mlir-opt                 0x00000001060f8838 mlir::MlirOptMain(llvm::raw_ostream&, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (mlir::PassManager&)>, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool) + 216
24 mlir-opt                 0x00000001060f8d2c mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) + 1208
25 mlir-opt                 0x0000000104d970a0 main + 108
26 dyld                     0x0000000109619088 start + 516
zsh: abort      mlir-opt --convert-func-to-llvm temp.mlir
llvmbot commented 1 year ago

@llvm/issue-subscribers-mlir

joker-eph commented 1 year ago

Here is the IR post running the pass:

"llvm.func"() ({
^bb0(%arg0: !llvm.ptr<f32>, %arg1: !llvm.ptr<f32>, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: i64):
  %0 = "builtin.unrealized_conversion_cast"(%arg7) : (i64) -> index
  %1 = "llvm.mlir.undef"() : () -> !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
  %2 = "llvm.insertvalue"(%1, %arg0) {position = array<i64: 0>} : (!llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>, !llvm.ptr<f32>) -> !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
  %3 = "llvm.insertvalue"(%2, %arg1) {position = array<i64: 1>} : (!llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>, !llvm.ptr<f32>) -> !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
  %4 = "llvm.insertvalue"(%3, %arg2) {position = array<i64: 2>} : (!llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>, i64) -> !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
  %5 = "llvm.insertvalue"(%4, %arg3) {position = array<i64: 3, 0>} : (!llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>, i64) -> !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
  %6 = "llvm.insertvalue"(%5, %arg5) {position = array<i64: 4, 0>} : (!llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>, i64) -> !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
  %7 = "llvm.insertvalue"(%6, %arg4) {position = array<i64: 3, 1>} : (!llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>, i64) -> !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
  %8 = "llvm.insertvalue"(%7, %arg6) {position = array<i64: 4, 1>} : (!llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>, i64) -> !llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>
  %9 = "builtin.unrealized_conversion_cast"(%8) : (!llvm.struct<(ptr<f32>, ptr<f32>, i64, array<2 x i64>, array<2 x i64>)>) -> memref<?x?xf32>
  %10 = "memref.dim"(%9, %0) : (memref<?x?xf32>, index) -> index
  "affine.for"(%10) ({
  ^bb0(%arg8: index):
    "affine.yield"() : () -> ()
  }) {lower_bound = affine_map<() -> (0)>, step = 1 : index, upper_bound = affine_map<()[s0] -> (s0)>} : (index) -> ()
  "llvm.return"() : () -> ()
}) {CConv = #llvm.cconv<ccc>, function_type = !llvm.func<void (ptr<f32>, ptr<f32>, i64, i64, i64, i64, i64, i64)>, linkage = #llvm.linkage<external>, sym_name = "func"} : () -> ()

This is then a verifier crash for mlir::isValidSymbol. @bondhugula or @ftynse may be able to help here?

ftynse commented 1 year ago

I believe the assertion is incorrect there and was not updated when we changed memref.dim to take the dimension index as an operand instead of an attribute. https://reviews.llvm.org/D142204

llvmbot commented 1 year ago

@llvm/issue-subscribers-mlir-affine