[llvm] 2c52c81 - ValueTracking: Document some difficult isKnownNeverInfinity cases
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 20 10:22:26 PST 2022
Author: Matt Arsenault
Date: 2022-12-20T13:22:22-05:00
New Revision: 2c52c811eef6ba1a9a0390aa2310d5fcaf128d7b
URL: https://github.com/llvm/llvm-project/commit/2c52c811eef6ba1a9a0390aa2310d5fcaf128d7b
DIFF: https://github.com/llvm/llvm-project/commit/2c52c811eef6ba1a9a0390aa2310d5fcaf128d7b.diff
LOG: ValueTracking: Document some difficult isKnownNeverInfinity cases
Add a comment and some negative tests. I'd like to have test coverage
and explicit handling of all the math operations for clarity.
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 c97092b6abdf..dbf2ef51eba3 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3833,6 +3833,24 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
case Intrinsic::maximum:
return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1) &&
isKnownNeverInfinity(Inst->getOperand(1), TLI, Depth + 1);
+ case Intrinsic::log:
+ case Intrinsic::log10:
+ case Intrinsic::log2:
+ // log(+inf) -> +inf
+ // log([+-]0.0) -> -inf
+ // log(-inf) -> nan
+ // log(-x) -> nan
+ // TODO: We lack API to check the == 0 case.
+ return false;
+ case Intrinsic::exp:
+ case Intrinsic::exp2:
+ case Intrinsic::pow:
+ case Intrinsic::powi:
+ case Intrinsic::fma:
+ case Intrinsic::fmuladd:
+ // These can return infinities on overflow cases, so it's hard to prove
+ // anything about it.
+ 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 52b370a9cacf..8f6e4fa069cc 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
@@ -2034,3 +2034,101 @@ define i1 @isKnownNeverNegInfinity_log2_maybe_0(double %x) {
}
declare double @llvm.log2.f64(double)
+
+define i1 @isNotKnownNeverInfinity_pow(double %x, double %y) {
+; CHECK-LABEL: @isNotKnownNeverInfinity_pow(
+; 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.pow.f64(double [[NINF_X]], double [[NINF_Y]])
+; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %ninf.x = fadd ninf double %x, 1.0
+ %ninf.y = fadd ninf double %y, 1.0
+ %op = call double @llvm.pow.f64(double %ninf.x, double %ninf.y)
+ %cmp = fcmp une double %op, 0x7ff0000000000000
+ ret i1 %cmp
+}
+
+declare double @llvm.pow.f64(double, double)
+
+define i1 @isNotKnownNeverInfinity_powi(double %x) {
+; CHECK-LABEL: @isNotKnownNeverInfinity_powi(
+; CHECK-NEXT: [[NINF_X:%.*]] = fadd ninf double [[X:%.*]], 1.000000e+00
+; CHECK-NEXT: [[OP:%.*]] = call double @llvm.powi.f64.i32(double [[NINF_X]], i32 2)
+; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %ninf.x = fadd ninf double %x, 1.0
+ %op = call double @llvm.powi.f64.i32(double %ninf.x, i32 2)
+ %cmp = fcmp une double %op, 0x7ff0000000000000
+ ret i1 %cmp
+}
+
+declare double @llvm.powi.f64(double, i32)
+
+define i1 @isNotKnownNeverInfinity_exp(double %x) {
+; CHECK-LABEL: @isNotKnownNeverInfinity_exp(
+; CHECK-NEXT: [[A:%.*]] = fadd ninf double [[X:%.*]], 1.000000e+00
+; CHECK-NEXT: [[E:%.*]] = call double @llvm.exp.f64(double [[A]])
+; CHECK-NEXT: [[R:%.*]] = fcmp une double [[E]], 0x7FF0000000000000
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %a = fadd ninf double %x, 1.0
+ %e = call double @llvm.exp.f64(double %a)
+ %r = fcmp une double %e, 0x7ff0000000000000
+ ret i1 %r
+}
+
+declare double @llvm.exp.f64(double)
+
+define i1 @isNotKnownNeverInfinity_exp2(double %x) {
+; CHECK-LABEL: @isNotKnownNeverInfinity_exp2(
+; CHECK-NEXT: [[A:%.*]] = fadd ninf double [[X:%.*]], 1.000000e+00
+; CHECK-NEXT: [[E:%.*]] = call double @llvm.exp2.f64(double [[A]])
+; CHECK-NEXT: [[R:%.*]] = fcmp une double [[E]], 0x7FF0000000000000
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %a = fadd ninf double %x, 1.0
+ %e = call double @llvm.exp2.f64(double %a)
+ %r = fcmp une double %e, 0x7ff0000000000000
+ ret i1 %r
+}
+
+define i1 @isNotKnownNeverInfinity_fma(double %x, double %y, double %z) {
+; CHECK-LABEL: @isNotKnownNeverInfinity_fma(
+; CHECK-NEXT: [[NINF_X:%.*]] = fadd ninf double [[X:%.*]], 1.000000e+00
+; CHECK-NEXT: [[NINF_Y:%.*]] = fadd ninf double [[Y:%.*]], 1.000000e+00
+; CHECK-NEXT: [[NINF_Z:%.*]] = fadd ninf double [[Z:%.*]], 1.000000e+00
+; CHECK-NEXT: [[OP:%.*]] = call double @llvm.fma.f64(double [[NINF_X]], double [[NINF_Y]], double [[NINF_Z]])
+; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %ninf.x = fadd ninf double %x, 1.0
+ %ninf.y = fadd ninf double %y, 1.0
+ %ninf.z = fadd ninf double %z, 1.0
+ %op = call double @llvm.fma.f64(double %ninf.x, double %ninf.y, double %ninf.z)
+ %cmp = fcmp une double %op, 0x7ff0000000000000
+ ret i1 %cmp
+}
+
+declare double @llvm.fma.f64(double, double, double)
+
+define i1 @isNotKnownNeverInfinity_fmuladd(double %x, double %y, double %z) {
+; CHECK-LABEL: @isNotKnownNeverInfinity_fmuladd(
+; CHECK-NEXT: [[NINF_X:%.*]] = fadd ninf double [[X:%.*]], 1.000000e+00
+; CHECK-NEXT: [[NINF_Y:%.*]] = fadd ninf double [[Y:%.*]], 1.000000e+00
+; CHECK-NEXT: [[NINF_Z:%.*]] = fadd ninf double [[Z:%.*]], 1.000000e+00
+; CHECK-NEXT: [[OP:%.*]] = call double @llvm.fmuladd.f64(double [[NINF_X]], double [[NINF_Y]], double [[NINF_Z]])
+; CHECK-NEXT: [[CMP:%.*]] = fcmp une double [[OP]], 0x7FF0000000000000
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %ninf.x = fadd ninf double %x, 1.0
+ %ninf.y = fadd ninf double %y, 1.0
+ %ninf.z = fadd ninf double %z, 1.0
+ %op = call double @llvm.fmuladd.f64(double %ninf.x, double %ninf.y, double %ninf.z)
+ %cmp = fcmp une double %op, 0x7ff0000000000000
+ ret i1 %cmp
+}
+
+declare double @llvm.fmuladd.f64(double, double, double)
More information about the llvm-commits
mailing list