[all-commits] [llvm/llvm-project] eafca2: [mlir][MemRef] Add required address space cast whe...

zero9178 via All-commits all-commits at lists.llvm.org
Mon Feb 6 03:09:53 PST 2023

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: eafca2303769800f5da4bc4cbf9e842c6a8cde9f
  Author: Markus Böck <markus.boeck02 at gmail.com>
  Date:   2023-02-06 (Mon, 06 Feb 2023)

  Changed paths:
    M mlir/lib/Conversion/MemRefToLLVM/AllocLikeConversion.cpp
    M mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir

  Log Message:
  [mlir][MemRef] Add required address space cast when lowering alloc to LLVM

alloc uses either `malloc` or a plugable allocation function for allocating the required memory. Both of these functions always return a `llvm.ptr<i8>`, aka a pointer in the default address space. When allocating for a memref in a different memory space however, no address space cast is created, leading to invalid LLVM IR being generated.

This is currently not caught by the verifier since the pointer to the memory is always bitcast which currently lacks a verifier disallowing address space casts. Translating to actual LLVM IR would cause the verifier to go off, since bitcast cannot translate from one address space to another: https://godbolt.org/z/3a1z97rc9

This patch fixes that issue by generating an address space cast if the address space of the allocation function does not match the address space of the resulting memref.

Not sure whether this is actually a real life problem. I found this issue while converting the pass to using opaque pointers which gets rid of all the bitcasts and hence caused type errors without the address space cast.

Differential Revision: https://reviews.llvm.org/D143341

More information about the All-commits mailing list