[llvm] 876f3d6 - ValueTracking: Add test for isKnownNeverInfinity for fptrunc

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 22 06:38:20 PST 2022


Author: Matt Arsenault
Date: 2022-12-22T09:38:14-05:00
New Revision: 876f3d6c91e4e3862ac4027b09720a77aa4299cf

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

LOG: ValueTracking: Add test for isKnownNeverInfinity for fptrunc

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 dbf2ef51eba32..ee88074e1145f 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3797,6 +3797,10 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
       // Peek through to source op. If it is not infinity, this is not infinity.
       return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1);
     }
+    case Instruction::FPTrunc: {
+      // Need a range check.
+      return false;
+    }
     default:
       break;
     }

diff  --git a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
index 8f6e4fa069cc3..a8c3ffff7bf5e 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
@@ -1264,6 +1264,30 @@ define i1 @isKnownNeverInfinity_fpext_sitofp(i16 %x) {
   ret i1 %r
 }
 
+define i1 @isKnownNeverInfinity_fptrunc(double %x) {
+; CHECK-LABEL: @isKnownNeverInfinity_fptrunc(
+; CHECK-NEXT:    [[A:%.*]] = fadd ninf double [[X:%.*]], 1.000000e+00
+; CHECK-NEXT:    [[E:%.*]] = fptrunc double [[A]] to float
+; CHECK-NEXT:    [[R:%.*]] = fcmp une float [[E]], 0x7FF0000000000000
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %a = fadd ninf double %x, 1.0
+  %e = fptrunc double %a to float
+  %r = fcmp une float %e, 0x7FF0000000000000
+  ret i1 %r
+}
+
+define i1 @isNotKnownNeverInfinity_fptrunc(double %unknown) {
+; CHECK-LABEL: @isNotKnownNeverInfinity_fptrunc(
+; CHECK-NEXT:    [[E:%.*]] = fptrunc double [[UNKNOWN:%.*]] to float
+; CHECK-NEXT:    [[R:%.*]] = fcmp une float [[E]], 0x7FF0000000000000
+; CHECK-NEXT:    ret i1 [[R]]
+;
+  %e = fptrunc double %unknown to float
+  %r = fcmp une float %e, 0x7FF0000000000000
+  ret i1 %r
+}
+
 define i1 @isKnownNeverInfinity_canonicalize(double %x) {
 ; CHECK-LABEL: @isKnownNeverInfinity_canonicalize(
 ; CHECK-NEXT:    ret i1 true


        


More information about the llvm-commits mailing list