[llvm] [WebAssembly] Constant fold wasm.dot (PR #149619)

Jasmine Tang via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 08:38:21 PDT 2025


================
@@ -3826,6 +3827,35 @@ static Constant *ConstantFoldFixedVectorCall(
     }
     return ConstantVector::get(Result);
   }
+  case Intrinsic::wasm_dot: {
+    unsigned NumElements =
+        cast<FixedVectorType>(Operands[0]->getType())->getNumElements();
+
+    assert(NumElements == 8 && NumElements / 2 == Result.size() &&
+           "wasm dot takes i16x8 and produce i32x4");
+    assert(Ty->isIntegerTy());
+    SmallVector<APInt, 8> MulVector;
+
+    for (unsigned I = 0; I < NumElements; ++I) {
+      ConstantInt *Elt0 =
+          cast<ConstantInt>(Operands[0]->getAggregateElement(I));
+      ConstantInt *Elt1 =
+          cast<ConstantInt>(Operands[1]->getAggregateElement(I));
+
+      // sext 32 first, according to specs
+      APInt IMul = Elt0->getValue().sext(32) * Elt1->getValue().sext(32);
+
+      // i16 -> i32 bypasses specs modulo on imul
----------------
badumbatish wrote:

the specs doesn't mention explicitly but it does mention modulo in iadd and imul, I think i'll still remove the comments for this

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


More information about the llvm-commits mailing list