[llvm] Reapply "[WebAssembly] Constant fold wasm.dot" (PR #153070)

Thomas Lively via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 14 16:26:02 PDT 2025


================
@@ -3826,6 +3827,30 @@ static Constant *ConstantFoldFixedVectorCall(
     }
     return ConstantVector::get(Result);
   }
+  case Intrinsic::wasm_dot: {
+    unsigned NumElements =
+        cast<FixedVectorType>(Operands[0]->getType())->getNumElements();
+
+    assert(NumElements == 8 && Result.size() == 4 &&
+           "wasm dot takes i16x8 and produces i32x4");
+    assert(Ty->isIntegerTy());
+    int32_t MulVector[8];
+
+    for (unsigned I = 0; I < NumElements; ++I) {
+      ConstantInt *Elt0 =
+          cast<ConstantInt>(Operands[0]->getAggregateElement(I));
+      ConstantInt *Elt1 =
+          cast<ConstantInt>(Operands[1]->getAggregateElement(I));
+
+      MulVector[I] = Elt0->getSExtValue() * Elt1->getSExtValue();
+    }
+    for (unsigned I = 0; I < Result.size(); I++) {
+      int64_t IAdd = (int64_t)MulVector[I * 2] + MulVector[I * 2 + 1];
----------------
tlively wrote:

I think this would be slightly more obvious if both multiplicands were cast to `int64_t`, even if it's not strictly necessary.

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


More information about the llvm-commits mailing list