[llvm] [DAG] Support saturated truncate (PR #99418)

David Green via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 5 07:29:56 PDT 2024


================
@@ -14915,6 +14920,180 @@ SDValue DAGCombiner::visitEXTEND_VECTOR_INREG(SDNode *N) {
   return SDValue();
 }
 
+SDValue DAGCombiner::visitTRUNCATE_USAT(SDNode *N) {
+  EVT VT = N->getValueType(0);
+  SDValue N0 = N->getOperand(0);
+
+  std::function<SDValue(SDValue)> MatchFPTOINT = [&](SDValue Val) -> SDValue {
----------------
davemgreen wrote:

This looks like it would match `trunc_usat_u(fptosi)`, `trunc_usat_u(fptoui)`, `trunc_usat_s(fptosi)` and `trunc_usat_s(fptoui)`, converting them all to `fptoui_sat`. I think `trunc_usat_u(fptoui)` should be enough and the others might clamp to the wrong range.

https://github.com/llvm/llvm-project/pull/99418


More information about the llvm-commits mailing list