Skip to content

[Support] KnownFPClass: add static helpers for more trig intrinsics - #190609

Merged
tgymnich merged 1 commit into
llvm:mainfrom
tgymnich:value-tracking-trig
Apr 9, 2026
Merged

tgymnich merged 1 commit into
llvm:mainfrom
tgymnich:value-tracking-trig

Conversation

@tgymnich

@tgymnich tgymnich commented Apr 6, 2026

Copy link
Copy Markdown
Member

Add KnownFPClass::tan, sinh, cosh, tanh, asin, acos, atan, and atan2 static helper methods, following the same pattern as the existing sin/cos helpers.

@github-actions

github-actions Bot commented Apr 6, 2026 •

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

@tgymnich
tgymnich marked this pull request as ready for review April 6, 2026 16:47
@tgymnich
tgymnich requested a review from nikic as a code owner April 6, 2026 16:47
@llvmbot llvmbot added llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:support llvm:analysis Includes value tracking, cost tables and constant folding llvm:transforms labels Apr 6, 2026
@llvmbot

llvmbot commented Apr 6, 2026 •

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-llvm-support

Author: Tim Gymnich (tgymnich)

Changes

Add KnownFPClass::tan, sinh, cosh, tanh, asin, acos, atan, and atan2 static helper methods, following the same pattern as the existing sin/cos helpers.


Full diff: https://github.com/llvm/llvm-project/pull/190609.diff

5 Files Affected:

  • (modified) llvm/include/llvm/Support/KnownFPClass.h (+25)
  • (modified) llvm/lib/Analysis/ValueTracking.cpp (+48-4)
  • (modified) llvm/lib/Support/KnownFPClass.cpp (+111)
  • (modified) llvm/test/Transforms/InstSimplify/known-never-infinity.ll (+118)
  • (modified) llvm/test/Transforms/InstSimplify/known-never-nan.ll (+20)
diff --git a/llvm/include/llvm/Support/KnownFPClass.h b/llvm/include/llvm/Support/KnownFPClass.h
index c48e0f8b7b65b..b18bfb55eacd1 100644
--- a/llvm/include/llvm/Support/KnownFPClass.h
+++ b/llvm/include/llvm/Support/KnownFPClass.h
@@ -299,6 +299,31 @@ struct KnownFPClass {
   /// Report known values for cos
   LLVM_ABI static KnownFPClass cos(const KnownFPClass &Src);
 
+  /// Report known values for tan
+  LLVM_ABI static KnownFPClass tan(const KnownFPClass &Src);
+
+  /// Report known values for sinh
+  LLVM_ABI static KnownFPClass sinh(const KnownFPClass &Src);
+
+  /// Report known values for cosh
+  LLVM_ABI static KnownFPClass cosh(const KnownFPClass &Src);
+
+  /// Report known values for tanh
+  LLVM_ABI static KnownFPClass tanh(const KnownFPClass &Src);
+
+  /// Report known values for asin
+  LLVM_ABI static KnownFPClass asin(const KnownFPClass &Src);
+
+  /// Report known values for acos
+  LLVM_ABI static KnownFPClass acos(const KnownFPClass &Src);
+
+  /// Report known values for atan
+  LLVM_ABI static KnownFPClass atan(const KnownFPClass &Src);
+
+  /// Report known values for atan2
+  LLVM_ABI static KnownFPClass atan2(const KnownFPClass &LHS,
+                                     const KnownFPClass &RHS);
+
   /// Return true if the sign bit must be 0, ignoring the sign of nans.
   bool signBitIsZeroOrNaN() const { return isKnownNever(fcNegative); }
 
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index a0fb28612c534..7f20f8f43f110 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -5258,13 +5258,57 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
       break;
     }
     case Intrinsic::sin:
-    case Intrinsic::cos: {
-      // Return NaN on infinite inputs.
+    case Intrinsic::cos:
+    case Intrinsic::tan:
+    case Intrinsic::sinh:
+    case Intrinsic::cosh:
+    case Intrinsic::tanh:
+    case Intrinsic::asin:
+    case Intrinsic::acos:
+    case Intrinsic::atan: {
       KnownFPClass KnownSrc;
       computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
                           KnownSrc, Q, Depth + 1);
-      Known = IID == Intrinsic::sin ? KnownFPClass::sin(KnownSrc)
-                                    : KnownFPClass::cos(KnownSrc);
+      switch (IID) {
+      case Intrinsic::sin:
+        Known = KnownFPClass::sin(KnownSrc);
+        break;
+      case Intrinsic::cos:
+        Known = KnownFPClass::cos(KnownSrc);
+        break;
+      case Intrinsic::tan:
+        Known = KnownFPClass::tan(KnownSrc);
+        break;
+      case Intrinsic::sinh:
+        Known = KnownFPClass::sinh(KnownSrc);
+        break;
+      case Intrinsic::cosh:
+        Known = KnownFPClass::cosh(KnownSrc);
+        break;
+      case Intrinsic::tanh:
+        Known = KnownFPClass::tanh(KnownSrc);
+        break;
+      case Intrinsic::asin:
+        Known = KnownFPClass::asin(KnownSrc);
+        break;
+      case Intrinsic::acos:
+        Known = KnownFPClass::acos(KnownSrc);
+        break;
+      case Intrinsic::atan:
+        Known = KnownFPClass::atan(KnownSrc);
+        break;
+      default:
+        llvm_unreachable("unhandled trig intrinsic");
+      }
+      break;
+    }
+    case Intrinsic::atan2: {
+      KnownFPClass KnownLHS, KnownRHS;
+      computeKnownFPClass(II->getArgOperand(0), DemandedElts, InterestedClasses,
+                          KnownLHS, Q, Depth + 1);
+      computeKnownFPClass(II->getArgOperand(1), DemandedElts, InterestedClasses,
+                          KnownRHS, Q, Depth + 1);
+      Known = KnownFPClass::atan2(KnownLHS, KnownRHS);
       break;
     }
     case Intrinsic::maxnum:
diff --git a/llvm/lib/Support/KnownFPClass.cpp b/llvm/lib/Support/KnownFPClass.cpp
index 4f704eabfc6ec..3d361c80ff154 100644
--- a/llvm/lib/Support/KnownFPClass.cpp
+++ b/llvm/lib/Support/KnownFPClass.cpp
@@ -612,6 +612,117 @@ KnownFPClass KnownFPClass::cos(const KnownFPClass &KnownSrc) {
   return sin(KnownSrc);
 }
 
+KnownFPClass KnownFPClass::tan(const KnownFPClass &KnownSrc) {
+  KnownFPClass Known;
+
+  // tan never returns Inf (tan(±Inf) = NaN; tan(finite) = finite).
+  Known.knownNot(fcInf);
+
+  // NaN propagates. tan(±Inf) is NaN.
+  if (KnownSrc.isKnownNeverNaN() && KnownSrc.isKnownNeverInfinity())
+    Known.knownNot(fcNan);
+
+  return Known;
+}
+
+KnownFPClass KnownFPClass::sinh(const KnownFPClass &KnownSrc) {
+  KnownFPClass Known;
+
+  // sinh is sign-preserving: sinh(x) < 0 iff x < 0.
+  if (KnownSrc.isKnownNever(fcNegative))
+    Known.knownNot(fcNegative);
+
+  Known.propagateNaN(KnownSrc);
+
+  return Known;
+}
+
+KnownFPClass KnownFPClass::cosh(const KnownFPClass &KnownSrc) {
+  KnownFPClass Known;
+
+  // cosh(x) >= 1 for all real x; cosh(±Inf) = +Inf. Never negative.
+  Known.knownNot(fcNegative);
+
+  Known.propagateNaN(KnownSrc);
+
+  return Known;
+}
+
+KnownFPClass KnownFPClass::tanh(const KnownFPClass &KnownSrc) {
+  KnownFPClass Known;
+
+  // tanh is bounded to (-1, 1), never Inf.
+  Known.knownNot(fcInf);
+
+  // tanh is sign-preserving: tanh(x) < 0 iff x < 0.
+  if (KnownSrc.isKnownNever(fcNegative))
+    Known.knownNot(fcNegative);
+
+  Known.propagateNaN(KnownSrc);
+
+  return Known;
+}
+
+KnownFPClass KnownFPClass::asin(const KnownFPClass &KnownSrc) {
+  KnownFPClass Known;
+
+  // asin is bounded to [-π/2, π/2], never Inf.
+  Known.knownNot(fcInf);
+
+  // asin is sign-preserving.
+  if (KnownSrc.isKnownNever(fcNegative))
+    Known.knownNot(fcNegative);
+
+  // NaN propagates. asin(x) is also NaN for |x| > 1, so we cannot rule
+  // out NaN without knowing the source is in [-1, 1].
+  Known.propagateNaN(KnownSrc);
+
+  return Known;
+}
+
+KnownFPClass KnownFPClass::acos(const KnownFPClass &KnownSrc) {
+  KnownFPClass Known;
+
+  // acos is bounded to [0, π], never Inf or negative.
+  Known.knownNot(fcInf);
+  Known.knownNot(fcNegative);
+
+  // NaN propagates. acos(x) is also NaN for |x| > 1, so we cannot rule
+  // out NaN without knowing the source is in [-1, 1].
+  Known.propagateNaN(KnownSrc);
+
+  return Known;
+}
+
+KnownFPClass KnownFPClass::atan(const KnownFPClass &KnownSrc) {
+  KnownFPClass Known;
+
+  // atan is bounded to (-π/2, π/2), never Inf. atan(±Inf) = ±π/2 (finite).
+  Known.knownNot(fcInf);
+
+  // atan is sign-preserving: atan(x) < 0 iff x < 0.
+  if (KnownSrc.isKnownNever(fcNegative))
+    Known.knownNot(fcNegative);
+
+  Known.propagateNaN(KnownSrc);
+
+  return Known;
+}
+
+KnownFPClass KnownFPClass::atan2(const KnownFPClass &KnownLHS,
+                                 const KnownFPClass &KnownRHS) {
+  KnownFPClass Known;
+
+  // atan2 result is in (-π, π], never Inf.
+  Known.knownNot(fcInf);
+
+  // NaN if either operand is NaN.
+  if (KnownLHS.isKnownNeverNaN() && KnownRHS.isKnownNeverNaN())
+    Known.knownNot(fcNan);
+
+  return Known;
+}
+
 KnownFPClass KnownFPClass::fpext(const KnownFPClass &KnownSrc,
                                  const fltSemantics &DstTy,
                                  const fltSemantics &SrcTy) {
diff --git a/llvm/test/Transforms/InstSimplify/known-never-infinity.ll b/llvm/test/Transforms/InstSimplify/known-never-infinity.ll
index af83f00368597..11051b32ac2a1 100644
--- a/llvm/test/Transforms/InstSimplify/known-never-infinity.ll
+++ b/llvm/test/Transforms/InstSimplify/known-never-infinity.ll
@@ -750,6 +750,116 @@ define i1 @isKnownNeverInfinity_cos(double %x) {
   ret i1 %r
 }
 
+; No source check required
+define i1 @isKnownNeverInfinity_tan(double %x) {
+; CHECK-LABEL: define i1 @isKnownNeverInfinity_tan
+; CHECK-SAME: (double [[X:%.*]]) {
+; CHECK-NEXT:    ret i1 true
+;
+  %e = call double @llvm.tan.f64(double %x)
+  %r = fcmp une double %e, 0x7ff0000000000000
+  ret i1 %r
+}
+
+; No source check required
+define i1 @isKnownNeverInfinity_tanh(double %x) {
+; CHECK-LABEL: define i1 @isKnownNeverInfinity_tanh
+; CHECK-SAME: (double [[X:%.*]]) {
+; CHECK-NEXT:    ret i1 true
+;
+  %e = call double @llvm.tanh.f64(double %x)
+  %r = fcmp une double %e, 0x7ff0000000000000
+  ret i1 %r
+}
+
+; No source check required
+define i1 @isKnownNeverInfinity_asin(double %x) {
+; CHECK-LABEL: define i1 @isKnownNeverInfinity_asin
+; CHECK-SAME: (double [[X:%.*]]) {
+; CHECK-NEXT:    ret i1 true
+;
+  %e = call double @llvm.asin.f64(double %x)
+  %r = fcmp une double %e, 0x7ff0000000000000
+  ret i1 %r
+}
+
+; No source check required
+define i1 @isKnownNeverInfinity_acos(double %x) {
+; CHECK-LABEL: define i1 @isKnownNeverInfinity_acos
+; CHECK-SAME: (double [[X:%.*]]) {
+; CHECK-NEXT:    ret i1 true
+;
+  %e = call double @llvm.acos.f64(double %x)
+  %r = fcmp une double %e, 0x7ff0000000000000
+  ret i1 %r
+}
+
+; No source check required
+define i1 @isKnownNeverInfinity_atan(double %x) {
+; CHECK-LABEL: define i1 @isKnownNeverInfinity_atan
+; CHECK-SAME: (double [[X:%.*]]) {
+; CHECK-NEXT:    ret i1 true
+;
+  %e = call double @llvm.atan.f64(double %x)
+  %r = fcmp une double %e, 0x7ff0000000000000
+  ret i1 %r
+}
+
+; No source check required
+define i1 @isKnownNeverInfinity_atan2(double %x, double %y) {
+; CHECK-LABEL: define i1 @isKnownNeverInfinity_atan2
+; CHECK-SAME: (double [[X:%.*]], double [[Y:%.*]]) {
+; CHECK-NEXT:    ret i1 true
+;
+  %e = call double @llvm.atan2.f64(double %x, double %y)
+  %r = fcmp une double %e, 0x7ff0000000000000
+  ret i1 %r
+}
+
+; sinh is sign-preserving: a non-negative input produces a non-negative result.
+define i1 @isKnownNeverNegative_sinh_nonneg(double nofpclass(nan ninf nzero nsub nnorm) %x) {
+; CHECK-LABEL: define i1 @isKnownNeverNegative_sinh_nonneg
+; CHECK-SAME: (double nofpclass(nan ninf nzero nsub nnorm) [[X:%.*]]) {
+; CHECK-NEXT:    ret i1 false
+;
+  %e = call double @llvm.sinh.f64(double %x)
+  %r = fcmp olt double %e, 0.0
+  ret i1 %r
+}
+
+; tanh is sign-preserving: a non-negative input produces a non-negative result.
+define i1 @isKnownNeverNegative_tanh_nonneg(double nofpclass(nan ninf nzero nsub nnorm) %x) {
+; CHECK-LABEL: define i1 @isKnownNeverNegative_tanh_nonneg
+; CHECK-SAME: (double nofpclass(nan ninf nzero nsub nnorm) [[X:%.*]]) {
+; CHECK-NEXT:    ret i1 false
+;
+  %e = call double @llvm.tanh.f64(double %x)
+  %r = fcmp olt double %e, 0.0
+  ret i1 %r
+}
+
+; asin is sign-preserving: a non-negative input produces a non-negative result.
+define i1 @isKnownNeverNegative_asin_nonneg(double nofpclass(nan ninf nzero nsub nnorm) %x) {
+; CHECK-LABEL: define i1 @isKnownNeverNegative_asin_nonneg
+; CHECK-SAME: (double nofpclass(nan ninf nzero nsub nnorm) [[X:%.*]]) {
+; CHECK-NEXT:    ret i1 false
+;
+  %e = call double @llvm.asin.f64(double %x)
+  %r = fcmp olt double %e, 0.0
+  ret i1 %r
+}
+
+; atan is sign-preserving: a non-negative input produces a non-negative result.
+define i1 @isKnownNeverNegative_atan_nonneg(double nofpclass(nan ninf nzero nsub nnorm) %x) {
+; CHECK-LABEL: define i1 @isKnownNeverNegative_atan_nonneg
+; CHECK-SAME: (double nofpclass(nan ninf nzero nsub nnorm) [[X:%.*]]) {
+; CHECK-NEXT:    ret i1 false
+;
+  %e = call double @llvm.atan.f64(double %x)
+  %r = fcmp olt double %e, 0.0
+  ret i1 %r
+}
+
 define i1 @isKnownNeverInfinity_log(double %x) {
 ; CHECK-LABEL: define i1 @isKnownNeverInfinity_log
 ; CHECK-SAME: (double [[X:%.*]]) {
@@ -1209,11 +1319,16 @@ define i1 @isKnownNeverInfinity_vector_reduce_fmin_fail(<4 x double> %x) {
   ret i1 %cmp
 }
 
+declare double @llvm.acos.f64(double)
+declare double @llvm.asin.f64(double)
+declare double @llvm.atan.f64(double)
+declare double @llvm.atan2.f64(double, double)
 declare double @llvm.arithmetic.fence.f64(double)
 declare double @llvm.canonicalize.f64(double)
 declare double @llvm.ceil.f64(double)
 declare double @llvm.copysign.f64(double, double)
 declare double @llvm.cos.f64(double)
+declare double @llvm.cosh.f64(double)
 declare double @llvm.exp2.f64(double)
 declare double @llvm.exp.f64(double)
 declare double @llvm.fabs.f64(double)
@@ -1235,7 +1350,10 @@ declare double @llvm.rint.f64(double)
 declare double @llvm.roundeven.f64(double)
 declare double @llvm.round.f64(double)
 declare double @llvm.sin.f64(double)
+declare double @llvm.sinh.f64(double)
 declare double @llvm.sqrt.f64(double)
+declare double @llvm.tan.f64(double)
+declare double @llvm.tanh.f64(double)
 declare double @llvm.trunc.f64(double)
 declare float @llvm.fptrunc.round.f32.f64(double, metadata)
 declare ppc_fp128 @llvm.ceil.ppcf128(ppc_fp128)
diff --git a/llvm/test/Transforms/InstSimplify/known-never-nan.ll b/llvm/test/Transforms/InstSimplify/known-never-nan.ll
index 907eca0a856a8..a98d98259df2d 100644
--- a/llvm/test/Transforms/InstSimplify/known-never-nan.ll
+++ b/llvm/test/Transforms/InstSimplify/known-never-nan.ll
@@ -554,6 +554,26 @@ unwind:
   resume ptr null
 }
 
+; tan(x) is never NaN when x is finite and not NaN (tan(±Inf) = NaN).
+define i1 @isKnownNeverNaN_tan_nonan_noinf(double nofpclass(nan inf) %x) {
+; CHECK-LABEL: @isKnownNeverNaN_tan_nonan_noinf(
+; CHECK-NEXT:    ret i1 false
+;
+  %e = call double @llvm.tan.f64(double %x)
+  %r = fcmp uno double %e, 0.0
+  ret i1 %r
+}
+
+; atan2 is never NaN when neither operand is NaN.
+define i1 @isKnownNeverNaN_atan2_nonan(double nofpclass(nan) %x, double nofpclass(nan) %y) {
+; CHECK-LABEL: @isKnownNeverNaN_atan2_nonan(
+; CHECK-NEXT:    ret i1 false
+;
+  %e = call double @llvm.atan2.f64(double %x, double %y)
+  %r = fcmp uno double %e, 0.0
+  ret i1 %r
+}
+
 ; This should not fold to false because fmul 0 * inf = nan
 define i1 @issue63316(i64 %arg) {
 ; CHECK-LABEL: @issue63316(

@tgymnich
tgymnich requested a review from arsenm April 6, 2026 22:52
@arsenm arsenm added the floating-point Floating-point math label Apr 8, 2026
Comment thread llvm/lib/Analysis/ValueTracking.cpp Resolved
@tgymnich
tgymnich force-pushed the value-tracking-trig branch 2 times, most recently from 02488d9 to faa6a0d Compare April 8, 2026 12:45
Comment thread llvm/lib/Support/KnownFPClass.cpp Resolved
@tgymnich
tgymnich force-pushed the value-tracking-trig branch from faa6a0d to 5d1f8a0 Compare April 9, 2026 15:04
Add KnownFPClass static helpers and computeKnownFPClass support for
tan, sinh, cosh, tanh, asin, acos, atan, and atan2:

- tan: never Inf; NaN-free if input is finite and non-NaN
- sinh: sign-preserving (sign of result matches sign of input)
- cosh: always non-negative (result >= 1 for all real inputs)
- tanh: never Inf; sign-preserving
- asin: never Inf; sign-preserving
- acos: never Inf or negative (result in [0, pi])
- atan: never Inf; sign-preserving (atan(+-Inf) = +-pi/2)
- atan2: never Inf; NaN-free if both operands are NaN-free

Tests are added in Attributor/nofpclass-trig.ll using direct nofpclass
attribute checking. Sign-preserving properties are tested via fabs to
show the inference is derived from the intrinsic's mathematical properties.
Indirect sin/cos tests are removed from InstSimplify/known-never-infinity.ll
as they are already covered by Attributor/nofpclass-sin-cos.ll.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@tgymnich
tgymnich force-pushed the value-tracking-trig branch from 5d1f8a0 to cfd8b54 Compare April 9, 2026 15:08
@tgymnich
tgymnich enabled auto-merge (squash) April 9, 2026 15:09
@tgymnich
tgymnich merged commit e76d803 into llvm:main Apr 9, 2026
7 of 8 checks passed
@tgymnich
tgymnich deleted the value-tracking-trig branch April 9, 2026 15:47
@llvm-ci

llvm-ci commented Apr 9, 2026

Copy link
Copy Markdown

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-gcc-ubuntu running on sie-linux-worker3 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/174/builds/34288

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
...
PASS: AddressSanitizer-x86_64-linux-dynamic :: TestCases/Linux/ptrace.cpp (6330 of 99509)
PASS: AddressSanitizer-x86_64-linux-dynamic :: TestCases/Posix/readv.cpp (6331 of 99509)
PASS: LeakSanitizer-AddressSanitizer-x86_64 :: TestCases/Linux/use_tls_static.cpp (6332 of 99509)
PASS: UBSan-MemorySanitizer-x86_64 :: TestCases/TypeCheck/Function/function.cpp (6333 of 99509)
PASS: LLVM :: CodeGen/X86/vector-fshr-sub128.ll (6334 of 99509)
PASS: AddressSanitizer-Unit :: ./Asan-x86_64-inline-Dynamic-Test/45/50 (6335 of 99509)
PASS: LLVM :: CodeGen/AMDGPU/shufflevector.v2i64.v2i64.ll (6336 of 99509)
PASS: LLVM :: CodeGen/AMDGPU/tid-mul-func-xnack-all-not-supported.ll (6337 of 99509)
PASS: LLVM :: MC/ARM/armv8a-fpmul.s (6338 of 99509)
PASS: Clang :: SemaTemplate/temp-param-subst-linear.cpp (6339 of 99509)
command timed out: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=3581.368360

YonahGoldberg pushed a commit to YonahGoldberg/llvm-project that referenced this pull request Apr 21, 2026
…lvm#190609)

Add KnownFPClass::tan, sinh, cosh, tanh, asin, acos, atan, and atan2
static helper methods, following the same pattern as the existing
sin/cos helpers.

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Comment on lines +677 to +679
// NaN propagates. asin(x) is also NaN for |x| > 1, so we cannot rule
// out NaN without knowing the source is in [-1, 1].
Known.propagateNaN(KnownSrc);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tgymnich! I think this change may have introduced a bug.

As your comment notes, asin returns NaN for any source outside the [-1, 1] domain. Yet we still call propagateNaN, which assumes a non-NaN source guarantees a non-NaN result.

For example, asin(2.0) should return NaN, but propagateNaN will incorrectly assume the result is a non-NaN.

acos below has a similar problem.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #213812 to fix this issue

dtcxzyw pushed a commit that referenced this pull request Aug 5, 2026
…13812)

`KnownFPClass` incorrectly assumed that a non-NaN input to `asin` or
`acos` implies a non-NaN result. However, both `asin` and `acos` can
return NaN from a finite input when `|x| > 1.0`, such as `asin(2.0)` or
`acos(2.0)`.

I have fixed this by removing the calls to
`Known.propagateNaN(KnownSrc)`, which incorrectly propagated that
`asin(non-NaN) == non-NaN`.

I discovered this while working on
#211686. The same issue was
previously noted in a post-merge review comment on
#190609 (comment)

AI disclosure:
I used OpenAI Codex (GPT-5.6-sol) to help generate the test updates,
which I reviewed and tested locally.
llvm-sync Bot pushed a commit to arm/arm-toolchain that referenced this pull request Aug 5, 2026
… `acos` (#213812)

`KnownFPClass` incorrectly assumed that a non-NaN input to `asin` or
`acos` implies a non-NaN result. However, both `asin` and `acos` can
return NaN from a finite input when `|x| > 1.0`, such as `asin(2.0)` or
`acos(2.0)`.

I have fixed this by removing the calls to
`Known.propagateNaN(KnownSrc)`, which incorrectly propagated that
`asin(non-NaN) == non-NaN`.

I discovered this while working on
llvm/llvm-project#211686. The same issue was
previously noted in a post-merge review comment on
llvm/llvm-project#190609 (comment)

AI disclosure:
I used OpenAI Codex (GPT-5.6-sol) to help generate the test updates,
which I reviewed and tested locally.
llvm-upstreamsync Bot pushed a commit to qualcomm/cpullvm-toolchain that referenced this pull request Aug 5, 2026
… `acos` (#213812)

`KnownFPClass` incorrectly assumed that a non-NaN input to `asin` or
`acos` implies a non-NaN result. However, both `asin` and `acos` can
return NaN from a finite input when `|x| > 1.0`, such as `asin(2.0)` or
`acos(2.0)`.

I have fixed this by removing the calls to
`Known.propagateNaN(KnownSrc)`, which incorrectly propagated that
`asin(non-NaN) == non-NaN`.

I discovered this while working on
llvm/llvm-project#211686. The same issue was
previously noted in a post-merge review comment on
llvm/llvm-project#190609 (comment)

AI disclosure:
I used OpenAI Codex (GPT-5.6-sol) to help generate the test updates,
which I reviewed and tested locally.
jinge90 pushed a commit to jinge90/llvm-project that referenced this pull request Aug 6, 2026
…vm#213812)

`KnownFPClass` incorrectly assumed that a non-NaN input to `asin` or
`acos` implies a non-NaN result. However, both `asin` and `acos` can
return NaN from a finite input when `|x| > 1.0`, such as `asin(2.0)` or
`acos(2.0)`.

I have fixed this by removing the calls to
`Known.propagateNaN(KnownSrc)`, which incorrectly propagated that
`asin(non-NaN) == non-NaN`.

I discovered this while working on
llvm#211686. The same issue was
previously noted in a post-merge review comment on
llvm#190609 (comment)

AI disclosure:
I used OpenAI Codex (GPT-5.6-sol) to help generate the test updates,
which I reviewed and tested locally.
tru pushed a commit that referenced this pull request Sep 30, 2026
…13812)

`KnownFPClass` incorrectly assumed that a non-NaN input to `asin` or
`acos` implies a non-NaN result. However, both `asin` and `acos` can
return NaN from a finite input when `|x| > 1.0`, such as `asin(2.0)` or
`acos(2.0)`.

I have fixed this by removing the calls to
`Known.propagateNaN(KnownSrc)`, which incorrectly propagated that
`asin(non-NaN) == non-NaN`.

I discovered this while working on
#211686. The same issue was
previously noted in a post-merge review comment on
#190609 (comment)

AI disclosure:
I used OpenAI Codex (GPT-5.6-sol) to help generate the test updates,
which I reviewed and tested locally.

(cherry picked from commit 0130acf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

floating-point Floating-point math llvm:analysis Includes value tracking, cost tables and constant folding llvm:instcombine Covers the InstCombine, InstSimplify and AggressiveInstCombine passes llvm:support llvm:transforms

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants