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

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 4 09:51:20 PDT 2025


================
@@ -3826,6 +3827,32 @@ 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));
+
+      APInt IMul = Elt0->getValue().sext(32) * Elt1->getValue().sext(32);
+
+      MulVector[I] = IMul.getSExtValue();
----------------
lukel97 wrote:

I think this can be 
```suggestion
      MulVector[I] Elt0->getSExtValue() * Elt1->getSExtValue();
```

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


More information about the llvm-commits mailing list