Skip to content

Commit fa98fcd

Browse files
authored
DAG: Handle AssertNoFPClass in computeKnownBits (#167289)
It's possible to determine the sign bit if the value is known one of the positive/negative classes and not-nan.
1 parent a3d00e1 commit fa98fcd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4149,6 +4149,25 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
41494149
Known.One.clearLowBits(LogOfAlign);
41504150
break;
41514151
}
4152+
case ISD::AssertNoFPClass: {
4153+
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
4154+
4155+
FPClassTest NoFPClass =
4156+
static_cast<FPClassTest>(Op.getConstantOperandVal(1));
4157+
const FPClassTest NegativeTestMask = fcNan | fcNegative;
4158+
if ((NoFPClass & NegativeTestMask) == NegativeTestMask) {
4159+
// Cannot be negative.
4160+
Known.makeNonNegative();
4161+
}
4162+
4163+
const FPClassTest PositiveTestMask = fcNan | fcPositive;
4164+
if ((NoFPClass & PositiveTestMask) == PositiveTestMask) {
4165+
// Cannot be positive.
4166+
Known.makeNegative();
4167+
}
4168+
4169+
break;
4170+
}
41524171
case ISD::FGETSIGN:
41534172
// All bits are zero except the low bit.
41544173
Known.Zero.setBitsFrom(1);

llvm/test/CodeGen/AMDGPU/compute-known-bits-nofpclass.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ define i32 @known_positive(float nofpclass(nan ninf nzero nsub nnorm) %signbit.z
55
; CHECK-LABEL: known_positive:
66
; CHECK: ; %bb.0:
77
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
8-
; CHECK-NEXT: v_and_b32_e32 v0, 0x7fffffff, v0
98
; CHECK-NEXT: s_setpc_b64 s[30:31]
109
%cast = bitcast float %signbit.zero to i32
1110
%and = and i32 %cast, 2147483647
@@ -27,7 +26,6 @@ define i32 @known_negative(float nofpclass(nan pinf pzero psub pnorm) %signbit.o
2726
; CHECK-LABEL: known_negative:
2827
; CHECK: ; %bb.0:
2928
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
30-
; CHECK-NEXT: v_or_b32_e32 v0, 0x80000000, v0
3129
; CHECK-NEXT: s_setpc_b64 s[30:31]
3230
%cast = bitcast float %signbit.one to i32
3331
%or = or i32 %cast, -2147483648

0 commit comments

Comments
 (0)