[llvm] af7e80b - ValueTracking: Look through copysign in isKnownNeverInfinity

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 17 08:52:15 PST 2022


Author: Matt Arsenault
Date: 2022-11-17T08:52:09-08:00
New Revision: af7e80b7cb36e09f71e42035ba5285a4ee3880b1

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

LOG: ValueTracking: Look through copysign in isKnownNeverInfinity

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 4c73eca580f5..1d8f26d4ebe3 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3791,6 +3791,7 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
       switch (II->getIntrinsicID()) {
       case Intrinsic::fabs:
       case Intrinsic::canonicalize:
+      case Intrinsic::copysign:
         return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1);
       default:
         break;

diff  --git a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
index cb31ca705862..81bb0b9564ad 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
@@ -186,6 +186,7 @@ declare float @llvm.maximum.f32(float, float)
 declare double @llvm.exp2.f64(double)
 declare float @llvm.fma.f32(float,float,float)
 declare double @llvm.canonicalize.f64(double)
+declare double @llvm.copysign.f64(double, double)
 
 declare void @expect_equal(i1,i1)
 
@@ -1325,3 +1326,24 @@ define i1 @isNotKnownNeverInfinity_fneg(double %x) {
   %r = fcmp une double %e, 0x7ff0000000000000
   ret i1 %r
 }
+
+define i1 @isKnownNeverInfinity_copysign(double %x, double %sign) {
+; CHECK-LABEL: @isKnownNeverInfinity_copysign(
+; CHECK-NEXT:    ret i1 true
+;
+  %a = fadd ninf double %x, 1.0
+  %e = call double @llvm.copysign.f64(double %a, double %sign)
+  %r = fcmp une double %e, 0x7ff0000000000000
+  ret i1 %r
+}
+
+define i1 @isNotKnownNeverInfinity_copysign(double %x, double %sign) {
+; CHECK-LABEL: @isNotKnownNeverInfinity_copysign(
+; CHECK-NEXT:    [[E:%.*]] = call double @llvm.copysign.f64(double [[X:%.*]], double [[SIGN:%.*]])
+; CHECK-NEXT:    [[R:%.*]] = fcmp une double [[E]], 0x7FF0000000000000
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %e = call double @llvm.copysign.f64(double %x, double %sign)
+  %r = fcmp une double %e, 0x7ff0000000000000
+  ret i1 %r
+}


        


More information about the llvm-commits mailing list