[llvm] 4996e3b - [ConstantFolding] Allow truncation when folding wasm.dot
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 9 08:15:42 PST 2026
Author: Nikita Popov
Date: 2026-01-09T17:15:31+01:00
New Revision: 4996e3be341af782b856597023c83ee3ef9b5094
URL: https://github.com/llvm/llvm-project/commit/4996e3be341af782b856597023c83ee3ef9b5094
DIFF: https://github.com/llvm/llvm-project/commit/4996e3be341af782b856597023c83ee3ef9b5094.diff
LOG: [ConstantFolding] Allow truncation when folding wasm.dot
Changes this to getSigned() to match the signedness of the calculation.
However, we still need to allow truncation because the addition
result may overflow, and the operation is specified to truncate
in that case.
Fixes https://github.com/llvm/llvm-project/issues/175159.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/InstSimplify/ConstProp/WebAssembly/dot.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index c3a3035fcaa9e..eaf4eb4454236 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -4288,7 +4288,7 @@ static Constant *ConstantFoldFixedVectorCall(
}
for (unsigned I = 0; I < Result.size(); I++) {
int64_t IAdd = (int64_t)MulVector[I * 2] + (int64_t)MulVector[I * 2 + 1];
- Result[I] = ConstantInt::get(Ty, IAdd);
+ Result[I] = ConstantInt::getSigned(Ty, IAdd, /*ImplicitTrunc=*/true);
}
return ConstantVector::get(Result);
diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/WebAssembly/dot.ll b/llvm/test/Transforms/InstSimplify/ConstProp/WebAssembly/dot.ll
index b537b7bccf861..d44437bd518af 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/WebAssembly/dot.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/WebAssembly/dot.ll
@@ -28,6 +28,14 @@ define <4 x i32> @dot_nonzero() {
ret <4 x i32> %res
}
+define <4 x i32> @dot_one_negative() {
+; CHECK-LABEL: define <4 x i32> @dot_one_negative() {
+; CHECK-NEXT: ret <4 x i32> splat (i32 -2)
+;
+ %res = tail call <4 x i32> @llvm.wasm.dot(<8 x i16> splat (i16 1), <8 x i16> splat (i16 -1))
+ ret <4 x i32> %res
+}
+
define <4 x i32> @dot_doubly_negative() {
; CHECK-LABEL: define <4 x i32> @dot_doubly_negative() {
; CHECK-NEXT: ret <4 x i32> splat (i32 2)
More information about the llvm-commits
mailing list