[llvm] [RISCV] Fold (vXi8 (trunc (vselect (setltu, X, 256), X, (sext (setgt X, 0))))) to vmax+vnclipu. (PR #94720)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 07:45:15 PDT 2024


================
@@ -13370,6 +13371,76 @@ static SDValue combineDeMorganOfBoolean(SDNode *N, SelectionDAG &DAG) {
   return DAG.getNode(ISD::XOR, DL, VT, Logic, DAG.getConstant(1, DL, VT));
 }
 
+// Fold (vXi8 (trunc (vselect (setltu, X, 256), X, (sext (setgt X, 0))))) to
----------------
preames wrote:

An alternate, or possible generalization, would be to fold the trunc through the select as:
(vselect (setltu, X, 256), (trunc X), (sext (setgt X, 0)))) -- the second trunc folds into the sext to a narrower type.

We could also see the source expressed that way, so we probably want to canonicalize one to the other at least.

If we have (vselect (X > 0), 255, 0) - and variants - do we reliably combine that into the sext of condition form?

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


More information about the llvm-commits mailing list