[llvm] [KnownFPClass] Fix `KnownFPClass::log` deductions for ppcf128 (PR #223296)

Eric Ross via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 20:45:02 PDT 2026


================
@@ -0,0 +1,147 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal < %s | FileCheck %s
+
+declare ppc_fp128 @llvm.log.ppcf128(ppc_fp128)
+declare ppc_fp128 @llvm.log10.ppcf128(ppc_fp128)
+declare ppc_fp128 @llvm.log2.ppcf128(ppc_fp128)
+declare ppc_fp128 @logl(ppc_fp128) memory(none)
+declare ppc_fp128 @log2l(ppc_fp128) memory(none)
+declare ppc_fp128 @log10l(ppc_fp128) memory(none)
+declare ppc_fp128 @sinpil(ppc_fp128) memory(none)
+declare ppc_fp128 @cospil(ppc_fp128) memory(none)
+declare ppc_fp128 @tanpil(ppc_fp128) memory(none)
+declare ppc_fp128 @lgammal(ppc_fp128) memory(none)
+declare ppc_fp128 @compoundnl(ppc_fp128, i64) memory(none)
+
+; We cannot rule out negative zero or subnormal here. ppc_fp128 can represent the
+; exact value of 1.0 +/- subnormal, and log(1.0 +/- subnormal) may be zero or
+; subnormal.
+define ppc_fp128 @ret_log_ppcf128(ppc_fp128 nofpclass(nan inf zero sub nnorm) %arg) {
+; CHECK-LABEL: define nofpclass(nan inf) ppc_fp128 @ret_log_ppcf128(
+; CHECK-SAME: ppc_fp128 nofpclass(nan inf zero sub nnorm) [[ARG:%.*]]) #[[ATTR2:[0-9]+]] {
+; CHECK-NEXT:    [[CALL:%.*]] = call nofpclass(nan inf) ppc_fp128 @llvm.log.ppcf128(ppc_fp128 nofpclass(nan inf zero sub nnorm) [[ARG]]) #[[ATTR4:[0-9]+]]
+; CHECK-NEXT:    ret ppc_fp128 [[CALL]]
+;
+  %call = call ppc_fp128 @llvm.log.ppcf128(ppc_fp128 %arg)
+  ret ppc_fp128 %call
+}
+
+; |log2(x)| > |log(x)|. log2(1.0 + x) can be approximated by x * log2(e) or
+; x * 1.442695 when x is close to zero, so it may technically be safe to rule
+; out negative zero (although this is likely too risky to implement). This test
+; watches for such a change.
+define ppc_fp128 @ret_log2_ppcf128(ppc_fp128 nofpclass(nan inf zero sub nnorm) %arg) {
+; CHECK-LABEL: define nofpclass(nan inf) ppc_fp128 @ret_log2_ppcf128(
+; CHECK-SAME: ppc_fp128 nofpclass(nan inf zero sub nnorm) [[ARG:%.*]]) #[[ATTR2]] {
+; CHECK-NEXT:    [[CALL:%.*]] = call nofpclass(nan inf) ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 nofpclass(nan inf zero sub nnorm) [[ARG]]) #[[ATTR4]]
+; CHECK-NEXT:    ret ppc_fp128 [[CALL]]
+;
+  %call = call ppc_fp128 @llvm.log2.ppcf128(ppc_fp128 %arg)
+  ret ppc_fp128 %call
+}
+
+; |log10(x)| < |log(x)|
+define ppc_fp128 @ret_log10_ppcf128(ppc_fp128 nofpclass(nan inf zero sub nnorm) %arg) {
+; CHECK-LABEL: define nofpclass(nan inf) ppc_fp128 @ret_log10_ppcf128(
+; CHECK-SAME: ppc_fp128 nofpclass(nan inf zero sub nnorm) [[ARG:%.*]]) #[[ATTR2]] {
+; CHECK-NEXT:    [[CALL:%.*]] = call nofpclass(nan inf) ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 nofpclass(nan inf zero sub nnorm) [[ARG]]) #[[ATTR4]]
+; CHECK-NEXT:    ret ppc_fp128 [[CALL]]
+;
+  %call = call ppc_fp128 @llvm.log10.ppcf128(ppc_fp128 %arg)
+  ret ppc_fp128 %call
+}
+
+define ppc_fp128 @ret_logl(ppc_fp128 nofpclass(nan inf zero sub nnorm) %arg) {
+; CHECK-LABEL: define ppc_fp128 @ret_logl(
+; CHECK-SAME: ppc_fp128 nofpclass(nan inf zero sub nnorm) [[ARG:%.*]]) #[[ATTR3:[0-9]+]] {
----------------
ZERICO2005 wrote:

How can I have `nofpclass` attributes added to `call ppc_fp128 @logl(ppc_fp128 %arg)`?

`llvm.log.ppcf128` returns `nofpclass(nan inf)` in the exact same scenario.

https://github.com/llvm/llvm-project/pull/223296


More information about the llvm-commits mailing list