@@ -2385,32 +2385,26 @@ SDValue DAGTypeLegalizer::ExpandFloatOp_LLRINT(SDNode *N) {
2385
2385
//
2386
2386
2387
2387
static ISD::NodeType GetPromotionOpcode (EVT OpVT, EVT RetVT) {
2388
- if (OpVT == MVT::f16 ) {
2388
+ if (OpVT == MVT::f16 )
2389
2389
return ISD::FP16_TO_FP;
2390
- } else if (RetVT == MVT::f16 ) {
2390
+ if (RetVT == MVT::f16 )
2391
2391
return ISD::FP_TO_FP16;
2392
- } else if (OpVT == MVT::bf16 ) {
2392
+ if (OpVT == MVT::bf16 )
2393
2393
return ISD::BF16_TO_FP;
2394
- } else if (RetVT == MVT::bf16 ) {
2394
+ if (RetVT == MVT::bf16 )
2395
2395
return ISD::FP_TO_BF16;
2396
- }
2397
-
2398
2396
report_fatal_error (" Attempt at an invalid promotion-related conversion" );
2399
2397
}
2400
2398
2401
2399
static ISD::NodeType GetPromotionOpcodeStrict (EVT OpVT, EVT RetVT) {
2402
2400
if (OpVT == MVT::f16 )
2403
2401
return ISD::STRICT_FP16_TO_FP;
2404
-
2405
2402
if (RetVT == MVT::f16 )
2406
2403
return ISD::STRICT_FP_TO_FP16;
2407
-
2408
2404
if (OpVT == MVT::bf16 )
2409
2405
return ISD::STRICT_BF16_TO_FP;
2410
-
2411
2406
if (RetVT == MVT::bf16 )
2412
2407
return ISD::STRICT_FP_TO_BF16;
2413
-
2414
2408
report_fatal_error (" Attempt at an invalid promotion-related conversion" );
2415
2409
}
2416
2410
@@ -3138,6 +3132,8 @@ void DAGTypeLegalizer::SoftPromoteHalfResult(SDNode *N, unsigned ResNo) {
3138
3132
break ;
3139
3133
case ISD::SELECT: R = SoftPromoteHalfRes_SELECT (N); break ;
3140
3134
case ISD::SELECT_CC: R = SoftPromoteHalfRes_SELECT_CC (N); break ;
3135
+ case ISD::STRICT_SINT_TO_FP:
3136
+ case ISD::STRICT_UINT_TO_FP:
3141
3137
case ISD::SINT_TO_FP:
3142
3138
case ISD::UINT_TO_FP: R = SoftPromoteHalfRes_XINT_TO_FP (N); break ;
3143
3139
case ISD::UNDEF: R = SoftPromoteHalfRes_UNDEF (N); break ;
@@ -3288,19 +3284,13 @@ SDValue DAGTypeLegalizer::SoftPromoteHalfRes_FFREXP(SDNode *N) {
3288
3284
3289
3285
SDValue DAGTypeLegalizer::SoftPromoteHalfRes_FP_ROUND (SDNode *N) {
3290
3286
EVT RVT = N->getValueType (0 );
3291
- EVT SVT = N->getOperand (0 ).getValueType ();
3287
+ bool IsStrict = N->isStrictFPOpcode ();
3288
+ SDValue Op = N->getOperand (IsStrict ? 1 : 0 );
3289
+ EVT SVT = Op.getValueType ();
3292
3290
3293
- if (N->isStrictFPOpcode ()) {
3294
- // FIXME: assume we only have two f16 variants for now.
3295
- unsigned Opcode;
3296
- if (RVT == MVT::f16 )
3297
- Opcode = ISD::STRICT_FP_TO_FP16;
3298
- else if (RVT == MVT::bf16 )
3299
- Opcode = ISD::STRICT_FP_TO_BF16;
3300
- else
3301
- llvm_unreachable (" unknown half type" );
3302
- SDValue Res = DAG.getNode (Opcode, SDLoc (N), {MVT::i16 , MVT::Other},
3303
- {N->getOperand (0 ), N->getOperand (1 )});
3291
+ if (IsStrict) {
3292
+ SDValue Res = DAG.getNode (GetPromotionOpcodeStrict (SVT, RVT), SDLoc (N),
3293
+ {MVT::i16 , MVT::Other}, {N->getOperand (0 ), Op});
3304
3294
ReplaceValueWith (SDValue (N, 1 ), Res.getValue (1 ));
3305
3295
return Res;
3306
3296
}
@@ -3359,6 +3349,16 @@ SDValue DAGTypeLegalizer::SoftPromoteHalfRes_XINT_TO_FP(SDNode *N) {
3359
3349
EVT NVT = TLI.getTypeToTransformTo (*DAG.getContext (), OVT);
3360
3350
SDLoc dl (N);
3361
3351
3352
+ if (N->isStrictFPOpcode ()) {
3353
+ SDValue Op = DAG.getNode (N->getOpcode (), dl, {NVT, MVT::Other},
3354
+ {N->getOperand (0 ), N->getOperand (1 )});
3355
+ Op = DAG.getNode (GetPromotionOpcodeStrict (NVT, OVT), dl,
3356
+ {MVT::i16 , MVT::Other}, {N->getOperand (0 ), Op});
3357
+ ReplaceValueWith (SDValue (N, 1 ), Op.getValue (1 ));
3358
+ DAG.ReplaceAllUsesOfValueWith (SDValue (N, 1 ), Op.getValue (1 ));
3359
+ return Op;
3360
+ }
3361
+
3362
3362
SDValue Res = DAG.getNode (N->getOpcode (), dl, NVT, N->getOperand (0 ));
3363
3363
3364
3364
// Round the value to the softened type.
@@ -3447,6 +3447,8 @@ bool DAGTypeLegalizer::SoftPromoteHalfOperand(SDNode *N, unsigned OpNo) {
3447
3447
Res = SoftPromoteHalfOp_FAKE_USE (N, OpNo);
3448
3448
break ;
3449
3449
case ISD::FCOPYSIGN: Res = SoftPromoteHalfOp_FCOPYSIGN (N, OpNo); break ;
3450
+ case ISD::STRICT_FP_TO_SINT:
3451
+ case ISD::STRICT_FP_TO_UINT:
3450
3452
case ISD::FP_TO_SINT:
3451
3453
case ISD::FP_TO_UINT: Res = SoftPromoteHalfOp_FP_TO_XINT (N); break ;
3452
3454
case ISD::FP_TO_SINT_SAT:
@@ -3473,7 +3475,7 @@ bool DAGTypeLegalizer::SoftPromoteHalfOperand(SDNode *N, unsigned OpNo) {
3473
3475
3474
3476
assert (Res.getNode () != N && " Expected a new node!" );
3475
3477
3476
- assert (Res.getValueType () == N->getValueType (0 ) && N-> getNumValues () == 1 &&
3478
+ assert (Res.getValueType () == N->getValueType (0 ) &&
3477
3479
" Invalid operand expansion" );
3478
3480
3479
3481
ReplaceValueWith (SDValue (N, 0 ), Res);
@@ -3517,16 +3519,8 @@ SDValue DAGTypeLegalizer::SoftPromoteHalfOp_FP_EXTEND(SDNode *N) {
3517
3519
Op = GetSoftPromotedHalf (N->getOperand (IsStrict ? 1 : 0 ));
3518
3520
3519
3521
if (IsStrict) {
3520
- unsigned Opcode;
3521
- if (SVT == MVT::f16 )
3522
- Opcode = ISD::STRICT_FP16_TO_FP;
3523
- else if (SVT == MVT::bf16 )
3524
- Opcode = ISD::STRICT_BF16_TO_FP;
3525
- else
3526
- llvm_unreachable (" unknown half type" );
3527
- SDValue Res =
3528
- DAG.getNode (Opcode, SDLoc (N), {N->getValueType (0 ), MVT::Other},
3529
- {N->getOperand (0 ), Op});
3522
+ SDValue Res = DAG.getNode (GetPromotionOpcodeStrict (SVT, RVT), SDLoc (N),
3523
+ {RVT, MVT::Other}, {N->getOperand (0 ), Op});
3530
3524
ReplaceValueWith (SDValue (N, 1 ), Res.getValue (1 ));
3531
3525
ReplaceValueWith (SDValue (N, 0 ), Res);
3532
3526
return SDValue ();
@@ -3537,17 +3531,26 @@ SDValue DAGTypeLegalizer::SoftPromoteHalfOp_FP_EXTEND(SDNode *N) {
3537
3531
3538
3532
SDValue DAGTypeLegalizer::SoftPromoteHalfOp_FP_TO_XINT (SDNode *N) {
3539
3533
EVT RVT = N->getValueType (0 );
3540
- SDValue Op = N->getOperand (0 );
3534
+ bool IsStrict = N->isStrictFPOpcode ();
3535
+ SDValue Op = N->getOperand (IsStrict ? 1 : 0 );
3541
3536
EVT SVT = Op.getValueType ();
3542
3537
SDLoc dl (N);
3543
3538
3544
- EVT NVT = TLI.getTypeToTransformTo (*DAG.getContext (), Op.getValueType ());
3545
-
3539
+ EVT NVT = TLI.getTypeToTransformTo (*DAG.getContext (), SVT);
3546
3540
Op = GetSoftPromotedHalf (Op);
3547
3541
3548
- SDValue Res = DAG.getNode (GetPromotionOpcode (SVT, RVT), dl, NVT, Op);
3542
+ if (IsStrict) {
3543
+ Op = DAG.getNode (GetPromotionOpcodeStrict (SVT, RVT), dl, {NVT, MVT::Other},
3544
+ {N->getOperand (0 ), Op});
3545
+ Op = DAG.getNode (N->getOpcode (), dl, {RVT, MVT::Other},
3546
+ {N->getOperand (0 ), Op});
3547
+ ReplaceValueWith (SDValue (N, 1 ), Op.getValue (1 ));
3548
+ DAG.ReplaceAllUsesOfValueWith (SDValue (N, 1 ), Op.getValue (1 ));
3549
+ return Op;
3550
+ }
3549
3551
3550
- return DAG.getNode (N->getOpcode (), dl, N->getValueType (0 ), Res);
3552
+ SDValue Res = DAG.getNode (GetPromotionOpcode (SVT, RVT), dl, NVT, Op);
3553
+ return DAG.getNode (N->getOpcode (), dl, RVT, Res);
3551
3554
}
3552
3555
3553
3556
SDValue DAGTypeLegalizer::SoftPromoteHalfOp_FP_TO_XINT_SAT (SDNode *N) {
0 commit comments