-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[WASM] Constant fold SIMD wasm intrinsics: any/alltrue #148074
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
5
commits into
llvm:main
Choose a base branch
from
badumbatish:constant_fold_wasm_intr
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.
+145
−1
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
637e45c
Precommit test for const fold wasm intrinsics for any/all true.
badumbatish e27f5bc
Added support for constant folding of wasm anytrue/alltrue
badumbatish e8d1ff2
Fix logic error in wasm_all_true, update tests
badumbatish 06b2e11
Fix code formatting error
badumbatish 2a3f33a
Remove tail from tail call
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
127 changes: 127 additions & 0 deletions
127
llvm/test/CodeGen/WebAssembly/const_fold_simd_intrinsics.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,127 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
|
||
; RUN: opt -passes=instcombine -S < %s | FileCheck %s | ||
|
||
; Test that intrinsics wasm call are constant folded | ||
|
||
; all_non_zero: a splat that is all non_zero | ||
; not_all_non_zero: a splat that is all one, except for 0 in the first location | ||
|
||
; all_zero: a splat that is all zero | ||
; not_all_zero: a splat that is all zero, except for a non-zero in the first location | ||
|
||
target triple = "wasm32-unknown-unknown" | ||
|
||
define void @all_true_splat_not_all_non_zero(ptr %ptr) { | ||
; CHECK-LABEL: define void @all_true_splat_not_all_non_zero( | ||
; CHECK-SAME: ptr [[PTR:%.*]]) { | ||
; CHECK-NEXT: store volatile i32 0, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 0, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 0, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 0, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 0, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
%a = call i32 @llvm.wasm.alltrue(<16 x i8> <i8 0, i8 1, i8 2, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>) | ||
store volatile i32 %a, ptr %ptr | ||
|
||
%b = call i32 @llvm.wasm.alltrue(<8 x i16> <i16 0, i16 1, i16 2, i16 1, i16 1, i16 1, i16 1, i16 1>) | ||
store volatile i32 %b, ptr %ptr | ||
|
||
%c = call i32 @llvm.wasm.alltrue(<4 x i32> <i32 0, i32 1, i32 1, i32 1>) | ||
store volatile i32 %c, ptr %ptr | ||
|
||
%d = call i32 @llvm.wasm.alltrue(<2 x i64> <i64 0, i64 42>) | ||
store volatile i32 %d, ptr %ptr | ||
|
||
%e = call i32 @llvm.wasm.alltrue(<4 x i64> <i64 0, i64 1, i64 1, i64 1>) | ||
store volatile i32 %e, ptr %ptr | ||
|
||
ret void | ||
} | ||
|
||
define void @all_true_splat_all_non_zero(ptr %ptr) { | ||
; CHECK-LABEL: define void @all_true_splat_all_non_zero( | ||
; CHECK-SAME: ptr [[PTR:%.*]]) { | ||
; CHECK-NEXT: store volatile i32 1, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 1, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 1, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 1, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 1, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
%a = call i32 @llvm.wasm.alltrue(<16 x i8> <i8 1, i8 3, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>) | ||
store volatile i32 %a, ptr %ptr | ||
|
||
%b = call i32 @llvm.wasm.alltrue(<8 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>) | ||
store volatile i32 %b, ptr %ptr | ||
|
||
%c = call i32 @llvm.wasm.alltrue(<4 x i32> <i32 1, i32 1, i32 1, i32 1>) | ||
store volatile i32 %c, ptr %ptr | ||
|
||
%d = call i32 @llvm.wasm.alltrue(<2 x i64> <i64 2, i64 2>) | ||
store volatile i32 %d, ptr %ptr | ||
|
||
%e = call i32 @llvm.wasm.alltrue(<4 x i64> <i64 1, i64 2, i64 1, i64 1>) | ||
store volatile i32 %e, ptr %ptr | ||
|
||
ret void | ||
} | ||
|
||
|
||
define void @any_true_splat_all_zero(ptr %ptr) { | ||
; CHECK-LABEL: define void @any_true_splat_all_zero( | ||
; CHECK-SAME: ptr [[PTR:%.*]]) { | ||
; CHECK-NEXT: store volatile i32 0, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 0, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 0, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 0, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 0, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
%a = call i32 @llvm.wasm.anytrue(<16 x i8> <i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>) | ||
store volatile i32 %a, ptr %ptr | ||
|
||
%b = call i32 @llvm.wasm.anytrue(<8 x i16> <i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>) | ||
store volatile i32 %b, ptr %ptr | ||
|
||
%c = call i32 @llvm.wasm.anytrue(<4 x i32> <i32 0, i32 0, i32 0, i32 0>) | ||
store volatile i32 %c, ptr %ptr | ||
|
||
%d = call i32 @llvm.wasm.anytrue(<2 x i64> <i64 0, i64 0>) | ||
store volatile i32 %d, ptr %ptr | ||
|
||
%e = call i32 @llvm.wasm.anytrue(<4 x i64> <i64 0, i64 0, i64 0, i64 0>) | ||
store volatile i32 %e, ptr %ptr | ||
|
||
ret void | ||
} | ||
|
||
|
||
define void @any_true_splat_not_all_zero(ptr %ptr) { | ||
; CHECK-LABEL: define void @any_true_splat_not_all_zero( | ||
; CHECK-SAME: ptr [[PTR:%.*]]) { | ||
; CHECK-NEXT: store volatile i32 1, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 1, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 1, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 1, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: store volatile i32 1, ptr [[PTR]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
%a = call i32 @llvm.wasm.anytrue(<16 x i8> <i8 1, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>) | ||
store volatile i32 %a, ptr %ptr | ||
|
||
%b = call i32 @llvm.wasm.anytrue(<8 x i16> <i16 3, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0, i16 0>) | ||
store volatile i32 %b, ptr %ptr | ||
|
||
%c = call i32 @llvm.wasm.anytrue(<4 x i32> <i32 1, i32 0, i32 0, i32 0>) | ||
store volatile i32 %c, ptr %ptr | ||
|
||
%d = call i32 @llvm.wasm.anytrue(<2 x i64> <i64 -1, i64 0>) | ||
store volatile i32 %d, ptr %ptr | ||
|
||
%e = call i32 @llvm.wasm.anytrue(<4 x i64> <i64 2, i64 0, i64 0, i64 0>) | ||
store volatile i32 %e, ptr %ptr | ||
|
||
ret void | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test/CodeGen directory is for tests that run
llc
, because this is actually in the middle end and runningopt
this should be inllvm/test/Transforms/InstSimplify/ConstProp/WebAssembly/
I think we also only need to run instsimplify for this since we're not creating any new instructions: