Skip to content

Commit 46bc54f

Browse files
authored
[ValueTracking] Fix assertion failure when computeKnownFPClass returns fcNone (#92355)
Fixes #92084 (comment).
1 parent a960573 commit 46bc54f

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,10 @@ static void computeKnownBitsFromOperator(const Operator *I,
11261126
KnownFPClass Result = computeKnownFPClass(V, fcAllFlags, Depth + 1, Q);
11271127
FPClassTest FPClasses = Result.KnownFPClasses;
11281128

1129+
// TODO: Treat it as zero/poison if the use of I is unreachable.
1130+
if (FPClasses == fcNone)
1131+
break;
1132+
11291133
if (Result.isKnownNever(fcNormal | fcSubnormal | fcNan)) {
11301134
Known.Zero.setAllBits();
11311135
Known.One.setAllBits();

llvm/test/Transforms/InstCombine/known-bits.ll

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,5 +1658,45 @@ define i32 @test_qnan_only(float nofpclass(snan sub norm zero inf) %x) {
16581658
ret i32 %and
16591659
}
16601660

1661+
; Make sure that we don't crash when the use of x is unreachable.
1662+
define i64 @pr92084(double %x) {
1663+
; CHECK-LABEL: @pr92084(
1664+
; CHECK-NEXT: [[CMP:%.*]] = fcmp uno double [[X:%.*]], 0.000000e+00
1665+
; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN1:%.*]], label [[IF_ELSE:%.*]]
1666+
; CHECK: if.then1:
1667+
; CHECK-NEXT: br i1 [[CMP]], label [[IF_ELSE]], label [[IF_THEN2:%.*]]
1668+
; CHECK: if.then2:
1669+
; CHECK-NEXT: [[CAST:%.*]] = bitcast double [[X]] to i64
1670+
; CHECK-NEXT: [[AND:%.*]] = and i64 [[CAST]], 1
1671+
; CHECK-NEXT: ret i64 [[AND]]
1672+
; CHECK: if.else:
1673+
; CHECK-NEXT: ret i64 0
1674+
;
1675+
%cmp = fcmp uno double %x, 0.000000e+00
1676+
br i1 %cmp, label %if.then1, label %if.else
1677+
1678+
if.then1:
1679+
br i1 %cmp, label %if.else, label %if.then2
1680+
1681+
if.then2:
1682+
%cast = bitcast double %x to i64
1683+
%and = and i64 %cast, 1
1684+
ret i64 %and
1685+
1686+
if.else:
1687+
ret i64 0
1688+
}
1689+
1690+
define i32 @test_none(float nofpclass(all) %x) {
1691+
; CHECK-LABEL: @test_none(
1692+
; CHECK-NEXT: [[Y:%.*]] = bitcast float [[X:%.*]] to i32
1693+
; CHECK-NEXT: [[AND:%.*]] = and i32 [[Y]], 4194304
1694+
; CHECK-NEXT: ret i32 [[AND]]
1695+
;
1696+
%y = bitcast float %x to i32
1697+
%and = and i32 %y, 4194304
1698+
ret i32 %and
1699+
}
1700+
16611701
declare void @use(i1)
16621702
declare void @sink(i8)

0 commit comments

Comments
 (0)