[Mlir-commits] [mlir] 432745f - [MLIR][LLVMIR] Preserve byval alignment in memcpy after inlining (#185433)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Mar 9 23:55:49 PDT 2026
Author: Berke Ates
Date: 2026-03-10T07:55:44+01:00
New Revision: 432745f24d06e46e24cfdaeeed2eb2274e2d4cc9
URL: https://github.com/llvm/llvm-project/commit/432745f24d06e46e24cfdaeeed2eb2274e2d4cc9
DIFF: https://github.com/llvm/llvm-project/commit/432745f24d06e46e24cfdaeeed2eb2274e2d4cc9.diff
LOG: [MLIR][LLVMIR] Preserve byval alignment in memcpy after inlining (#185433)
This PR adds alignment attributes to the generated memcpy intrinsics
after inlining functions with byval arguments.
Added:
Modified:
mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
mlir/test/Dialect/LLVMIR/inlining.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp b/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
index b61138ad4678b..680fafcc099f2 100644
--- a/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/LLVMIR/Transforms/InlinerInterfaceImpl.cpp
@@ -623,8 +623,18 @@ static Value handleByValArgumentInit(OpBuilder &builder, Location loc,
Value copySize =
LLVM::ConstantOp::create(builder, loc, builder.getI64Type(),
builder.getI64IntegerAttr(elementTypeSize));
+ // Preserve the alignment of the destination (alloca) in the memcpy's
+ // arg_attrs.
+ NamedAttribute dstAlignAttr =
+ builder.getNamedAttr(LLVM::LLVMDialect::getAlignAttrName(),
+ builder.getI64IntegerAttr(targetAlignment));
+ ArrayAttr argAttrs =
+ builder.getArrayAttr({builder.getDictionaryAttr({dstAlignAttr})});
LLVM::MemcpyOp::create(builder, loc, allocaOp, argument, copySize,
- /*isVolatile=*/false);
+ /*isVolatile=*/false,
+ /*access_groups=*/nullptr, /*alias_scopes=*/nullptr,
+ /*noalias_scopes=*/nullptr, /*tbaa=*/nullptr, argAttrs,
+ /*res_attrs=*/nullptr);
return allocaOp;
}
diff --git a/mlir/test/Dialect/LLVMIR/inlining.mlir b/mlir/test/Dialect/LLVMIR/inlining.mlir
index cc3600af431ea..85cae992f01de 100644
--- a/mlir/test/Dialect/LLVMIR/inlining.mlir
+++ b/mlir/test/Dialect/LLVMIR/inlining.mlir
@@ -570,6 +570,26 @@ llvm.func @test_byval_global() {
// -----
+// Check that alignment information is preserved in the memcpy when inlining
+// byval arguments.
+
+llvm.func @byval_aligned_arg(%ptr : !llvm.ptr { llvm.byval = i32, llvm.align = 16 }) {
+ llvm.return
+}
+
+// CHECK-LABEL: llvm.func @test_byval_memcpy_alignment
+// CHECK-SAME: %[[PTR:[a-zA-Z0-9_]+]]: !llvm.ptr
+llvm.func @test_byval_memcpy_alignment(%ptr : !llvm.ptr) {
+ // Verify the memcpy carries the alignment info from the byval attribute.
+ // CHECK: %[[ALLOCA:.+]] = llvm.alloca
+ // CHECK: "llvm.intr.memcpy"(%[[ALLOCA]], %[[PTR]]
+ // CHECK-SAME: {llvm.align = 16 : i64}
+ llvm.call @byval_aligned_arg(%ptr) : (!llvm.ptr) -> ()
+ llvm.return
+}
+
+// -----
+
// Check that inlining does not hoist byval allocas out of automatic allocation
// scopes, such as parallel forall regions. Each parallel iteration must have
// its own private copy of the byval argument.
More information about the Mlir-commits
mailing list