[llvm-branch-commits] [llvm] RuntimeLibcalls: Annotate divrem libcall remainder out arguments (PR #240731)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Nov 9 22:54:22 PST 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/240731
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
>From ac5e950e977f11ada74821faf419b33ab9dd32bd Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Mon, 9 Nov 2026 22:47:44 -0800
Subject: [PATCH] RuntimeLibcalls: Annotate divrem libcall remainder out
arguments
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
---
llvm/include/llvm/IR/RuntimeLibcalls.td | 21 ++++++++++++++-----
.../Util/DeclareRuntimeLibcalls/divmod.ll | 5 +++--
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 7922f88ec6e7a9..740958cb8b255e 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -249,6 +249,8 @@ foreach IntTy = [TypeSuffix<"I8", UInt8>, TypeSuffix<"I16", UInt16>,
def UREM_#IntTy.Suffix : RuntimeLibcall<IntTy.Type, [IntTy.Type, IntTy.Type]>;
}
+defvar OutPtrAttrs = [NoAlias, WriteOnly, NonNull];
+
foreach IntTy = [TypeSuffix<"I32", Int32>, TypeSuffix<"I64", Int64>,
TypeSuffix<"I128", Int128>] in {
def MULO_#IntTy.Suffix
@@ -259,14 +261,24 @@ foreach IntTy = [TypeSuffix<"I8", Int8>, TypeSuffix<"I16", Int16>,
TypeSuffix<"I32", Int32>, TypeSuffix<"I64", Int64>,
TypeSuffix<"I128", Int128>] in {
def SDIVREM_#IntTy.Suffix
- : RuntimeLibcall<IntTy.Type, [IntTy.Type, IntTy.Type, Ptr]>;
+ : RuntimeLibcall<IntTy.Type, [IntTy.Type, IntTy.Type, Ptr]> {
+ let FnAttrs = MathFnAttrs;
+ let Memory = ArgMemWriteOnly;
+ let ParamAttrs = [[], [], OutPtrAttrs];
+ let ParamPointeeTypes = [NoneType, NoneType, IntTy.Type];
+ }
}
foreach IntTy = [TypeSuffix<"I8", UInt8>, TypeSuffix<"I16", UInt16>,
TypeSuffix<"I32", UInt32>, TypeSuffix<"I64", UInt64>,
TypeSuffix<"I128", UInt128>] in {
def UDIVREM_#IntTy.Suffix
- : RuntimeLibcall<IntTy.Type, [IntTy.Type, IntTy.Type, Ptr]>;
+ : RuntimeLibcall<IntTy.Type, [IntTy.Type, IntTy.Type, Ptr]> {
+ let FnAttrs = MathFnAttrs;
+ let Memory = ArgMemWriteOnly;
+ let ParamAttrs = [[], [], OutPtrAttrs];
+ let ParamPointeeTypes = [NoneType, NoneType, IntTy.Type];
+ }
}
foreach IntTy = [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64] in {
@@ -281,8 +293,9 @@ class DivRemPairImpl<RuntimeLibcall P, string Name = NAME>
defvar IntTy = P.ReturnType;
let ReturnType = !cast<FuncArgType>(!cast<string>(IntTy) # "Pair");
let ArgumentTypes = [IntTy, IntTy];
- let FnAttrs = MathFnAttrs;
let Memory = NoMemory;
+ let ParamAttrs = [];
+ let ParamPointeeTypes = [];
}
foreach IntTy = [TypeSuffix<"I32", Int32>, TypeSuffix<"I64", Int64>] in {
@@ -302,8 +315,6 @@ def F80 : TypeSuffix<"F80", X86FP80>;
def F128 : TypeSuffix<"F128", FP128>;
def PPCF128 : TypeSuffix<"PPCF128", PPCFP128>;
-defvar OutPtrAttrs = [NoAlias, WriteOnly, NonNull];
-
foreach FPTy = [F32, F64] in {
def SQRT_#FPTy.Suffix : RuntimeLibcall<FPTy.Type, [FPTy.Type]> {
let FnAttrs = MathFnAttrs;
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/divmod.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/divmod.ll
index 38cd3b1fb77abb..08012cf5dd1c97 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/divmod.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/divmod.ll
@@ -17,9 +17,10 @@
; WINDOWS: declare arm_aapcscc inreg { i64, i64 } @__rt_udiv64(i64, i64) #0
; WINDOWS: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
-; DARWIN: declare i32 @__divmodsi4(i32, i32, ptr)
-; DARWIN: declare i32 @__udivmodsi4(i32, i32, ptr)
+; DARWIN: declare i32 @__divmodsi4(i32, i32, ptr noalias nonnull writeonly align 4 dereferenceable(4)) [[DIVMOD_ATTRS:#[0-9]+]]
+; DARWIN: declare i32 @__udivmodsi4(i32, i32, ptr noalias nonnull writeonly align 4 dereferenceable(4)) [[DIVMOD_ATTRS]]
; DARWIN-NOT: inreg { i32, i32 } @__divmodsi4
+; DARWIN: attributes [[DIVMOD_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(argmem: write) }
define void @f() {
ret void
More information about the llvm-branch-commits
mailing list