@@ -5413,18 +5413,21 @@ verifyReturnAddressArgumentIsConstant(SDValue Op, SelectionDAG &DAG) const {
5413
5413
5414
5414
char TargetLowering::isNegatibleForFree (SDValue Op, SelectionDAG &DAG,
5415
5415
bool LegalOperations, bool ForCodeSize,
5416
+ bool EnableUseCheck,
5416
5417
unsigned Depth) const {
5417
5418
// fneg is removable even if it has multiple uses.
5418
5419
if (Op.getOpcode () == ISD::FNEG)
5419
5420
return 2 ;
5420
5421
5421
- // Don't allow anything with multiple uses unless we know it is free.
5422
+ // If the caller requires checking uses, don't allow anything with multiple
5423
+ // uses unless we know it is free.
5422
5424
EVT VT = Op.getValueType ();
5423
5425
const SDNodeFlags Flags = Op->getFlags ();
5424
5426
const TargetOptions &Options = DAG.getTarget ().Options ;
5425
- if (!Op.hasOneUse () && !(Op.getOpcode () == ISD::FP_EXTEND &&
5426
- isFPExtFree (VT, Op.getOperand (0 ).getValueType ())))
5427
- return 0 ;
5427
+ if (EnableUseCheck)
5428
+ if (!Op.hasOneUse () && !(Op.getOpcode () == ISD::FP_EXTEND &&
5429
+ isFPExtFree (VT, Op.getOperand (0 ).getValueType ())))
5430
+ return 0 ;
5428
5431
5429
5432
// Don't recurse exponentially.
5430
5433
if (Depth > SelectionDAG::MaxRecursionDepth)
@@ -5468,11 +5471,11 @@ char TargetLowering::isNegatibleForFree(SDValue Op, SelectionDAG &DAG,
5468
5471
5469
5472
// fold (fneg (fadd A, B)) -> (fsub (fneg A), B)
5470
5473
if (char V = isNegatibleForFree (Op.getOperand (0 ), DAG, LegalOperations,
5471
- ForCodeSize, Depth + 1 ))
5474
+ ForCodeSize, EnableUseCheck, Depth + 1 ))
5472
5475
return V;
5473
5476
// fold (fneg (fadd A, B)) -> (fsub (fneg B), A)
5474
5477
return isNegatibleForFree (Op.getOperand (1 ), DAG, LegalOperations,
5475
- ForCodeSize, Depth + 1 );
5478
+ ForCodeSize, EnableUseCheck, Depth + 1 );
5476
5479
case ISD::FSUB:
5477
5480
// We can't turn -(A-B) into B-A when we honor signed zeros.
5478
5481
if (!Options.NoSignedZerosFPMath && !Flags.hasNoSignedZeros ())
@@ -5485,7 +5488,7 @@ char TargetLowering::isNegatibleForFree(SDValue Op, SelectionDAG &DAG,
5485
5488
case ISD::FDIV:
5486
5489
// fold (fneg (fmul X, Y)) -> (fmul (fneg X), Y) or (fmul X, (fneg Y))
5487
5490
if (char V = isNegatibleForFree (Op.getOperand (0 ), DAG, LegalOperations,
5488
- ForCodeSize, Depth + 1 ))
5491
+ ForCodeSize, EnableUseCheck, Depth + 1 ))
5489
5492
return V;
5490
5493
5491
5494
// Ignore X * 2.0 because that is expected to be canonicalized to X + X.
@@ -5494,7 +5497,7 @@ char TargetLowering::isNegatibleForFree(SDValue Op, SelectionDAG &DAG,
5494
5497
return 0 ;
5495
5498
5496
5499
return isNegatibleForFree (Op.getOperand (1 ), DAG, LegalOperations,
5497
- ForCodeSize, Depth + 1 );
5500
+ ForCodeSize, EnableUseCheck, Depth + 1 );
5498
5501
5499
5502
case ISD::FMA:
5500
5503
case ISD::FMAD: {
@@ -5504,15 +5507,15 @@ char TargetLowering::isNegatibleForFree(SDValue Op, SelectionDAG &DAG,
5504
5507
// fold (fneg (fma X, Y, Z)) -> (fma (fneg X), Y, (fneg Z))
5505
5508
// fold (fneg (fma X, Y, Z)) -> (fma X, (fneg Y), (fneg Z))
5506
5509
char V2 = isNegatibleForFree (Op.getOperand (2 ), DAG, LegalOperations,
5507
- ForCodeSize, Depth + 1 );
5510
+ ForCodeSize, EnableUseCheck, Depth + 1 );
5508
5511
if (!V2)
5509
5512
return 0 ;
5510
5513
5511
5514
// One of Op0/Op1 must be cheaply negatible, then select the cheapest.
5512
5515
char V0 = isNegatibleForFree (Op.getOperand (0 ), DAG, LegalOperations,
5513
- ForCodeSize, Depth + 1 );
5516
+ ForCodeSize, EnableUseCheck, Depth + 1 );
5514
5517
char V1 = isNegatibleForFree (Op.getOperand (1 ), DAG, LegalOperations,
5515
- ForCodeSize, Depth + 1 );
5518
+ ForCodeSize, EnableUseCheck, Depth + 1 );
5516
5519
char V01 = std::max (V0, V1);
5517
5520
return V01 ? std::max (V01, V2) : 0 ;
5518
5521
}
@@ -5521,7 +5524,7 @@ char TargetLowering::isNegatibleForFree(SDValue Op, SelectionDAG &DAG,
5521
5524
case ISD::FP_ROUND:
5522
5525
case ISD::FSIN:
5523
5526
return isNegatibleForFree (Op.getOperand (0 ), DAG, LegalOperations,
5524
- ForCodeSize, Depth + 1 );
5527
+ ForCodeSize, EnableUseCheck, Depth + 1 );
5525
5528
}
5526
5529
5527
5530
return 0 ;
@@ -5565,7 +5568,7 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
5565
5568
5566
5569
// fold (fneg (fadd A, B)) -> (fsub (fneg A), B)
5567
5570
if (isNegatibleForFree (Op.getOperand (0 ), DAG, LegalOperations, ForCodeSize,
5568
- Depth + 1 ))
5571
+ false , Depth + 1 ))
5569
5572
return DAG.getNode (ISD::FSUB, SDLoc (Op), Op.getValueType (),
5570
5573
getNegatedExpression (Op.getOperand (0 ), DAG,
5571
5574
LegalOperations, ForCodeSize,
@@ -5592,7 +5595,7 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
5592
5595
case ISD::FDIV:
5593
5596
// fold (fneg (fmul X, Y)) -> (fmul (fneg X), Y)
5594
5597
if (isNegatibleForFree (Op.getOperand (0 ), DAG, LegalOperations, ForCodeSize,
5595
- Depth + 1 ))
5598
+ false , Depth + 1 ))
5596
5599
return DAG.getNode (Op.getOpcode (), SDLoc (Op), Op.getValueType (),
5597
5600
getNegatedExpression (Op.getOperand (0 ), DAG,
5598
5601
LegalOperations, ForCodeSize,
@@ -5616,9 +5619,9 @@ SDValue TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
5616
5619
ForCodeSize, Depth + 1 );
5617
5620
5618
5621
char V0 = isNegatibleForFree (Op.getOperand (0 ), DAG, LegalOperations,
5619
- ForCodeSize, Depth + 1 );
5622
+ ForCodeSize, false , Depth + 1 );
5620
5623
char V1 = isNegatibleForFree (Op.getOperand (1 ), DAG, LegalOperations,
5621
- ForCodeSize, Depth + 1 );
5624
+ ForCodeSize, false , Depth + 1 );
5622
5625
if (V0 >= V1) {
5623
5626
// fold (fneg (fma X, Y, Z)) -> (fma (fneg X), Y, (fneg Z))
5624
5627
SDValue Neg0 = getNegatedExpression (
0 commit comments