@@ -1909,6 +1909,8 @@ SDValue DAGCombiner::visit(SDNode *N) {
1909
1909
case ISD::ZERO_EXTEND_VECTOR_INREG:
1910
1910
case ISD::ANY_EXTEND_VECTOR_INREG: return visitEXTEND_VECTOR_INREG(N);
1911
1911
case ISD::TRUNCATE: return visitTRUNCATE(N);
1912
+ case ISD::TRUNCATE_SSAT_U:
1913
+ case ISD::TRUNCATE_USAT_U: return visitTRUNCATE_USAT(N);
1912
1914
case ISD::BITCAST: return visitBITCAST(N);
1913
1915
case ISD::BUILD_PAIR: return visitBUILD_PAIR(N);
1914
1916
case ISD::FADD: return visitFADD(N);
@@ -14918,6 +14920,29 @@ SDValue DAGCombiner::visitEXTEND_VECTOR_INREG(SDNode *N) {
14918
14920
return SDValue();
14919
14921
}
14920
14922
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
+
14921
14946
/// Detect patterns of truncation with unsigned saturation:
14922
14947
///
14923
14948
/// (truncate (umin (x, unsigned_max_of_dest_type)) to dest_type).
0 commit comments