[llvm-branch-commits] [llvm] 750a60b - RuntimeLibcalls: Annotate divrem libcall remainder out arguments (#240731)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 11 01:52:02 PST 2026


Author: Matt Arsenault
Date: 2026-11-11T03:40:44Z
New Revision: 750a60bc9608be22a0a671ad3f578f4020cd76d4

URL: https://github.com/llvm/llvm-project/commit/750a60bc9608be22a0a671ad3f578f4020cd76d4
DIFF: https://github.com/llvm/llvm-project/commit/750a60bc9608be22a0a671ad3f578f4020cd76d4.diff

LOG: RuntimeLibcalls: Annotate divrem libcall remainder out arguments (#240731)

Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>

Added: 
    

Modified: 
    llvm/include/llvm/IR/RuntimeLibcalls.td
    llvm/test/Transforms/Util/DeclareRuntimeLibcalls/divmod.ll

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index c4a5e154715cb..0123afd784cfa 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 38cd3b1fb77ab..08012cf5dd1c9 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