[PATCH] D139318: ValueTracking: Teach isKnownNeverInfinity about llvm.sin/llvm.cos

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 5 05:35:17 PST 2022


arsenm created this revision.
arsenm added reviewers: spatel, kpn, andrew.w.kaylor, sepavloff, nlopes.
Herald added a subscriber: hiraditya.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

https://reviews.llvm.org/D139318

Files:
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/test/Transforms/InstSimplify/floating-point-compare.ll


Index: llvm/test/Transforms/InstSimplify/floating-point-compare.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/floating-point-compare.ll
+++ llvm/test/Transforms/InstSimplify/floating-point-compare.ll
@@ -1729,9 +1729,7 @@
 ; No source check required
 define i1 @isKnownNeverInfinity_sin(double %x) {
 ; CHECK-LABEL: @isKnownNeverInfinity_sin(
-; CHECK-NEXT:    [[E:%.*]] = call double @llvm.sin.f64(double [[X:%.*]])
-; CHECK-NEXT:    [[R:%.*]] = fcmp une double [[E]], 0x7FF0000000000000
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 true
 ;
   %e = call double @llvm.sin.f64(double %x)
   %r = fcmp une double %e, 0x7ff0000000000000
@@ -1743,9 +1741,7 @@
 ; No source check required
 define i1 @isKnownNeverInfinity_cos(double %x) {
 ; CHECK-LABEL: @isKnownNeverInfinity_cos(
-; CHECK-NEXT:    [[E:%.*]] = call double @llvm.cos.f64(double [[X:%.*]])
-; CHECK-NEXT:    [[R:%.*]] = fcmp une double [[E]], 0x7FF0000000000000
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 true
 ;
   %e = call double @llvm.cos.f64(double %x)
   %r = fcmp une double %e, 0x7ff0000000000000
Index: llvm/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/lib/Analysis/ValueTracking.cpp
+++ llvm/lib/Analysis/ValueTracking.cpp
@@ -3807,6 +3807,10 @@
 
     if (const auto *II = dyn_cast<IntrinsicInst>(V)) {
       switch (II->getIntrinsicID()) {
+      case Intrinsic::sin:
+      case Intrinsic::cos:
+        // Return NaN on infinite inputs.
+        return true;
       case Intrinsic::fabs:
       case Intrinsic::sqrt:
       case Intrinsic::canonicalize:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139318.480073.patch
Type: text/x-patch
Size: 1680 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221205/26310518/attachment.bin>


More information about the llvm-commits mailing list