[llvm] [RISCV] Support (truncate (smin (smax X, C1), C2)) for vnclipu in combineTruncToVnclip. (PR #93756)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu May 30 04:47:12 PDT 2024


================
@@ -16230,17 +16230,35 @@ static SDValue combineTruncToVnclip(SDNode *N, SelectionDAG &DAG,
     return SDValue();
   };
 
+  SDLoc DL(N);
+
   auto DetectUSatPattern = [&](SDValue V) {
-    // Src must be a UMIN or UMIN_VL.
-    APInt C;
-    SDValue UMin = MatchMinMax(V, ISD::UMIN, RISCVISD::UMIN_VL, C);
-    if (!UMin)
-      return SDValue();
+    APInt LoC, HiC;
+
+    // Simple case, V is a UMIN.
+    if (SDValue UMin = MatchMinMax(V, ISD::UMIN, RISCVISD::UMIN_VL, HiC))
+      if (HiC.isMask(VT.getScalarSizeInBits()))
+        return UMin;
+
+    // If we have an SMAX that removes negative numbers first, then we can match
+    // SMIN instead of UMIN.
+    if (SDValue SMin = MatchMinMax(V, ISD::SMIN, RISCVISD::SMIN_VL, HiC))
+      if (SDValue SMax = MatchMinMax(SMin, ISD::SMAX, RISCVISD::SMAX_VL, LoC))
+        if (LoC.isNonNegative() && HiC.isMask(VT.getScalarSizeInBits()))
+          return SMin;
----------------
lukel97 wrote:

Just to double check, SMin is the ISD::SMAX and SMax is the input? This is a nit but would it be clearer to rename it something more like SMinOp and SMaxOp

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


More information about the llvm-commits mailing list