[mlir][GPU] add required address space cast when lowering to LLVM
authorMarkus Böck <markus.boeck02@gmail.com>
Sun, 12 Feb 2023 22:52:16 +0000 (23:52 +0100)
committerMarkus Böck <markus.boeck02@gmail.com>
Mon, 13 Feb 2023 21:24:20 +0000 (22:24 +0100)
commit0aaf2e3bc057aa1d784455f8f4da66bc464733d6
tree98a0278d25f66b224a38359140f1eaa947636c87
parent9d0b596aada6fb2166dd4f6f58e359fbac483154
[mlir][GPU] add required address space cast when lowering to LLVM

The runtime functions `memset` and `memcpy` are lowered are declared with pointers to the default address space (0) while their ops however are compatible with memrefs taking any address space.
Such cases do not cause any issues with MLIRs LLVM Dialect due to `bitcast`s verifier being too lenient at the moment, but actual LLVM IR does not allow casting between address spaces using `bitcast`: https://godbolt.org/z/3a1z97rc9

This patch fixes the issue by inserting an address space cast before the bitcast, to first cast the pointer into the correct address space before doing the bitcast.

Differential Revision: https://reviews.llvm.org/D143866
mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
mlir/test/Conversion/GPUCommon/lower-memcpy-to-gpu-runtime-calls.mlir
mlir/test/Conversion/GPUCommon/lower-memset-to-gpu-runtime-calls.mlir