[llvm] [DAGCombiner] Fold vector subtraction if above threshold to `umin` (PR #148834)

Piotr Fusik via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 15 05:13:51 PDT 2025


================
@@ -4093,6 +4093,26 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
       return N0;
   }
 
+  // (sub x, ([v]select (ult x, y), 0, y)) -> (umin x, (sub x, y))
+  // (sub x, ([v]select (uge x, y), y, 0)) -> (umin x, (sub x, y))
+  if (N1.hasOneUse() && hasUMin(VT)) {
----------------
pfusik wrote:

Unfortunately, fixed vectors are not matched on RISC-V.
`TLI.isOperationLegal(ISD::UMIN, LK.second)` in `hasUMin` yields `false` because [operation action is Custom](https://github.com/llvm/llvm-project/blob/8a7a64873b13e6fd931b748fbf50b3da26fe7fca/llvm/lib/Target/RISCV/RISCVISelLowering.cpp#L1359).

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


More information about the llvm-commits mailing list