@@ -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,17 @@ 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
+
12476
12480
// It can/will be lowered or combined as a bit operation.
12477
12481
// Need to check their input recursively to handle.
12478
12482
case ISD::FNEG:
12479
12483
case ISD::FABS:
12480
12484
case ISD::FCOPYSIGN:
12481
- return isCanonicalized(DAG, Op.getOperand(0), MaxDepth - 1);
12485
+ return isCanonicalized(DAG, Op.getOperand(0), Trunc, MaxDepth - 1);
12482
12486
12483
12487
case ISD::FSIN:
12484
12488
case ISD::FCOS:
@@ -12513,47 +12517,48 @@ bool SITargetLowering::isCanonicalized(SelectionDAG &DAG, SDValue Op,
12513
12517
12514
12518
// FIXME: Does this apply with clamp? It's implemented with max.
12515
12519
for (unsigned I = 0, E = Op.getNumOperands(); I != E; ++I) {
12516
- if (!isCanonicalized(DAG, Op.getOperand(I), MaxDepth - 1))
12520
+ if (!isCanonicalized(DAG, Op.getOperand(I), Trunc, MaxDepth - 1))
12517
12521
return false;
12518
12522
}
12519
12523
12520
12524
return true;
12521
12525
}
12522
12526
case ISD::SELECT: {
12523
- return isCanonicalized(DAG, Op.getOperand(1), MaxDepth - 1) &&
12524
- isCanonicalized(DAG, Op.getOperand(2), MaxDepth - 1);
12527
+ return isCanonicalized(DAG, Op.getOperand(1), Trunc, MaxDepth - 1) &&
12528
+ isCanonicalized(DAG, Op.getOperand(2), Trunc, MaxDepth - 1);
12525
12529
}
12526
12530
case ISD::BUILD_VECTOR: {
12527
12531
for (unsigned i = 0, e = Op.getNumOperands(); i != e; ++i) {
12528
12532
SDValue SrcOp = Op.getOperand(i);
12529
- if (!isCanonicalized(DAG, SrcOp, MaxDepth - 1))
12533
+ if (!isCanonicalized(DAG, SrcOp, Trunc, MaxDepth - 1))
12530
12534
return false;
12531
12535
}
12532
12536
12533
12537
return true;
12534
12538
}
12535
12539
case ISD::EXTRACT_VECTOR_ELT:
12536
12540
case ISD::EXTRACT_SUBVECTOR: {
12537
- return isCanonicalized(DAG, Op.getOperand(0), MaxDepth - 1);
12541
+ return isCanonicalized(DAG, Op.getOperand(0), Trunc, MaxDepth - 1);
12538
12542
}
12539
12543
case ISD::INSERT_VECTOR_ELT: {
12540
- return isCanonicalized(DAG, Op.getOperand(0), MaxDepth - 1) &&
12541
- isCanonicalized(DAG, Op.getOperand(1), MaxDepth - 1);
12544
+ return isCanonicalized(DAG, Op.getOperand(0), Trunc, MaxDepth - 1) &&
12545
+ isCanonicalized(DAG, Op.getOperand(1), Trunc, MaxDepth - 1);
12542
12546
}
12543
12547
case ISD::UNDEF:
12544
12548
// Could be anything.
12545
12549
return false;
12546
12550
12547
12551
case ISD::BITCAST:
12548
- return isCanonicalized(DAG, Op.getOperand(0), MaxDepth - 1);
12552
+ return isCanonicalized(DAG, Op.getOperand(0), Trunc, MaxDepth - 1);
12549
12553
case ISD::TRUNCATE: {
12550
12554
// Hack round the mess we make when legalizing extract_vector_elt
12551
12555
if (Op.getValueType() == MVT::i16) {
12552
12556
SDValue TruncSrc = Op.getOperand(0);
12553
12557
if (TruncSrc.getValueType() == MVT::i32 &&
12554
12558
TruncSrc.getOpcode() == ISD::BITCAST &&
12555
12559
TruncSrc.getOperand(0).getValueType() == MVT::v2f16) {
12556
- return isCanonicalized(DAG, TruncSrc.getOperand(0), MaxDepth - 1);
12560
+ return isCanonicalized(DAG, TruncSrc.getOperand(0), Trunc,
12561
+ MaxDepth - 1);
12557
12562
}
12558
12563
}
12559
12564
return false;
@@ -12831,7 +12836,10 @@ SDValue SITargetLowering::performFCanonicalizeCombine(
12831
12836
}
12832
12837
}
12833
12838
12834
- return isCanonicalized(DAG, N0) ? N0 : SDValue();
12839
+ bool Trunc = false;
12840
+ return isCanonicalized(DAG, N0, Trunc)
12841
+ ? Trunc ? DAG.getNode(ISD::FREEZE, SDLoc(N), VT, N0) : N0
12842
+ : SDValue();
12835
12843
}
12836
12844
12837
12845
static unsigned minMaxOpcToMin3Max3Opc(unsigned Opc) {
0 commit comments