[llvm] [RISCV] Merge shuffle sources if lanes are disjoint (PR #119401)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 10 08:24:51 PST 2024


================
@@ -5540,6 +5601,16 @@ static SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG,
     ShuffleMaskRHS.push_back(IsLHSOrUndefIndex ? -1 : (MaskIndex - NumElts));
   }
 
+  // If the mask indices are disjoint between the two sources, we can lower it
+  // as a vselect + a single source vrgather.vv. Don't do this if the operands
+  // will be splatted since they will be lowered to something cheaper like
+  // vrgather.vi anyway.
+  if (!DAG.isSplatValue(V2) && !DAG.isSplatValue(V1) &&
----------------
preames wrote:

A couple comments here:
1) The other case you probably want to guard against is when either side is an identity shuffle because then the existing lowering produces a masked vrgather at worst.
2) The distinction between your code (which checks LHS and RHS masks) and the swap code just below is interesting.  The two should probably be in sync.  However, looking at your test diffs, I'm not sure the isSplatMask is actually a good idea here.

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


More information about the llvm-commits mailing list