Issue 239613
Summary [MLIR]Crash in SPIR-V GlobalISel Legalizer when lowering vector.extract operations
Labels mlir
Assignees
Reporter frida-albrecht
    The `--gpu-lower-to-xevm-pipeline` crashes with an assertion failure during SPIR-V code generation when processing vector operations with `vector<128xi48>`.


test commit: [4fb8315](https://github.com/llvm/llvm-project/commit/4fb83151289b8c9f5255d7e899d11ea94374c394)

test case:
```mlir
module attributes {gpu.container_module} {
  gpu.module @func_981975_kernel_0 attributes {dlti.dl_spec = #dlti.dl_spec<index = 32 : i32>} {
    llvm.func spir_funccc @_Z12get_group_idj(i32) -> i64 attributes {memory_effects = #llvm.memory_effects<other = none, argMem = none, inaccessibleMem = none, errnoMem = none, targetMem0 = none, targetMem1 = none>, no_unwind, will_return}
    llvm.func spir_kernelcc @func_981975_kernel(%arg0: !llvm.ptr<1>, %arg1: !llvm.ptr<1>, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: i64, %arg8: i64, %arg9: i64, %arg10: i64, %arg11: i48, %arg12: vector<128xi48>) attributes {gpu.kernel, gpu.known_block_size = array<i32: 1, 1, 1>, gpu.known_grid_size = array<i32: 2, 1, 1>, reqd_work_group_size = array<i32: 1, 1, 1>} {
 %0 = llvm.mlir.constant(0 : i32) : i32
      %1 = llvm.mlir.poison : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
      %2 = llvm.insertvalue %arg0, %1[0] : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
      %3 = llvm.insertvalue %arg1, %2[1] : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
      %4 = llvm.insertvalue %arg2, %3[2] : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
      %5 = llvm.insertvalue %arg3, %4[3, 0] : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
      %6 = llvm.insertvalue %arg7, %5[4, 0] : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
      %7 = llvm.insertvalue %arg4, %6[3, 1] : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
 %8 = llvm.insertvalue %arg8, %7[4, 1] : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
      %9 = llvm.insertvalue %arg5, %8[3, 2] : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
 %10 = llvm.insertvalue %arg9, %9[4, 2] : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
      %11 = llvm.insertvalue %arg6, %10[3, 3] : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
 %12 = llvm.insertvalue %arg10, %11[4, 3] : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)>
      %13 = builtin.unrealized_conversion_cast %12 : !llvm.struct<(ptr<1>, ptr<1>, i64, array<4 x i64>, array<4 x i64>)> to memref<2x7x7x1xi48, 1>
      %14 = llvm.call spir_funccc @_Z12get_group_idj(%0) {memory_effects = #llvm.memory_effects<other = none, argMem = none, inaccessibleMem = none, errnoMem = none, targetMem0 = none, targetMem1 = none>, no_unwind, will_return} : (i32) -> i64
      %15 = builtin.unrealized_conversion_cast %14 : i64 to index
      %c0 = arith.constant 0 : index
      %c7 = arith.constant 7 : index
      %c1 = arith.constant 1 : index
      scf.for %arg13 = %c0 to %c7 step %c1 {
        %c0_0 = arith.constant 0 : index
 %c7_1 = arith.constant 7 : index
        %c1_2 = arith.constant 1 : index
        scf.for %arg14 = %c0_0 to %c7_1 step %c1_2 {
          %c0_3 = arith.constant 0 : index
          %c1_4 = arith.constant 1 : index
 %c128 = arith.constant 128 : index
          scf.for %arg15 = %c0_3 to %c1_4 step %c128 {
            %c0_5 = arith.constant 0 : index
 %c8 = arith.constant 8 : index
            %c1_6 = arith.constant 1 : index
            scf.for %arg16 = %c0_5 to %c8 step %c1_6 {
 %c0_7 = arith.constant 0 : index
              %c1_8 = arith.constant 1 : index
              %c1_9 = arith.constant 1 : index
              scf.for %arg17 = %c0_7 to %c1_8 step %c1_9 {
                %c0_10 = arith.constant 0 : index
                %c1_11 = arith.constant 1 : index
 %c1_12 = arith.constant 1 : index
                scf.for %arg18 = %c0_10 to %c1_11 step %c1_12 {
                  %16 = vector.transfer_read %13[%15, %arg13, %arg14, %arg15], %arg11 : memref<2x7x7x1xi48, 1>, vector<128xi48>
 %17 = llvm.add %16, %arg12 : vector<128xi48>
 vector.transfer_write %17, %13[%15, %arg13, %arg14, %arg15] : vector<128xi48>, memref<2x7x7x1xi48, 1>
                }
              }
 }
          }
        }
      }
      llvm.return
    }
 }
}

```



Step to reproduce:
```
mlir-opt test.mlir --gpu-lower-to-xevm-pipeline
```

Crash backtrace:
```
test.mlir:45:25: warning: op has users but no layout assigned for its result
 %16 = vector.transfer_read %13[%15, %arg13, %arg14, %arg15], %arg11 : memref<2x7x7x1xi48, 1>, vector<128xi48>
 ^
test.mlir:45:25: note: see current operation: %16 = vector.transfer_read %13[%15, %arg13, %arg14, %arg15], %arg11 : memref<2x7x7x1xi48, 1>, vector<128xi48>
test.mlir:46:25: warning: op has users but no layout assigned for its result
                  %17 = llvm.add %16, %arg12 : vector<128xi48>
                        ^
test.mlir:46:25: note: see current operation: %17 = llvm.add %16, %arg12 : vector<128xi48>
test.mlir:45:25: warning: op has users but no layout assigned for its result
                  %16 = vector.transfer_read %13[%15, %arg13, %arg14, %arg15], %arg11 : memref<2x7x7x1xi48, 1>, vector<128xi48>
                        ^
test.mlir:45:25: note: see current operation: %16 = vector.transfer_read %13[%15, %arg13, %arg14, %arg15], %arg11 : memref<2x7x7x1xi48, 1>, vector<128xi48>
test.mlir:46:25: warning: op has users but no layout assigned for its result
 %17 = llvm.add %16, %arg12 : vector<128xi48>
 ^
test.mlir:46:25: note: see current operation: %17 = llvm.add %16, %arg12 : vector<128xi48>
test.mlir:45:25: warning: op has users but no layout assigned for its result
                  %16 = vector.transfer_read %13[%15, %arg13, %arg14, %arg15], %arg11 : memref<2x7x7x1xi48, 1>, vector<128xi48>
                        ^
test.mlir:45:25: note: see current operation: %16 = vector.transfer_read %13[%15, %arg13, %arg14, %arg15], %arg11 : memref<2x7x7x1xi48, 1>, vector<128xi48>
test.mlir:46:25: warning: op has users but no layout assigned for its result
 %17 = llvm.add %16, %arg12 : vector<128xi48>
 ^
test.mlir:46:25: note: see current operation: %17 = llvm.add %16, %arg12 : vector<128xi48>
[xegpu-optimize-peephole]: XeGPUPeepHoleOptimizerPass only supports PVC, BMG targets.
test.mlir:45:25: warning: op has users but no layout assigned for its result
                  %16 = vector.transfer_read %13[%15, %arg13, %arg14, %arg15], %arg11 : memref<2x7x7x1xi48, 1>, vector<128xi48>
                        ^
test.mlir:45:25: note: see current operation: %16 = vector.transfer_read %13[%15, %arg13, %arg14, %arg15], %arg11 : memref<2x7x7x1xi48, 1>, vector<128xi48>
test.mlir:46:25: warning: op has users but no layout assigned for its result
 %17 = llvm.add %16, %arg12 : vector<128xi48>
 ^
test.mlir:46:25: note: see current operation: %17 = llvm.add %16, %arg12 : vector<128xi48>
mlir-opt: /home/llvm-project/llvm-project-latest/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp:1428: virtual llvm::MachineInstrBuilder llvm::MachineIRBuilder::buildInstr(unsigned int, llvm::ArrayRef<llvm::DstOp>, llvm::ArrayRef<llvm::SrcOp>, std::optional<unsigned int>): Assertion `(TypeSize::ScalarTy)DstOps.size() * DstOps[0].getLLTTy(*getMRI()).getSizeInBits() == SrcOps[0].getLLTTy(*getMRI()).getSizeInBits() && "input operands do not cover output register"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.      Program arguments: mlir-opt test.mlir --gpu-lower-to-xevm-pipeline
1.      Running pass 'Function Pass Manager' on module 'LLVMDialectModule'.
2.      Running pass 'Legalizer' on function '@func_981975_kernel'
 #0 0x000055ba6aae5139 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x1fdb139)
 #1 0x000055ba6aae193c llvm::sys::RunSignalHandlers() (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x1fd793c)
 #2 0x000055ba6aae1aa6 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f1966bcd520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007f1966c219bc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969bc)
 #5 0x00007f1966bcd476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007f1966bb37f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007f1966bb371b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007f1966bc4e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000055ba6c6b5e9a llvm::MachineIRBuilder::buildInstr(unsigned int, llvm::ArrayRef<llvm::DstOp>, llvm::ArrayRef<llvm::SrcOp>, std::optional<unsigned int>) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x3babe9a)
#10 0x000055ba6c6b0ec3 llvm::MachineIRBuilder::buildUnmerge(llvm::ArrayRef<llvm::Register>, llvm::SrcOp const&) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x3ba6ec3)
#11 0x000055ba6c2f6d46 legalizeSpvExtractElt(llvm::LegalizerHelper&, llvm::MachineInstr&, llvm::SPIRVGlobalRegistry*) SPIRVLegalizerInfo.cpp:0:0
#12 0x000055ba6c696bc8 llvm::LegalizerHelper::legalizeInstrStep(llvm::MachineInstr&, llvm::LostDebugLocObserver&) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x3b8cbc8)
#13 0x000055ba6c63867f llvm::legalizeMachineFunction(llvm::MachineFunction&, llvm::LegalizerInfo const&, llvm::ArrayRef<llvm::GISelChangeObserver*>, llvm::LostDebugLocObserver&, llvm::MachineIRBuilder&, llvm::LibcallLoweringInfo const*, llvm::GISelValueTracking*) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x3b2e67f)
#14 0x000055ba6c63a3f7 runLegalizerOnMachineFunction(llvm::MachineFunction&, llvm::function_ref<llvm::GISelCSEInfo* ()>, llvm::function_ref<llvm::GISelValueTracking* ()>, llvm::LibcallLoweringInfo const*) Legalizer.cpp:0:0
#15 0x000055ba6c63af4c llvm::LegalizerLegacy::runOnMachineFunction(llvm::MachineFunction&) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x3b30f4c)
#16 0x000055ba6ccfd35c llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#17 0x000055ba72b38506 llvm::FPPassManager::runOnFunction(llvm::Function&) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0xa02e506)
#18 0x000055ba72b38ac9 llvm::FPPassManager::runOnModule(llvm::Module&) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0xa02eac9)
#19 0x000055ba72b394c1 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) LegacyPassManager.cpp:0:0
#20 0x000055ba72b39d0b llvm::legacy::PassManagerImpl::run(llvm::Module&) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0xa02fd0b)
#21 0x000055ba6c45e0c5 runCodeGenPipelineLegacy(llvm::TargetMachine&, llvm::Module&, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*, llvm::CodeGenFileType, bool, bool) RunCodeGen.cpp:0:0
#22 0x000055ba6c45e2ed llvm::runCodeGenPipeline(llvm::TargetMachine&, llvm::Module&, llvm::raw_pwrite_stream&, llvm::raw_pwrite_stream*, llvm::CodeGenFileType, bool, bool, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x39542ed)
#23 0x000055ba6c1b1625 SPIRVTranslate (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x36a7625)
#24 0x000055ba6c1b217e SPIRVTranslateModule (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x36a817e)
#25 0x000055ba6c1aefa5 (anonymous namespace)::SPIRVSerializer::moduleToObject(llvm::Module&) Target.cpp:0:0
#26 0x000055ba6c1b0099 (anonymous namespace)::SPIRVSerializer::run() Target.cpp:0:0
#27 0x000055ba6c1b09a2 (anonymous namespace)::XeVMTargetAttrImpl::serializeToObject(mlir::Attribute, mlir::Operation*, mlir::gpu::TargetOptions const&) const (.constprop.0) Target.cpp:0:0
#28 0x000055ba6c1b0c9b mlir::gpu::detail::TargetAttrInterfaceInterfaceTraits::FallbackModel<(anonymous namespace)::XeVMTargetAttrImpl>::serializeToObject(mlir::gpu::detail::TargetAttrInterfaceInterfaceTraits::Concept const*, mlir::Attribute, mlir::Operation*, mlir::gpu::TargetOptions const&) Target.cpp:0:0
#29 0x000055ba72398aad mlir::gpu::TargetAttrInterface::serializeToObject(mlir::Operation*, mlir::gpu::TargetOptions const&) const (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x988eaad)
#30 0x000055ba6f1bf00f mlir::gpu::transformGpuModulesToBinaries(mlir::Operation*, mlir::gpu::OffloadingLLVMTranslationAttrInterface, mlir::gpu::TargetOptions const&) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0x66b500f)
#31 0x000055ba6f1c0579 (anonymous namespace)::GpuModuleToBinaryPass::runOnOperation() ModuleToBinary.cpp:0:0
#32 0x000055ba732ee3b9 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0xa7e43b9)
#33 0x000055ba732ee694 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0xa7e4694)
#34 0x000055ba732f02e2 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0xa7e62e2)
#35 0x000055ba732f12b9 mlir::PassManager::run(mlir::Operation*) (/home/llvm-project/llvm-project-latest/build/bin/mlir-opt+0xa7e72b9)
#36 0x000055ba6abaf696 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#37 0x000055ba6abb0c4e processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#38 0x000055ba6abb0e91 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, 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::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#39 0x000055ba736644cd mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<ll<truncated>Please see the issue for the entire body.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to