[llvm-branch-commits] [llvm] RuntimeLibcalls: Move sqrt attributes to TableGen (PR #240726)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Nov 9 22:14:20 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
Co-authored-by: Claude Opus 5.5 <noreply@<!-- -->anthropic.com>
---
Full diff: https://github.com/llvm/llvm-project/pull/240726.diff
6 Files Affected:
- (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+11-1)
- (modified) llvm/include/llvm/IR/RuntimeLibcallsImpl.td (+7-2)
- (modified) llvm/lib/IR/RuntimeLibcalls.cpp (-20)
- (modified) llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm64ec.ll (+3-2)
- (modified) llvm/test/Transforms/Util/DeclareRuntimeLibcalls/hexagon.ll (+8-8)
- (modified) llvm/test/Transforms/Util/DeclareRuntimeLibcalls/systemz.ll (+5-5)
``````````diff
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index 98c0f54ac5dbe..4b8d3252acc24 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -302,6 +302,17 @@ 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;
+ let Memory = ErrnoMemWriteOnly;
+ let RetAttrs = [NoFPClassAttr<"fcNegInf | fcNegSubnormal | fcNegNormal">];
+ }
+}
+
+foreach FPTy = [F80, F128, PPCF128] in
+ def SQRT_#FPTy.Suffix : RuntimeLibcall<FPTy.Type, [FPTy.Type]>;
+
foreach FPTy = [F32, F64, F80, F128, PPCF128] in {
def ADD_#FPTy.Suffix : RuntimeLibcall<FPTy.Type, [FPTy.Type, FPTy.Type]>;
def FAST_ADD_#FPTy.Suffix : RuntimeLibcall<FPTy.Type, [FPTy.Type, FPTy.Type]>;
@@ -320,7 +331,6 @@ foreach FPTy = [F32, F64, F80, F128, PPCF128] in {
: RuntimeLibcall<FPTy.Type, [FPTy.Type, FPTy.Type, FPTy.Type]>;
def POWI_#FPTy.Suffix : RuntimeLibcall<FPTy.Type, [FPTy.Type, Int]>;
- def SQRT_#FPTy.Suffix : RuntimeLibcall<FPTy.Type, [FPTy.Type]>;
def FAST_SQRT_#FPTy.Suffix : RuntimeLibcall<FPTy.Type, [FPTy.Type]>;
def CBRT_#FPTy.Suffix : RuntimeLibcall<FPTy.Type, [FPTy.Type]>;
diff --git a/llvm/include/llvm/IR/RuntimeLibcallsImpl.td b/llvm/include/llvm/IR/RuntimeLibcallsImpl.td
index b1910d92c10b1..3ecfbc989fb27 100644
--- a/llvm/include/llvm/IR/RuntimeLibcallsImpl.td
+++ b/llvm/include/llvm/IR/RuntimeLibcallsImpl.td
@@ -159,6 +159,7 @@ class MemoryEffects<ModRefInfo mr = ModRef> {
def UnknownMemory : MemoryEffects;
def ArgMemWriteOnly : MemoryEffects<NoModRef> { let ArgMem = Mod; }
+def ErrnoMemWriteOnly : MemoryEffects<NoModRef> { let ErrnoMem = Mod; }
class ValueAttr<list<AttrProperty> props, string expr>
: Attr<"", IntersectPreserve, props> {
@@ -176,6 +177,10 @@ class AllocFamilyAttr<string family>
: ValueAttr<[FnAttr],
"Attribute::get(C, \"alloc-family\", \"" # family # "\")">;
+class NoFPClassAttr<string mask>
+ : ValueAttr<[ParamAttr, RetAttr],
+ "Attribute::getWithNoFPClass(C, " # mask # ")">;
+
def CapturesNone
: ValueAttr<[ParamAttr],
"Attribute::getWithCaptureInfo(C, CaptureInfo::none())">;
@@ -218,7 +223,7 @@ class MaskedRuntimeLibcall<RuntimeLibcall unmasked, FuncArgType mask>
}
// TODO: NoCallback probably unsafe in general
-defvar VectorMathFnAttrs = [NoCallback, NoFree, NoSync, NoUnwind, WillReturn];
+defvar MathFnAttrs = [NoCallback, NoFree, NoSync, NoUnwind, WillReturn];
multiclass VectorMathLibcall<string suffix, FuncArgType RetType = NoneType,
list<FuncArgType> ArgTypes = [],
@@ -227,7 +232,7 @@ multiclass VectorMathLibcall<string suffix, FuncArgType RetType = NoneType,
list<FuncArgType> paramPointeeTypes = []> {
defvar VT = !cast<VectorFuncArgType>(suffix);
def _#suffix : RuntimeLibcall<RetType, ArgTypes> {
- let FnAttrs = VectorMathFnAttrs;
+ let FnAttrs = MathFnAttrs;
let Memory = memory;
let ParamAttrs = paramAttrs;
let ParamPointeeTypes = paramPointeeTypes;
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index ea1a696a84786..300f20b809c05 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -611,26 +611,6 @@ RuntimeLibcallsInfo::getFunctionTy(LLVMContext &Ctx, const Triple &TT,
FuncAttrBuilder.addMemoryAttr(MemoryEffects::none());
return {FuncTy, Attrs.addFnAttributes(Ctx, FuncAttrBuilder)};
}
- case RTLIB::impl_sqrtf:
- case RTLIB::impl_sqrt: {
- AttrBuilder FuncAttrBuilder(Ctx);
-
- for (Attribute::AttrKind Attr : CommonFnAttrs)
- FuncAttrBuilder.addAttribute(Attr);
- FuncAttrBuilder.addMemoryAttr(MemoryEffects::errnoMemOnly(ModRefInfo::Mod));
-
- AttributeList Attrs;
- Attrs = Attrs.addFnAttributes(Ctx, FuncAttrBuilder);
-
- Type *ScalarTy = LibcallImpl == RTLIB::impl_sqrtf ? Type::getFloatTy(Ctx)
- : Type::getDoubleTy(Ctx);
- FunctionType *FuncTy = FunctionType::get(ScalarTy, {ScalarTy}, false);
-
- Attrs = Attrs.addRetAttribute(
- Ctx, Attribute::getWithNoFPClass(Ctx, fcNegInf | fcNegSubnormal |
- fcNegNormal));
- return {FuncTy, Attrs};
- }
default:
break;
}
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm64ec.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm64ec.ll
index f17f447245439..23d5ca31a5809 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm64ec.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/arm64ec.ll
@@ -505,8 +505,8 @@
; CHECK-NEXT: declare float @"#sinf"(float)
; CHECK-NEXT: declare double @"#sinh"(double)
; CHECK-NEXT: declare float @"#sinhf"(float)
-; CHECK-NEXT: declare double @"#sqrt"(double)
-; CHECK-NEXT: declare float @"#sqrtf"(float)
+; CHECK-NEXT: declare nofpclass(ninf nsub nnorm) double @"#sqrt"(double) [[SQRT_ATTRS:#[0-9]+]]
+; CHECK-NEXT: declare nofpclass(ninf nsub nnorm) float @"#sqrtf"(float) [[SQRT_ATTRS]]
; CHECK-NEXT: declare double @"#tan"(double)
; CHECK-NEXT: declare float @"#tanf"(float)
; CHECK-NEXT: declare double @"#tanh"(double)
@@ -518,3 +518,4 @@
; CHECK-NEXT: attributes [[CALLOC_ATTRS]] = { nofree nounwind willreturn allockind("alloc") allocsize(0,1) "alloc-family"="malloc" }
; CHECK-NEXT: attributes [[FREE_ATTRS]] = { nounwind willreturn allockind("free") "alloc-family"="malloc" }
; CHECK-NEXT: attributes [[MALLOC_ATTRS]] = { nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) "alloc-family"="malloc" }
+; CHECK-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/hexagon.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/hexagon.ll
index 6d6865f26cdab..73ea2866069d1 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/hexagon.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/hexagon.ll
@@ -174,7 +174,7 @@
; CHECK-NEXT: declare i64 @__hexagon_moddi3(i64, i64)
; CHECK-NEXT: declare i32 @__hexagon_modsi3(i32, i32)
; CHECK-NEXT: declare double @__hexagon_muldf3(double, double)
-; CHECK-NEXT: declare float @__hexagon_sqrtf(float)
+; CHECK-NEXT: declare nofpclass(ninf nsub nnorm) float @__hexagon_sqrtf(float) [[SQRT_ATTRS:#[0-9]+]]
; CHECK-NEXT: declare double @__hexagon_subdf3(double, double)
; CHECK-NEXT: declare i64 @__hexagon_udivdi3(i64, i64)
; CHECK-NEXT: declare i32 @__hexagon_udivsi3(i32, i32)
@@ -429,8 +429,8 @@
; CHECK-NEXT: declare float @sinf(float)
; CHECK-NEXT: declare double @sinh(double)
; CHECK-NEXT: declare float @sinhf(float)
-; CHECK-NEXT: declare nofpclass(ninf nsub nnorm) double @sqrt(double) [[SQRT_ATTRS:#[0-9]+]]
-; CHECK-NEXT: declare nofpclass(ninf nsub nnorm) float @sqrtf(float) [[SQRT_ATTRS:#[0-9]+]]
+; CHECK-NEXT: declare nofpclass(ninf nsub nnorm) double @sqrt(double) [[SQRT_ATTRS]]
+; CHECK-NEXT: declare nofpclass(ninf nsub nnorm) float @sqrtf(float) [[SQRT_ATTRS]]
; CHECK-NEXT: declare double @tan(double)
; CHECK-NEXT: declare float @tanf(float)
; CHECK-NEXT: declare double @tanh(double)
@@ -439,10 +439,10 @@
; CHECK-NEXT: declare float @tgammaf(float)
; CHECK-NEXT: declare double @trunc(double)
; CHECK-NEXT: declare float @truncf(float)
+; CHECK-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; CHECK-NEXT: attributes [[CALLOC_ATTRS]] = { nofree nounwind willreturn allockind("alloc") allocsize(0,1) "alloc-family"="malloc" }
; CHECK-NEXT: attributes [[FREE_ATTRS]] = { nounwind willreturn allockind("free") "alloc-family"="malloc" }
; CHECK-NEXT: attributes [[MALLOC_ATTRS]] = { nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) "alloc-family"="malloc" }
-; CHECK-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; LINUX: @__safestack_unsafe_stack_ptr = external thread_local(initialexec) global ptr
; LINUX-NEXT: @__stack_chk_guard = external global ptr
@@ -613,7 +613,7 @@
; LINUX-NEXT: declare i64 @__hexagon_moddi3(i64, i64)
; LINUX-NEXT: declare i32 @__hexagon_modsi3(i32, i32)
; LINUX-NEXT: declare double @__hexagon_muldf3(double, double)
-; LINUX-NEXT: declare float @__hexagon_sqrtf(float)
+; LINUX-NEXT: declare nofpclass(ninf nsub nnorm) float @__hexagon_sqrtf(float) [[SQRT_ATTRS:#[0-9]+]]
; LINUX-NEXT: declare double @__hexagon_subdf3(double, double)
; LINUX-NEXT: declare i64 @__hexagon_udivdi3(i64, i64)
; LINUX-NEXT: declare i32 @__hexagon_udivsi3(i32, i32)
@@ -870,8 +870,8 @@
; LINUX-NEXT: declare float @sinf(float)
; LINUX-NEXT: declare double @sinh(double)
; LINUX-NEXT: declare float @sinhf(float)
-; LINUX-NEXT: declare nofpclass(ninf nsub nnorm) double @sqrt(double) [[SQRT_ATTRS:#[0-9]+]]
-; LINUX-NEXT: declare nofpclass(ninf nsub nnorm) float @sqrtf(float) [[SQRT_ATTRS:#[0-9]+]]
+; LINUX-NEXT: declare nofpclass(ninf nsub nnorm) double @sqrt(double) [[SQRT_ATTRS]]
+; LINUX-NEXT: declare nofpclass(ninf nsub nnorm) float @sqrtf(float) [[SQRT_ATTRS]]
; LINUX-NEXT: declare double @tan(double)
; LINUX-NEXT: declare float @tanf(float)
; LINUX-NEXT: declare double @tanh(double)
@@ -880,7 +880,7 @@
; LINUX-NEXT: declare float @tgammaf(float)
; LINUX-NEXT: declare double @trunc(double)
; LINUX-NEXT: declare float @truncf(float)
+; LINUX-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; LINUX-NEXT: attributes [[CALLOC_ATTRS]] = { nofree nounwind willreturn allockind("alloc") allocsize(0,1) "alloc-family"="malloc" }
; LINUX-NEXT: attributes [[FREE_ATTRS]] = { nounwind willreturn allockind("free") "alloc-family"="malloc" }
; LINUX-NEXT: attributes [[MALLOC_ATTRS]] = { nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) "alloc-family"="malloc" }
-; LINUX-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
diff --git a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/systemz.ll b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/systemz.ll
index 161de6d44ffa7..b1bade94eb998 100644
--- a/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/systemz.ll
+++ b/llvm/test/Transforms/Util/DeclareRuntimeLibcalls/systemz.ll
@@ -517,7 +517,7 @@
; ZOS-NEXT: declare i64 @"@@FRND at B"(float)
; ZOS-NEXT: declare float @"@@FSIN at B"(float)
; ZOS-NEXT: declare float @"@@FSNH at B"(float)
-; ZOS-NEXT: declare float @"@@FSQT at B"(float)
+; ZOS-NEXT: declare nofpclass(ninf nsub nnorm) float @"@@FSQT at B"(float) [[SQRT_ATTRS:#[0-9]+]]
; ZOS-NEXT: declare float @"@@FTAN at B"(float)
; ZOS-NEXT: declare float @"@@FTNH at B"(float)
; ZOS-NEXT: declare float @"@@FTRC at B"(float)
@@ -589,7 +589,7 @@
; ZOS-NEXT: declare double @"@@WLOG at B"(double)
; ZOS-NEXT: declare double @"@@WPOW at B"(double, double)
; ZOS-NEXT: declare double @"@@WSNH at B"(double)
-; ZOS-NEXT: declare double @"@@WSQT at B"(double)
+; ZOS-NEXT: declare nofpclass(ninf nsub nnorm) double @"@@WSQT at B"(double) [[SQRT_ATTRS]]
; ZOS-NEXT: declare signext i32 @_Unwind_RaiseException(ptr)
; ZOS-NEXT: declare void @_Unwind_Resume(ptr)
; ZOS-NEXT: declare double @__adddf3(double, double)
@@ -1045,8 +1045,8 @@
; ZOS-NEXT: declare float @sinhf(float)
; ZOS-NEXT: declare fp128 @sinhl(fp128)
; ZOS-NEXT: declare fp128 @sinl(fp128)
-; ZOS-NEXT: declare nofpclass(ninf nsub nnorm) double @sqrt(double) [[SQRT_ATTRS:#[0-9]+]]
-; ZOS-NEXT: declare nofpclass(ninf nsub nnorm) float @sqrtf(float) [[SQRT_ATTRS:#[0-9]+]]
+; ZOS-NEXT: declare nofpclass(ninf nsub nnorm) double @sqrt(double) [[SQRT_ATTRS]]
+; ZOS-NEXT: declare nofpclass(ninf nsub nnorm) float @sqrtf(float) [[SQRT_ATTRS]]
; ZOS-NEXT: declare fp128 @sqrtl(fp128)
; ZOS-NEXT: declare double @tan(double)
; ZOS-NEXT: declare float @tanf(float)
@@ -1060,7 +1060,7 @@
; ZOS-NEXT: declare double @trunc(double)
; ZOS-NEXT: declare float @truncf(float)
; ZOS-NEXT: declare fp128 @truncl(fp128)
+; ZOS-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
; ZOS-NEXT: attributes [[CALLOC_ATTRS]] = { nofree nounwind willreturn allockind("alloc") allocsize(0,1) "alloc-family"="malloc" }
; ZOS-NEXT: attributes [[FREE_ATTRS]] = { nounwind willreturn allockind("free") "alloc-family"="malloc" }
; ZOS-NEXT: attributes [[MALLOC_ATTRS]] = { nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) "alloc-family"="malloc" }
-; ZOS-NEXT: attributes [[SQRT_ATTRS]] = { nocallback nofree nosync nounwind willreturn memory(errnomem: write) }
``````````
</details>
https://github.com/llvm/llvm-project/pull/240726
More information about the llvm-branch-commits
mailing list