For https://github.com/llvm/llvm-project/issues/60070.
The issue is caused by memref.store is not registed.
Registe it by add "memref::MemRefDialect" as dependetDialects for GpuToLLVMConsersionPass.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Do you know why we are generating ops from the memref dialect in gpu to llvm conversion in the first place?
It happens in VectorStoreToMemrefStoreLowering::matchAndRewrite https://github.com/llvm/llvm-project/blob/main/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp#L2203 where rewriter.replaceOpWithNewOp<memref::StoreOp> is called.
It is added by populateVectorToLLVMConversionPatterns in GpuToLLVMConversionPass::runOnOperation.
But windows build seems go different pattern and not have the dependency. :( So the windows build behavior is the correct path and gpu to llvm conversion don't need memref dialect?
Both VectorStoreToMemrefStoreLowering and VectorLoadStoreConversion<mlir::vector::StoreOp, mlir::vector::StoreOpAdaptor> are added to legalize vector.store.
On windows, VectorLoadStoreConversion has higher benefit, so it does not crash.
And on linux, VectorStoreToMemrefStoreLowering has higher benefit, and memref.store is not resisted, so it will crash.
If patterns added for vector.store are expected to be selected, memref.store should be registered.
Still not sure why windows and linux has different benefit for VectorStoreToMemrefStoreLowering and VectorLoadStoreConversion<mlir::vector::StoreOp, mlir::vector::StoreOpAdaptor>. Should I create an issue for the difference?
Does one of the patterns actually has a higher benefit value? Or do they have the default value and one just happens to be selected instead of the other? In the latter case, it sounds like there is some non-determinism involved (e.g., something stored in a hashmap) that is exposed by platform differences.
The difference is caused by llvm::array_pod_sort used in
unsigned OperationLegalizer::applyCostModelToPatterns( unsigned generatedOpDepth = computeOpLegalizationDepth( generatedOp, minOpPatternDepth, legalizerPatterns); depth = std::max(depth, generatedOpDepth + 1); }
If change it to std::stable_sort, both windows and linux will select VectorStoreToMemrefStoreLowering and crash.
Create https://reviews.llvm.org/D142110 for the non-determinism between windows and linux.
It happens in VectorStoreToMemrefStoreLowering::matchAndRewrite https://github.com/llvm/llvm-project/blob/main/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp#L2203 where rewriter.replaceOpWithNewOp<memref::StoreOp> is called.
I suppose the same problem is possible with just -convert-vector-to-llvm. This is what happens with uncontrolled addition of patterns :(