From 876f3d6c91e4e3862ac4027b09720a77aa4299cf Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Sun, 4 Dec 2022 09:09:41 -0500 Subject: [PATCH] ValueTracking: Add test for isKnownNeverInfinity for fptrunc --- llvm/lib/Analysis/ValueTracking.cpp | 4 ++++ .../InstSimplify/floating-point-compare.ll | 24 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index dbf2ef5..ee88074 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 8f6e4fa..a8c3fff 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 -- 2.7.4