Skip to content

Commit d24fe81

Browse files
committed
ValueTracking: Look through canonicalize in isKnownNeverInfinity
1 parent 4fdf624 commit d24fe81

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,6 +3785,15 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
37853785
default:
37863786
break;
37873787
}
3788+
3789+
if (const auto *II = dyn_cast<IntrinsicInst>(V)) {
3790+
switch (II->getIntrinsicID()) {
3791+
case Intrinsic::canonicalize:
3792+
return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1);
3793+
default:
3794+
break;
3795+
}
3796+
}
37883797
}
37893798

37903799
// try to handle fixed width vector constants

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ declare <2 x float> @llvm.maxnum.v2f32(<2 x float>, <2 x float>)
185185
declare float @llvm.maximum.f32(float, float)
186186
declare double @llvm.exp2.f64(double)
187187
declare float @llvm.fma.f32(float,float,float)
188+
declare double @llvm.canonicalize.f64(double)
188189

189190
declare void @expect_equal(i1,i1)
190191

@@ -1261,3 +1262,24 @@ define i1 @isKnownNeverInfinity_fpext_sitofp(i16 %x) {
12611262
%r = fcmp oeq double %e, 0xfff0000000000000
12621263
ret i1 %r
12631264
}
1265+
1266+
define i1 @isKnownNeverInfinity_canonicalize(double %x) {
1267+
; CHECK-LABEL: @isKnownNeverInfinity_canonicalize(
1268+
; CHECK-NEXT: ret i1 true
1269+
;
1270+
%a = fadd ninf double %x, 1.0
1271+
%e = call double @llvm.canonicalize.f64(double %a)
1272+
%r = fcmp une double %e, 0x7ff0000000000000
1273+
ret i1 %r
1274+
}
1275+
1276+
define i1 @isNotKnownNeverInfinity_canonicalize(double %x) {
1277+
; CHECK-LABEL: @isNotKnownNeverInfinity_canonicalize(
1278+
; CHECK-NEXT: [[E:%.*]] = call double @llvm.canonicalize.f64(double [[X:%.*]])
1279+
; CHECK-NEXT: [[R:%.*]] = fcmp une double [[E]], 0x7FF0000000000000
1280+
; CHECK-NEXT: ret i1 [[R]]
1281+
;
1282+
%e = call double @llvm.canonicalize.f64(double %x)
1283+
%r = fcmp une double %e, 0x7ff0000000000000
1284+
ret i1 %r
1285+
}

0 commit comments

Comments
 (0)