[llvm] [WebAssembly] Add fold support for dot (PR #151775)

Sam Parker via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 6 02:48:52 PDT 2025


================
@@ -3436,6 +3439,53 @@ static SDValue performSETCCCombine(SDNode *N,
   return SDValue();
 }
 
+static SDValue performAddCombine(SDNode *N, SelectionDAG &DAG) {
+  assert(N->getOpcode() == ISD::ADD);
+  EVT VT = N->getValueType(0);
+  SDValue N0 = N->getOperand(0), N1 = N->getOperand(1);
+
+  if (VT != MVT::v4i32)
+    return SDValue();
+
+  auto IsShuffleWithMask = [](SDValue V, ArrayRef<int> ShuffleValue) {
+    if (V.getOpcode() != ISD::VECTOR_SHUFFLE)
+      return SDValue();
+    if (cast<ShuffleVectorSDNode>(V)->getMask() != ShuffleValue)
+      return SDValue();
+    return V;
+  };
+  auto ShuffleA = IsShuffleWithMask(N0, {0, 2, 4, 6});
+  auto ShuffleB = IsShuffleWithMask(N1, {1, 3, 5, 7});
+  // two SDValues must be muls
----------------
sparker-arm wrote:

Yes, another test where the shuffles are reordered would be good. It will test us if they are then canonicalised into the form you're expecting (I'm hoping this is true too).

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


More information about the llvm-commits mailing list