-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[WebAssembly] Constant fold wasm.dot #149619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
badumbatish
wants to merge
6
commits into
llvm:main
Choose a base branch
from
badumbatish:wasm_fold_dot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5563f46
[WebAssembly] Precommit test for constant folding dot
badumbatish 50ca839
[WebAssembly] Constant fold dot operation
badumbatish 3287cd6
Merge branch 'main' into wasm_fold_dot
badumbatish fa8c096
Addresses specs questions and added test to reflect
badumbatish 10d7dc9
Addresses nit, added negative test case
badumbatish 0271d8d
Address nits and performance issues
badumbatish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
llvm/test/Transforms/InstSimplify/ConstProp/WebAssembly/dot.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
|
||
; RUN: opt -passes=instsimplify -S < %s | FileCheck %s | ||
|
||
; Test that intrinsics wasm dot call are constant folded | ||
|
||
target triple = "wasm32-unknown-unknown" | ||
|
||
|
||
define <4 x i32> @dot_zero() { | ||
; CHECK-LABEL: define <4 x i32> @dot_zero() { | ||
; CHECK-NEXT: ret <4 x i32> zeroinitializer | ||
; | ||
%res = tail call <4 x i32> @llvm.wasm.dot(<8 x i16> zeroinitializer, <8 x i16> zeroinitializer) | ||
ret <4 x i32> %res | ||
} | ||
|
||
; a = 1 2 3 4 5 6 7 8 | ||
; b = 1 2 3 4 5 6 7 8 | ||
; k1|k2 = a * b = 1 4 9 16 25 36 49 64 | ||
; k1 + k2 = (1+4) | (9 + 16) | (25 + 36) | (49 + 64) | ||
; result = 5 | 25 | 61 | 113 | ||
define <4 x i32> @dot_nonzero() { | ||
; CHECK-LABEL: define <4 x i32> @dot_nonzero() { | ||
; CHECK-NEXT: ret <4 x i32> <i32 5, i32 25, i32 61, i32 113> | ||
; | ||
%res = tail call <4 x i32> @llvm.wasm.dot(<8 x i16> <i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8>, <8 x i16> <i16 1, i16 2, i16 3, i16 4, i16 5, i16 6, i16 7, i16 8>) | ||
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) | ||
; | ||
%res = tail call <4 x i32> @llvm.wasm.dot(<8 x i16> <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>, <8 x i16> <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>) | ||
ret <4 x i32> %res | ||
} | ||
|
||
; This test checks for llvm's compliance on spec's wasm.dot's imul and iadd | ||
; Since the original number can only be i16::max == 2^15 - 1, | ||
; subsequent modulo of 2^32 of imul and iadd | ||
; should return the same result | ||
; 2*(2^15 - 1)^2 % 2^32 == 2*(2^15 - 1)^2 | ||
define <4 x i32> @dot_follow_modulo_spec_1() { | ||
; CHECK-LABEL: define <4 x i32> @dot_follow_modulo_spec_1() { | ||
; CHECK-NEXT: ret <4 x i32> <i32 2147352578, i32 0, i32 0, i32 0> | ||
; | ||
%res = tail call <4 x i32> @llvm.wasm.dot(<8 x i16> <i16 32767, i16 32767, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>, <8 x i16> <i16 32767, i16 32767, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>) | ||
ret <4 x i32> %res | ||
} | ||
|
||
; This test checks for llvm's compliance on spec's wasm.dot's imul and iadd | ||
; 2*(- 2^15)^2 == 2^31, doesn't exceed 2^32 so we don't have to mod | ||
; wrapping around is -(2^31), still doesn't exceed 2^32 | ||
define <4 x i32> @dot_follow_modulo_spec_2() { | ||
; CHECK-LABEL: define <4 x i32> @dot_follow_modulo_spec_2() { | ||
; CHECK-NEXT: ret <4 x i32> <i32 -2147483648, i32 0, i32 0, i32 0> | ||
; | ||
%res = tail call <4 x i32> @llvm.wasm.dot(<8 x i16> <i16 -32768, i16 -32768, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>, <8 x i16> <i16 -32768, i16 -32768, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>) | ||
ret <4 x i32> %res | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.