Skip to content

Commit 07fa1a5

Browse files
committed
DAG: Handle AssertNoFPClass in computeKnownBits
It's possible to determine the sign bit if the value is known one of the positive/negative classes and not-nan.
1 parent 741ba82 commit 07fa1a5

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4121,6 +4121,27 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
41214121
Known.One.clearLowBits(LogOfAlign);
41224122
break;
41234123
}
4124+
case ISD::AssertNoFPClass: {
4125+
Known = computeKnownBits(Op.getOperand(0), DemandedElts, Depth + 1);
4126+
4127+
FPClassTest NoFPClass =
4128+
static_cast<FPClassTest>(Op.getConstantOperandVal(1));
4129+
const FPClassTest NegativeTestMask = fcNan | fcNegative;
4130+
if ((NoFPClass & NegativeTestMask) == NegativeTestMask) {
4131+
// Cannot be negative.
4132+
Known.Zero.setSignBit();
4133+
Known.One.clearSignBit();
4134+
}
4135+
4136+
const FPClassTest PositiveTestMask = fcNan | fcPositive;
4137+
if ((NoFPClass & PositiveTestMask) == PositiveTestMask) {
4138+
// Cannot be positive.
4139+
Known.Zero.clearSignBit();
4140+
Known.One.setSignBit();
4141+
}
4142+
4143+
break;
4144+
}
41244145
case ISD::FGETSIGN:
41254146
// All bits are zero except the low bit.
41264147
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)