[mlir][llvm] Add memset support for mem2reg/sroa
authorThéo Degioanni <theo.degioanni@nextsilicon.com>
Wed, 14 Jun 2023 08:43:10 +0000 (08:43 +0000)
committerChristian Ulmann <christian.ulmann@nextsilicon.com>
Wed, 14 Jun 2023 09:17:08 +0000 (09:17 +0000)
commit8404b23acd70b8db1411b98a04b4ea62eaeb48dd
treeea2355f5ab7efd84b9554855df475f130576e661
parent1e41a29d739a0a1e7bcab57ccdc455343978b6ca
[mlir][llvm] Add memset support for mem2reg/sroa

This revision introduces support for memset intrinsics in SROA and
mem2reg for the LLVM dialect. This is achieved for SROA by breaking
memsets of aggregates into multiple memsets of scalars, and for mem2reg
by promoting memsets of single integer slots into the value the memset
operation would yield.

The SROA logic supports breaking memsets of static size operating at the
start of a memory slot. The intended most common case is for memsets
covering the entirety of a struct, most often as a way to initialize it
to 0.

The mem2reg logic supports dynamic values and static sizes as input to
promotable memsets. This is achieved by lowering memsets into
`ceil(log_2(n))` LeftShift operations, `ceil(log_2(n))` Or operations
and up to one ZExt operation (for n the byte width of the integer),
computing in registers the integer value the memset would create. Only
byte-aligned integers are supported, more types could easily be added
afterwards.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D152367
mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
mlir/include/mlir/Interfaces/MemorySlotInterfaces.td
mlir/lib/Dialect/LLVMIR/IR/LLVMMemorySlot.cpp
mlir/lib/Dialect/MemRef/IR/MemRefMemorySlot.cpp
mlir/lib/Transforms/Mem2Reg.cpp
mlir/test/Dialect/LLVMIR/mem2reg-intrinsics.mlir [new file with mode: 0644]
mlir/test/Dialect/LLVMIR/sroa-intrinsics.mlir [new file with mode: 0644]