@@ -12416,7 +12416,7 @@ SDValue SITargetLowering::performRcpCombine(SDNode *N,
12416
12416
}
12417
12417
12418
12418
bool SITargetLowering::isCanonicalized(SelectionDAG &DAG, SDValue Op,
12419
- unsigned MaxDepth) const {
12419
+ bool &Trunc, unsigned MaxDepth) const {
12420
12420
unsigned Opcode = Op.getOpcode();
12421
12421
if (Opcode == ISD::FCANONICALIZE)
12422
12422
return true;
@@ -12450,7 +12450,6 @@ bool SITargetLowering::isCanonicalized(SelectionDAG &DAG, SDValue Op,
12450
12450
case ISD::FSQRT:
12451
12451
case ISD::FDIV:
12452
12452
case ISD::FREM:
12453
- case ISD::FP_ROUND:
12454
12453
case ISD::FP_EXTEND:
12455
12454
case ISD::FLDEXP:
12456
12455
case AMDGPUISD::FMUL_LEGACY:
@@ -12473,12 +12472,22 @@ bool SITargetLowering::isCanonicalized(SelectionDAG &DAG, SDValue Op,
12473
12472
case AMDGPUISD::CVT_F32_UBYTE3:
12474
12473
return true;
12475
12474
12475
+ case ISD::FP_ROUND:
12476
+ if (Op.getConstantOperandVal(1))
12477
+ Trunc = true;
12478
+ return true;
12479
+
12480
+ case ISD::FREEZE:
12481
+ // FREEZE is used as an optimization barrier; we can ignore any TRUNC in its
12482
+ // input.
12483
+ return isCanonicalized(DAG, Op.getOperand(0), MaxDepth - 1);
12484
+
12476
12485
// It can/will be lowered or combined as a bit operation.
12477
12486
// Need to check their input recursively to handle.
12478
12487
case ISD::FNEG:
12479
12488
case ISD::FABS:
12480
12489
case ISD::FCOPYSIGN:
12481
- return isCanonicalized(DAG, Op.getOperand(0), MaxDepth - 1);
12490
+ return isCanonicalized(DAG, Op.getOperand(0), Trunc, MaxDepth - 1);
12482
12491
12483
12492
case ISD::FSIN:
12484
12493
case ISD::FCOS:
@@ -12513,47 +12522,48 @@ bool SITargetLowering::isCanonicalized(SelectionDAG &DAG, SDValue Op,
12513
12522
12514
12523
// FIXME: Does this apply with clamp? It's implemented with max.
12515
12524
for (unsigned I = 0, E = Op.getNumOperands(); I != E; ++I) {
12516
- if (!isCanonicalized(DAG, Op.getOperand(I), MaxDepth - 1))
12525
+ if (!isCanonicalized(DAG, Op.getOperand(I), Trunc, MaxDepth - 1))
12517
12526
return false;
12518
12527
}
12519
12528
12520
12529
return true;
12521
12530
}
12522
12531
case ISD::SELECT: {
12523
- return isCanonicalized(DAG, Op.getOperand(1), MaxDepth - 1) &&
12524
- isCanonicalized(DAG, Op.getOperand(2), MaxDepth - 1);
12532
+ return isCanonicalized(DAG, Op.getOperand(1), Trunc, MaxDepth - 1) &&
12533
+ isCanonicalized(DAG, Op.getOperand(2), Trunc, MaxDepth - 1);
12525
12534
}
12526
12535
case ISD::BUILD_VECTOR: {
12527
12536
for (unsigned i = 0, e = Op.getNumOperands(); i != e; ++i) {
12528
12537
SDValue SrcOp = Op.getOperand(i);
12529
- if (!isCanonicalized(DAG, SrcOp, MaxDepth - 1))
12538
+ if (!isCanonicalized(DAG, SrcOp, Trunc, MaxDepth - 1))
12530
12539
return false;
12531
12540
}
12532
12541
12533
12542
return true;
12534
12543
}
12535
12544
case ISD::EXTRACT_VECTOR_ELT:
12536
12545
case ISD::EXTRACT_SUBVECTOR: {
12537
- return isCanonicalized(DAG, Op.getOperand(0), MaxDepth - 1);
12546
+ return isCanonicalized(DAG, Op.getOperand(0), Trunc, MaxDepth - 1);
12538
12547
}
12539
12548
case ISD::INSERT_VECTOR_ELT: {
12540
- return isCanonicalized(DAG, Op.getOperand(0), MaxDepth - 1) &&
12541
- isCanonicalized(DAG, Op.getOperand(1), MaxDepth - 1);
12549
+ return isCanonicalized(DAG, Op.getOperand(0), Trunc, MaxDepth - 1) &&
12550
+ isCanonicalized(DAG, Op.getOperand(1), Trunc, MaxDepth - 1);
12542
12551
}
12543
12552
case ISD::UNDEF:
12544
12553
// Could be anything.
12545
12554
return false;
12546
12555
12547
12556
case ISD::BITCAST:
12548
- return isCanonicalized(DAG, Op.getOperand(0), MaxDepth - 1);
12557
+ return isCanonicalized(DAG, Op.getOperand(0), Trunc, MaxDepth - 1);
12549
12558
case ISD::TRUNCATE: {
12550
12559
// Hack round the mess we make when legalizing extract_vector_elt
12551
12560
if (Op.getValueType() == MVT::i16) {
12552
12561
SDValue TruncSrc = Op.getOperand(0);
12553
12562
if (TruncSrc.getValueType() == MVT::i32 &&
12554
12563
TruncSrc.getOpcode() == ISD::BITCAST &&
12555
12564
TruncSrc.getOperand(0).getValueType() == MVT::v2f16) {
12556
- return isCanonicalized(DAG, TruncSrc.getOperand(0), MaxDepth - 1);
12565
+ return isCanonicalized(DAG, TruncSrc.getOperand(0), Trunc,
12566
+ MaxDepth - 1);
12557
12567
}
12558
12568
}
12559
12569
return false;
@@ -12831,7 +12841,10 @@ SDValue SITargetLowering::performFCanonicalizeCombine(
12831
12841
}
12832
12842
}
12833
12843
12834
- return isCanonicalized(DAG, N0) ? N0 : SDValue();
12844
+ bool Trunc = false;
12845
+ return isCanonicalized(DAG, N0, Trunc)
12846
+ ? Trunc ? DAG.getNode(ISD::FREEZE, SDLoc(N), VT, N0) : N0
12847
+ : SDValue();
12835
12848
}
12836
12849
12837
12850
static unsigned minMaxOpcToMin3Max3Opc(unsigned Opc) {
0 commit comments