Skip to content

Commit 7e67747

Browse files
committed
[DAG] Combine trunc[us]_u(fptoui(x)) to fptoui_sat(x)
1 parent 8d81896 commit 7e67747

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,8 @@ SDValue DAGCombiner::visit(SDNode *N) {
19091909
case ISD::ZERO_EXTEND_VECTOR_INREG:
19101910
case ISD::ANY_EXTEND_VECTOR_INREG: return visitEXTEND_VECTOR_INREG(N);
19111911
case ISD::TRUNCATE: return visitTRUNCATE(N);
1912+
case ISD::TRUNCATE_SSAT_U:
1913+
case ISD::TRUNCATE_USAT_U: return visitTRUNCATE_USAT(N);
19121914
case ISD::BITCAST: return visitBITCAST(N);
19131915
case ISD::BUILD_PAIR: return visitBUILD_PAIR(N);
19141916
case ISD::FADD: return visitFADD(N);
@@ -14918,6 +14920,29 @@ SDValue DAGCombiner::visitEXTEND_VECTOR_INREG(SDNode *N) {
1491814920
return SDValue();
1491914921
}
1492014922

14923+
SDValue DAGCombiner::visitTRUNCATE_USAT(SDNode *N) {
14924+
EVT VT = N->getValueType(0);
14925+
SDValue N0 = N->getOperand(0);
14926+
14927+
std::function<SDValue(SDValue)> MatchFPTOINT = [&](SDValue Val) -> SDValue {
14928+
if (Val.getOpcode() == ISD::FP_TO_UINT)
14929+
return Val;
14930+
return SDValue();
14931+
};
14932+
14933+
SDValue FPInstr = MatchFPTOINT(N0);
14934+
if (!FPInstr)
14935+
return SDValue();
14936+
14937+
EVT FPVT = FPInstr.getOperand(0).getValueType();
14938+
if (!DAG.getTargetLoweringInfo().shouldConvertFpToSat(ISD::FP_TO_UINT_SAT,
14939+
FPVT, VT))
14940+
return SDValue();
14941+
return DAG.getNode(ISD::FP_TO_UINT_SAT, SDLoc(FPInstr), VT,
14942+
FPInstr.getOperand(0),
14943+
DAG.getValueType(VT.getScalarType()));
14944+
}
14945+
1492114946
/// Detect patterns of truncation with unsigned saturation:
1492214947
///
1492314948
/// (truncate (umin (x, unsigned_max_of_dest_type)) to dest_type).

0 commit comments

Comments
 (0)