[llvm] ba1669c - ValueTracking: Look through fabs and fneg in isKnownNeverInfinity
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 17 00:06:23 PST 2022
Author: Matt Arsenault
Date: 2022-11-17T00:06:15-08:00
New Revision: ba1669c81f8c03610d600508b07d12944b553ec1
URL: https://github.com/llvm/llvm-project/commit/ba1669c81f8c03610d600508b07d12944b553ec1
DIFF: https://github.com/llvm/llvm-project/commit/ba1669c81f8c03610d600508b07d12944b553ec1.diff
LOG: ValueTracking: Look through fabs and fneg 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 6f67509b8011..40e4253fae53 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -3778,6 +3778,7 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
Type *FPTy = Inst->getType()->getScalarType();
return ilogb(APFloat::getLargest(FPTy->getFltSemantics())) >= IntSize;
}
+ case Instruction::FNeg:
case Instruction::FPExt: {
// Peek through to source op. If it is not infinity, this is not infinity.
return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1);
@@ -3788,6 +3789,7 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
if (const auto *II = dyn_cast<IntrinsicInst>(V)) {
switch (II->getIntrinsicID()) {
+ case Intrinsic::fabs:
case Intrinsic::canonicalize:
return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1);
default:
diff --git a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
index 8ae5c51bbc72..cb31ca705862 100644
--- a/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
+++ b/llvm/test/Transforms/InstSimplify/floating-point-compare.ll
@@ -1283,3 +1283,45 @@ define i1 @isNotKnownNeverInfinity_canonicalize(double %x) {
%r = fcmp une double %e, 0x7ff0000000000000
ret i1 %r
}
+
+define i1 @isKnownNeverInfinity_fabs(double %x) {
+; CHECK-LABEL: @isKnownNeverInfinity_fabs(
+; CHECK-NEXT: ret i1 true
+;
+ %a = fadd ninf double %x, 1.0
+ %e = call double @llvm.fabs.f64(double %a)
+ %r = fcmp une double %e, 0x7ff0000000000000
+ ret i1 %r
+}
+
+define i1 @isNotKnownNeverInfinity_fabs(double %x) {
+; CHECK-LABEL: @isNotKnownNeverInfinity_fabs(
+; CHECK-NEXT: [[E:%.*]] = call double @llvm.fabs.f64(double [[X:%.*]])
+; CHECK-NEXT: [[R:%.*]] = fcmp une double [[E]], 0x7FF0000000000000
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %e = call double @llvm.fabs.f64(double %x)
+ %r = fcmp une double %e, 0x7ff0000000000000
+ ret i1 %r
+}
+
+define i1 @isKnownNeverInfinity_fneg(double %x) {
+; CHECK-LABEL: @isKnownNeverInfinity_fneg(
+; CHECK-NEXT: ret i1 true
+;
+ %a = fadd ninf double %x, 1.0
+ %e = fneg double %a
+ %r = fcmp une double %e, 0x7ff0000000000000
+ ret i1 %r
+}
+
+define i1 @isNotKnownNeverInfinity_fneg(double %x) {
+; CHECK-LABEL: @isNotKnownNeverInfinity_fneg(
+; CHECK-NEXT: [[E:%.*]] = fneg double [[X:%.*]]
+; CHECK-NEXT: [[R:%.*]] = fcmp une double [[E]], 0x7FF0000000000000
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %e = fneg double %x
+ %r = fcmp une double %e, 0x7ff0000000000000
+ ret i1 %r
+}
More information about the llvm-commits
mailing list