- Notifications
You must be signed in to change notification settings - Fork 15.2k
[DAGCombiner] Fold select into partial.reduce.add operands. #167857
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
sdesmalen-arm wants to merge 3 commits into main Choose a base branch from users/sdesmalen-arm/predicated-partial-reduce-add
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.
+245 −28
Open
Changes from all commits
Commits
Show all changes
3 commits Select commit Hold shift + click to select a range
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
159 changes: 159 additions & 0 deletions 159 llvm/test/CodeGen/AArch64/partial-reduction-add-predicated.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,159 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6 | ||
| ; RUN: llc < %s | FileCheck %s | ||
| | ||
| target triple = "aarch64" | ||
| | ||
| define <4 x i32> @predicate_dot_fixed_length(<4 x i32> %acc, <16 x i1> %p, <16 x i8> %a, <16 x i8> %b) #0 { | ||
| ; CHECK-LABEL: predicate_dot_fixed_length: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: shl v1.16b, v1.16b, #7 | ||
| ; CHECK-NEXT: cmlt v1.16b, v1.16b, #0 | ||
| ; CHECK-NEXT: and v1.16b, v1.16b, v3.16b | ||
| ; CHECK-NEXT: sdot v0.4s, v2.16b, v1.16b | ||
| ; CHECK-NEXT: ret | ||
| %ext.1 = sext <16 x i8> %a to <16 x i32> | ||
| %ext.2 = sext <16 x i8> %b to <16 x i32> | ||
| %mul = mul nsw <16 x i32> %ext.1, %ext.2 | ||
| %sel = select <16 x i1> %p, <16 x i32> %mul, <16 x i32> zeroinitializer | ||
| %red = call <4 x i32> @llvm.vector.partial.reduce.add(<4 x i32> %acc, <16 x i32> %sel) | ||
| ret <4 x i32> %red | ||
| } | ||
| | ||
| define <4 x i32> @predicate_dot_by_C_fixed_length(<4 x i32> %acc, <16 x i1> %p, <16 x i8> %a) #0 { | ||
| ; CHECK-LABEL: predicate_dot_by_C_fixed_length: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: shl v1.16b, v1.16b, #7 | ||
| ; CHECK-NEXT: movi v3.16b, #127 | ||
| ; CHECK-NEXT: cmlt v1.16b, v1.16b, #0 | ||
| ; CHECK-NEXT: and v1.16b, v1.16b, v3.16b | ||
| ; CHECK-NEXT: sdot v0.4s, v2.16b, v1.16b | ||
| ; CHECK-NEXT: ret | ||
| %ext.1 = sext <16 x i8> %a to <16 x i32> | ||
| %mul = mul nsw <16 x i32> %ext.1, splat(i32 127) | ||
| %sel = select <16 x i1> %p, <16 x i32> %mul, <16 x i32> zeroinitializer | ||
| %red = call <4 x i32> @llvm.vector.partial.reduce.add(<4 x i32> %acc, <16 x i32> %sel) | ||
| ret <4 x i32> %red | ||
| } | ||
| | ||
| define <vscale x 4 x i32> @predicate_dot_scalable(<vscale x 4 x i32> %acc, <vscale x 16 x i1> %p, <vscale x 16 x i8> %a, <vscale x 16 x i8> %b) #0 { | ||
| ; CHECK-LABEL: predicate_dot_scalable: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: movi v3.2d, #0000000000000000 | ||
| ; CHECK-NEXT: sel z2.b, p0, z2.b, z3.b | ||
| ; CHECK-NEXT: sdot z0.s, z1.b, z2.b | ||
| ; CHECK-NEXT: ret | ||
| %ext.1 = sext <vscale x 16 x i8> %a to <vscale x 16 x i32> | ||
| %ext.2 = sext <vscale x 16 x i8> %b to <vscale x 16 x i32> | ||
| %mul = mul nsw <vscale x 16 x i32> %ext.1, %ext.2 | ||
| %sel = select <vscale x 16 x i1> %p, <vscale x 16 x i32> %mul, <vscale x 16 x i32> zeroinitializer | ||
| %red = call <vscale x 4 x i32> @llvm.vector.partial.reduce.add(<vscale x 4 x i32> %acc, <vscale x 16 x i32> %sel) | ||
| ret <vscale x 4 x i32> %red | ||
| } | ||
| | ||
| define <vscale x 4 x i32> @predicate_dot_by_C_scalable(<vscale x 4 x i32> %acc, <vscale x 16 x i1> %p, <vscale x 16 x i8> %a) #0 { | ||
| ; CHECK-LABEL: predicate_dot_by_C_scalable: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: mov z2.b, p0/z, #127 // =0x7f | ||
| ; CHECK-NEXT: sdot z0.s, z1.b, z2.b | ||
| ; CHECK-NEXT: ret | ||
| %ext.1 = sext <vscale x 16 x i8> %a to <vscale x 16 x i32> | ||
| %mul = mul nsw <vscale x 16 x i32> %ext.1, splat(i32 127) | ||
| %sel = select <vscale x 16 x i1> %p, <vscale x 16 x i32> %mul, <vscale x 16 x i32> zeroinitializer | ||
| %red = call <vscale x 4 x i32> @llvm.vector.partial.reduce.add(<vscale x 4 x i32> %acc, <vscale x 16 x i32> %sel) | ||
| ret <vscale x 4 x i32> %red | ||
| } | ||
| | ||
| define <4 x i32> @predicate_ext_mul_fixed_length(<4 x i32> %acc, <16 x i1> %p, <16 x i8> %a) #0 { | ||
| ; CHECK-LABEL: predicate_ext_mul_fixed_length: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: movi v3.16b, #1 | ||
| ; CHECK-NEXT: and v1.16b, v1.16b, v3.16b | ||
| ; CHECK-NEXT: sdot v0.4s, v2.16b, v1.16b | ||
| ; CHECK-NEXT: ret | ||
| %ext = sext <16 x i8> %a to <16 x i32> | ||
| %sel = select <16 x i1> %p, <16 x i32> %ext, <16 x i32> zeroinitializer | ||
| %red = call <4 x i32> @llvm.vector.partial.reduce.add(<4 x i32> %acc, <16 x i32> %sel) | ||
| ret <4 x i32> %red | ||
| } | ||
| | ||
| define <vscale x 4 x i32> @predicate_ext_mul_scalable(<vscale x 4 x i32> %acc, <vscale x 16 x i1> %p, <vscale x 16 x i8> %a) #0 { | ||
| ; CHECK-LABEL: predicate_ext_mul_scalable: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: mov z2.b, p0/z, #1 // =0x1 | ||
| ; CHECK-NEXT: sdot z0.s, z1.b, z2.b | ||
| ; CHECK-NEXT: ret | ||
| %ext = sext <vscale x 16 x i8> %a to <vscale x 16 x i32> | ||
| %sel = select <vscale x 16 x i1> %p, <vscale x 16 x i32> %ext, <vscale x 16 x i32> zeroinitializer | ||
| %red = call <vscale x 4 x i32> @llvm.vector.partial.reduce.add(<vscale x 4 x i32> %acc, <vscale x 16 x i32> %sel) | ||
| ret <vscale x 4 x i32> %red | ||
| } | ||
| | ||
| define <4 x float> @predicated_fdot_fixed_length(<4 x float> %acc, <8 x i1> %p, <8 x half> %a, <8 x half> %b) #1 { | ||
| ; CHECK-LABEL: predicated_fdot_fixed_length: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: ushll v1.8h, v1.8b, #0 | ||
| ; CHECK-NEXT: // kill: def $q0 killed $q0 def $z0 | ||
| ; CHECK-NEXT: // kill: def $q2 killed $q2 def $z2 | ||
| ; CHECK-NEXT: shl v1.8h, v1.8h, #15 | ||
| ; CHECK-NEXT: cmlt v1.8h, v1.8h, #0 | ||
| ; CHECK-NEXT: and v1.16b, v1.16b, v3.16b | ||
| ; CHECK-NEXT: fdot z0.s, z2.h, z1.h | ||
| ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0 | ||
| ; CHECK-NEXT: ret | ||
| %ext.1 = fpext <8 x half> %a to <8 x float> | ||
| %ext.2 = fpext <8 x half> %b to <8 x float> | ||
| %mul = fmul <8 x float> %ext.1, %ext.2 | ||
| %sel = select <8 x i1> %p, <8 x float> %mul, <8 x float> zeroinitializer | ||
| %red = call <4 x float> @llvm.vector.partial.reduce.fadd(<4 x float> %acc, <8 x float> %sel) | ||
| ret <4 x float> %red | ||
| } | ||
| | ||
| define <vscale x 4 x float> @predicated_fdot_scalable(<vscale x 4 x float> %acc, <vscale x 8 x i1> %p, <vscale x 8 x half> %a, <vscale x 8 x half> %b) #1 { | ||
| ; CHECK-LABEL: predicated_fdot_scalable: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: movi v3.2d, #0000000000000000 | ||
| ; CHECK-NEXT: sel z2.h, p0, z2.h, z3.h | ||
| ; CHECK-NEXT: fdot z0.s, z1.h, z2.h | ||
| ; CHECK-NEXT: ret | ||
| %ext.1 = fpext <vscale x 8 x half> %a to <vscale x 8 x float> | ||
| %ext.2 = fpext <vscale x 8 x half> %b to <vscale x 8 x float> | ||
| %mul = fmul <vscale x 8 x float> %ext.1, %ext.2 | ||
| %sel = select <vscale x 8 x i1> %p, <vscale x 8 x float> %mul, <vscale x 8 x float> zeroinitializer | ||
| %red = call <vscale x 4 x float> @llvm.vector.partial.reduce.fadd(<vscale x 4 x float> %acc, <vscale x 8 x float> %sel) | ||
| ret <vscale x 4 x float> %red | ||
| } | ||
| | ||
| define <4 x float> @predicated_fpext_fmul_fixed_length(<4 x float> %acc, <8 x i1> %p, <8 x half> %a) #1 { | ||
| ; CHECK-LABEL: predicated_fpext_fmul_fixed_length: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: ushll v1.8h, v1.8b, #0 | ||
| ; CHECK-NEXT: movi v3.8h, #60, lsl #8 | ||
| ; CHECK-NEXT: // kill: def $q0 killed $q0 def $z0 | ||
| ; CHECK-NEXT: // kill: def $q2 killed $q2 def $z2 | ||
| ; CHECK-NEXT: shl v1.8h, v1.8h, #15 | ||
| ; CHECK-NEXT: cmlt v1.8h, v1.8h, #0 | ||
| ; CHECK-NEXT: and v1.16b, v1.16b, v3.16b | ||
| ; CHECK-NEXT: fdot z0.s, z2.h, z1.h | ||
| ; CHECK-NEXT: // kill: def $q0 killed $q0 killed $z0 | ||
| ; CHECK-NEXT: ret | ||
| %ext = fpext <8 x half> %a to <8 x float> | ||
| %sel = select <8 x i1> %p, <8 x float> %ext, <8 x float> zeroinitializer | ||
| %red = call <4 x float> @llvm.vector.partial.reduce.fadd(<4 x float> %acc, <8 x float> %sel) | ||
| ret <4 x float> %red | ||
| } | ||
| | ||
| define <vscale x 4 x float> @predicated_fpext_fmul_scalable(<vscale x 4 x float> %acc, <vscale x 8 x i1> %p, <vscale x 8 x half> %a) #1 { | ||
| ; CHECK-LABEL: predicated_fpext_fmul_scalable: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: movi v2.2d, #0000000000000000 | ||
| ; CHECK-NEXT: fmov z2.h, p0/m, #1.00000000 | ||
| ; CHECK-NEXT: fdot z0.s, z1.h, z2.h | ||
| ; CHECK-NEXT: ret | ||
| %ext = fpext <vscale x 8 x half> %a to <vscale x 8 x float> | ||
| %sel = select <vscale x 8 x i1> %p, <vscale x 8 x float> %ext, <vscale x 8 x float> zeroinitializer | ||
| %red = call <vscale x 4 x float> @llvm.vector.partial.reduce.fadd(<vscale x 4 x float> %acc, <vscale x 8 x float> %sel) | ||
| ret <vscale x 4 x float> %red | ||
| } | ||
| | ||
| attributes #0 = { nounwind "target-features"="+sve,+dotprod" } | ||
| attributes #1 = { nounwind "target-features"="+sve2p1,+dotprod" } |
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
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.
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.
Is this correct with respect to poison? Select blocks poison propagation, but we're moving b out of the select. I think we need to freeze b
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.
Good point, I've added the Freeze (if the value may be poison).