Skip to content

Commit ba1669c

Browse files
committed
ValueTracking: Look through fabs and fneg in isKnownNeverInfinity
1 parent d24fe81 commit ba1669c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3778,6 +3778,7 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
37783778
Type *FPTy = Inst->getType()->getScalarType();
37793779
return ilogb(APFloat::getLargest(FPTy->getFltSemantics())) >= IntSize;
37803780
}
3781+
case Instruction::FNeg:
37813782
case Instruction::FPExt: {
37823783
// Peek through to source op. If it is not infinity, this is not infinity.
37833784
return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1);
@@ -3788,6 +3789,7 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
37883789

37893790
if (const auto *II = dyn_cast<IntrinsicInst>(V)) {
37903791
switch (II->getIntrinsicID()) {
3792+
case Intrinsic::fabs:
37913793
case Intrinsic::canonicalize:
37923794
return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1);
37933795
default:

llvm/test/Transforms/InstSimplify/floating-point-compare.ll

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,3 +1283,45 @@ define i1 @isNotKnownNeverInfinity_canonicalize(double %x) {
12831283
%r = fcmp une double %e, 0x7ff0000000000000
12841284
ret i1 %r
12851285
}
1286+
1287+
define i1 @isKnownNeverInfinity_fabs(double %x) {
1288+
; CHECK-LABEL: @isKnownNeverInfinity_fabs(
1289+
; CHECK-NEXT: ret i1 true
1290+
;
1291+
%a = fadd ninf double %x, 1.0
1292+
%e = call double @llvm.fabs.f64(double %a)
1293+
%r = fcmp une double %e, 0x7ff0000000000000
1294+
ret i1 %r
1295+
}
1296+
1297+
define i1 @isNotKnownNeverInfinity_fabs(double %x) {
1298+
; CHECK-LABEL: @isNotKnownNeverInfinity_fabs(
1299+
; CHECK-NEXT: [[E:%.*]] = call double @llvm.fabs.f64(double [[X:%.*]])
1300+
; CHECK-NEXT: [[R:%.*]] = fcmp une double [[E]], 0x7FF0000000000000
1301+
; CHECK-NEXT: ret i1 [[R]]
1302+
;
1303+
%e = call double @llvm.fabs.f64(double %x)
1304+
%r = fcmp une double %e, 0x7ff0000000000000
1305+
ret i1 %r
1306+
}
1307+
1308+
define i1 @isKnownNeverInfinity_fneg(double %x) {
1309+
; CHECK-LABEL: @isKnownNeverInfinity_fneg(
1310+
; CHECK-NEXT: ret i1 true
1311+
;
1312+
%a = fadd ninf double %x, 1.0
1313+
%e = fneg double %a
1314+
%r = fcmp une double %e, 0x7ff0000000000000
1315+
ret i1 %r
1316+
}
1317+
1318+
define i1 @isNotKnownNeverInfinity_fneg(double %x) {
1319+
; CHECK-LABEL: @isNotKnownNeverInfinity_fneg(
1320+
; CHECK-NEXT: [[E:%.*]] = fneg double [[X:%.*]]
1321+
; CHECK-NEXT: [[R:%.*]] = fcmp une double [[E]], 0x7FF0000000000000
1322+
; CHECK-NEXT: ret i1 [[R]]
1323+
;
1324+
%e = fneg double %x
1325+
%r = fcmp une double %e, 0x7ff0000000000000
1326+
ret i1 %r
1327+
}

0 commit comments

Comments
 (0)