[llvm] [RISCV] Fold vector shift of sext/zext to widening multiply (PR #121563)

Piotr Fusik via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 09:28:01 PST 2025


================
@@ -17341,6 +17341,78 @@ static SDValue combineScalarCTPOPToVCPOP(SDNode *N, SelectionDAG &DAG,
   return DAG.getZExtOrTrunc(Pop, DL, VT);
 }
 
+static SDValue combineSHL(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
+                          const RISCVSubtarget &Subtarget) {
+  if (DCI.isBeforeLegalize())
+    return SDValue();
+
+  // (shl (zext x), y) -> (vwsll   x, y)
+  if (SDValue V = combineOp_VLToVWOp_VL(N, DCI, Subtarget))
+    return V;
+
+  // (shl (sext x), C) -> (vwmulsu x, 1u << C)
+  // (shl (zext x), C) -> (vwmulu  x, 1u << C)
+
+  SDValue LHS = N->getOperand(0);
+  if (!LHS.hasOneUse())
+    return SDValue();
+  unsigned Opcode;
+  switch (LHS.getOpcode()) {
+  case ISD::SIGN_EXTEND:
----------------
pfusik wrote:

We probably should, as [other widening optimizations do](https://github.com/llvm/llvm-project/blob/56c5a6ba836065a6e3be9d04e2c64aa8a758a3f4/llvm/lib/Target/RISCV/RISCVISelLowering.cpp#L14917).
There's no `rvv` test covering this, so I'd need to add one.
How to handle the mask and EVL values? Can this be an operand of `ISD::SHL` or `RISCVISD::SHL_VL` or both?

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


More information about the llvm-commits mailing list