Skip to content

Commit 3357e28

Browse files
committed
Fix PromoteHalf support
1 parent 4cdbc89 commit 3357e28

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,7 +2639,11 @@ SDValue DAGTypeLegalizer::PromoteFloatOp_FCOPYSIGN(SDNode *N, unsigned OpNo) {
26392639
// Convert the promoted float value to the desired integer type
26402640
SDValue DAGTypeLegalizer::PromoteFloatOp_UnaryOp(SDNode *N, unsigned OpNo) {
26412641
SDValue Op = GetPromotedFloat(N->getOperand(0));
2642-
return DAG.getNode(N->getOpcode(), SDLoc(N), N->getValueType(0), Op);
2642+
if (N->getOpcode() == ISD::AssertNoFPClass)
2643+
return DAG.getNode(N->getOpcode(), SDLoc(N), N->getValueType(0), Op,
2644+
N->getOperand(1));
2645+
else
2646+
return DAG.getNode(N->getOpcode(), SDLoc(N), N->getValueType(0), Op);
26432647
}
26442648

26452649
SDValue DAGTypeLegalizer::PromoteFloatOp_FP_TO_XINT_SAT(SDNode *N,
@@ -2999,8 +3003,10 @@ SDValue DAGTypeLegalizer::PromoteFloatRes_UnaryOp(SDNode *N) {
29993003
EVT VT = N->getValueType(0);
30003004
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), VT);
30013005
SDValue Op = GetPromotedFloat(N->getOperand(0));
3002-
3003-
return DAG.getNode(N->getOpcode(), SDLoc(N), NVT, Op);
3006+
if (N->getOpcode() == ISD::AssertNoFPClass)
3007+
return DAG.getNode(N->getOpcode(), SDLoc(N), NVT, Op, N->getOperand(1));
3008+
else
3009+
return DAG.getNode(N->getOpcode(), SDLoc(N), NVT, Op);
30043010
}
30053011

30063012
// Binary operations where the result and both operands have PromoteFloat type
@@ -3245,6 +3251,8 @@ void DAGTypeLegalizer::SoftPromoteHalfResult(SDNode *N, unsigned ResNo) {
32453251
report_fatal_error("Do not know how to soft promote this operator's "
32463252
"result!");
32473253

3254+
// case ISD::AssertNoFPClass:
3255+
// break;
32483256
case ISD::ARITH_FENCE:
32493257
R = SoftPromoteHalfRes_ARITH_FENCE(N); break;
32503258
case ISD::BITCAST: R = SoftPromoteHalfRes_BITCAST(N); break;
@@ -3283,6 +3291,7 @@ void DAGTypeLegalizer::SoftPromoteHalfResult(SDNode *N, unsigned ResNo) {
32833291
case ISD::FTRUNC:
32843292
case ISD::FTAN:
32853293
case ISD::FTANH:
3294+
case ISD::AssertNoFPClass:
32863295
case ISD::FCANONICALIZE: R = SoftPromoteHalfRes_UnaryOp(N); break;
32873296

32883297
// Binary FP Operations
@@ -3604,7 +3613,11 @@ SDValue DAGTypeLegalizer::SoftPromoteHalfRes_UnaryOp(SDNode *N) {
36043613
// Promote to the larger FP type.
36053614
Op = DAG.getNode(GetPromotionOpcode(OVT, NVT), dl, NVT, Op);
36063615

3607-
SDValue Res = DAG.getNode(N->getOpcode(), dl, NVT, Op);
3616+
SDValue Res;
3617+
if (N->getOpcode() == ISD::AssertNoFPClass)
3618+
Res = DAG.getNode(N->getOpcode(), dl, NVT, Op, N->getOperand(1));
3619+
else
3620+
Res = DAG.getNode(N->getOpcode(), dl, NVT, Op);
36083621

36093622
// Convert back to FP16 as an integer.
36103623
return DAG.getNode(GetPromotionOpcode(NVT, OVT), dl, MVT::i16, Res);

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
8080
/// Pretend all of this node's results are legal.
8181
bool IgnoreNodeResults(SDNode *N) const {
8282
return N->getOpcode() == ISD::TargetConstant ||
83-
N->getOpcode() == ISD::Register;
83+
N->getOpcode() == ISD::Register ||
84+
(N->getOpcode() == ISD::AssertNoFPClass &&
85+
IgnoreNodeResults(N->getOperand(0).getNode()));
8486
}
8587

8688
// Bijection from SDValue to unique id. As each created node gets a
@@ -796,6 +798,8 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
796798
//===--------------------------------------------------------------------===//
797799

798800
SDValue GetSoftPromotedHalf(SDValue Op) {
801+
while (Op.getNode()->getOpcode() == ISD::AssertNoFPClass)
802+
Op = Op.getNode()->getOperand(0);
799803
TableId &PromotedId = SoftPromotedHalfs[getTableId(Op)];
800804
SDValue PromotedOp = getSDValue(PromotedId);
801805
assert(PromotedOp.getNode() && "Operand wasn't promoted?");

llvm/test/CodeGen/ARM/nofpclass.ll

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=armv8-unknown-none-eabi < %s | FileCheck %s
3+
4+
define nofpclass(nan inf) half @f1(half returned nofpclass(nan inf) %x) {
5+
; CHECK-LABEL: f1:
6+
; CHECK: @ %bb.0: @ %entry
7+
; CHECK-NEXT: bx lr
8+
entry:
9+
ret half %x
10+
}
11+
12+
define noundef half @f2(half nofpclass(nan) %a) {
13+
; CHECK-LABEL: f2:
14+
; CHECK: @ %bb.0: @ %entry
15+
; CHECK-NEXT: vmov.f32 s0, #1.000000e+00
16+
; CHECK-NEXT: vmov s2, r0
17+
; CHECK-NEXT: vcvtb.f32.f16 s2, s2
18+
; CHECK-NEXT: vadd.f32 s0, s2, s0
19+
; CHECK-NEXT: vcvtb.f16.f32 s0, s0
20+
; CHECK-NEXT: vmov r0, s0
21+
; CHECK-NEXT: bx lr
22+
entry:
23+
%0 = fadd half %a, 0xH3C00
24+
ret half %0
25+
}

0 commit comments

Comments
 (0)