[clang] a944191 - [CIR] Use allocation size for argument dereferenceable attribute (#235138)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 3 15:48:44 PST 2026
Author: Andy Kaylor
Date: 2026-11-03T15:48:39-08:00
New Revision: a944191f2e3d1f2878feec7b96d70e29960eccec
URL: https://github.com/llvm/llvm-project/commit/a944191f2e3d1f2878feec7b96d70e29960eccec
DIFF: https://github.com/llvm/llvm-project/commit/a944191f2e3d1f2878feec7b96d70e29960eccec.diff
LOG: [CIR] Use allocation size for argument dereferenceable attribute (#235138)
This updates the CIR rewrite context to use an argument's allocation
size rather than type size when setting the dereferenceable attribute
for indirect arguments. There are no cases for x86 where these sizes
will be different, so I don't have a source-to-ir test for this. It will
be needed for AArch64 lowering, and it works in the new form for other
targets, so I'm making the change now.
Assisted-by: Cursor / various models
Added:
Modified:
clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp
clang/test/CIR/Transforms/abi-lowering/byval-sret-arg-attr-lowering.cir
Removed:
################################################################################
diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp
index 8498ef6027cad..d8b31f028a731 100644
--- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp
+++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/CIRABIRewriteContext.cpp
@@ -316,7 +316,7 @@ mlir::ArrayAttr updateArgAttrs(mlir::MLIRContext *ctx, mlir::ModuleOp module,
llvm::DeadOnReturnInfo().toIntValue())));
attrs.set(mlir::LLVM::LLVMDialect::getDereferenceableAttrName(),
builder.getI64IntegerAttr(
- dl.getTypeSize(pointeeTy).getFixedValue()));
+ dl.getTypeAllocSize(pointeeTy).getFixedValue()));
}
newArgAttrs.push_back(attrs.getDictionary(ctx));
} else {
diff --git a/clang/test/CIR/Transforms/abi-lowering/byval-sret-arg-attr-lowering.cir b/clang/test/CIR/Transforms/abi-lowering/byval-sret-arg-attr-lowering.cir
index 85c0660db0333..8c51f07229496 100644
--- a/clang/test/CIR/Transforms/abi-lowering/byval-sret-arg-attr-lowering.cir
+++ b/clang/test/CIR/Transforms/abi-lowering/byval-sret-arg-attr-lowering.cir
@@ -5,6 +5,7 @@
// RUN: | cir-translate -mlir-to-llvmir --allow-unregistered-dialect \
// RUN: | FileCheck %s --check-prefix=LLVM
+!s32i = !cir.int<s, 32>
!s64i = !cir.int<s, 64>
!rec_Big = !cir.struct<"Big" {data !s64i, data !s64i, data !s64i}>
@@ -23,6 +24,11 @@
args = [ { kind = "indirect", indirect_align = 8, byval = false } ]
}
+#non_byval_vec_arg = {
+ return = { kind = "direct" },
+ args = [ { kind = "indirect", indirect_align = 16, byval = false } ]
+}
+
#passthrough = {
return = { kind = "direct" },
args = [ ]
@@ -64,6 +70,15 @@ module attributes {
// CHECK: cir.func{{.*}} @takes_non_byval(%{{.*}}: !cir.ptr<!rec_Big> {{{.*}}llvm.dead_on_return = -1 : i64, llvm.dereferenceable = 24 : i64, llvm.nofreeobj, llvm.noundef{{.*}}})
// LLVM: define void @takes_non_byval(ptr nofreeobj noundef align 8 dead_on_return dereferenceable(24) %{{.+}})
+ // A three-element vector holds 12 bytes, and its allocation is padded to 16.
+ cir.func @takes_vec3_non_byval(%arg0: !cir.vector<3 x !s32i>)
+ attributes { test_classify = #non_byval_vec_arg } {
+ cir.return
+ }
+
+ // CHECK: cir.func{{.*}} @takes_vec3_non_byval(%{{.*}}: !cir.ptr<!cir.vector<3 x !s32i>> {{{.*}}llvm.dereferenceable = 16 : i64{{.*}}})
+ // LLVM: define void @takes_vec3_non_byval(ptr nofreeobj noundef align 16 dead_on_return dereferenceable(16) %{{.+}})
+
// The call site's byval operand attribute is converted too.
cir.func @caller(%s: !rec_Big) attributes { test_classify = #passthrough } {
cir.call @takes_big(%s) : (!rec_Big) -> ()
More information about the cfe-commits
mailing list