From 41dd02e8575144e576e9ad111bbdc3f856c58445 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Sun, 4 Dec 2022 09:18:49 -0500 Subject: [PATCH] ValueTracking: Teach isKnownNeverInfinity about min/max functions --- llvm/lib/Analysis/ValueTracking.cpp | 6 ++++++ .../InstSimplify/floating-point-compare.ll | 24 ++++------------------ 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index c25506e..4181831 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -3822,6 +3822,12 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI, case Intrinsic::fptrunc_round: // Requires knowing the value range. return false; + case Intrinsic::minnum: + case Intrinsic::maxnum: + case Intrinsic::minimum: + case Intrinsic::maximum: + return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1) && + isKnownNeverInfinity(Inst->getOperand(1), 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 a2628d5..019069a 100644 --- a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll +++ b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll @@ -1663,11 +1663,7 @@ define i1 @isKnownNeverInfinity_ceil_x86_fp80(x86_fp80 %x) { define i1 @isKnownNeverInfinity_minnum(double %x, double %y) { ; CHECK-LABEL: @isKnownNeverInfinity_minnum( -; CHECK-NEXT: [[NINF_X:%.*]] = fadd ninf double [[X:%.*]], 1.000000e+00 -; CHECK-NEXT: [[NINF_Y:%.*]] = fadd ninf double [[Y:%.*]], 1.000000e+00 -; CHECK-NEXT: [[OP:%.*]] = call double @llvm.minnum.f64(double [[NINF_X]], double [[NINF_Y]]) -; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000 -; CHECK-NEXT: ret i1 [[CMP]] +; CHECK-NEXT: ret i1 true ; %ninf.x = fadd ninf double %x, 1.0 %ninf.y = fadd ninf double %y, 1.0 @@ -1706,11 +1702,7 @@ declare double @llvm.minnum.f64(double, double) define i1 @isKnownNeverInfinity_maxnum(double %x, double %y) { ; CHECK-LABEL: @isKnownNeverInfinity_maxnum( -; CHECK-NEXT: [[NINF_X:%.*]] = fadd ninf double [[X:%.*]], 1.000000e+00 -; CHECK-NEXT: [[NINF_Y:%.*]] = fadd ninf double [[Y:%.*]], 1.000000e+00 -; CHECK-NEXT: [[OP:%.*]] = call double @llvm.maxnum.f64(double [[NINF_X]], double [[NINF_Y]]) -; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000 -; CHECK-NEXT: ret i1 [[CMP]] +; CHECK-NEXT: ret i1 true ; %ninf.x = fadd ninf double %x, 1.0 %ninf.y = fadd ninf double %y, 1.0 @@ -1749,11 +1741,7 @@ declare double @llvm.maxnum.f64(double, double) define i1 @isKnownNeverInfinity_minimum(double %x, double %y) { ; CHECK-LABEL: @isKnownNeverInfinity_minimum( -; CHECK-NEXT: [[NINF_X:%.*]] = fadd ninf double [[X:%.*]], 1.000000e+00 -; CHECK-NEXT: [[NINF_Y:%.*]] = fadd ninf double [[Y:%.*]], 1.000000e+00 -; CHECK-NEXT: [[OP:%.*]] = call double @llvm.minimum.f64(double [[NINF_X]], double [[NINF_Y]]) -; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000 -; CHECK-NEXT: ret i1 [[CMP]] +; CHECK-NEXT: ret i1 true ; %ninf.x = fadd ninf double %x, 1.0 %ninf.y = fadd ninf double %y, 1.0 @@ -1792,11 +1780,7 @@ declare double @llvm.minimum.f64(double, double) define i1 @isKnownNeverInfinity_maximum(double %x, double %y) { ; CHECK-LABEL: @isKnownNeverInfinity_maximum( -; CHECK-NEXT: [[NINF_X:%.*]] = fadd ninf double [[X:%.*]], 1.000000e+00 -; CHECK-NEXT: [[NINF_Y:%.*]] = fadd ninf double [[Y:%.*]], 1.000000e+00 -; CHECK-NEXT: [[OP:%.*]] = call double @llvm.maximum.f64(double [[NINF_X]], double [[NINF_Y]]) -; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000 -; CHECK-NEXT: ret i1 [[CMP]] +; CHECK-NEXT: ret i1 true ; %ninf.x = fadd ninf double %x, 1.0 %ninf.y = fadd ninf double %y, 1.0 -- 2.7.4