[llvm] [WebAssembly] Constant fold wasm.dot (PR #149619)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 28 09:06:56 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
----------------
lukel97 wrote:
I would just leave out the comment if the spec doesn't mention anything about truncation. No need to worry about it if the spec doesn't!
https://github.com/llvm/llvm-project/pull/149619
More information about the llvm-commits
mailing list