-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[AArch64][SVE] Add basic support for @llvm.masked.compressstore
#168350
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
MacDue
wants to merge
2
commits into
llvm:main
Choose a base branch
from
MacDue:compressstore_basic_lowering
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.
+218
−11
Open
Changes from all commits
Commits
Show all changes
2 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
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
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
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 |
|---|---|---|
|
|
@@ -333,6 +333,29 @@ class AArch64TTIImpl final : public BasicTTIImplBase<AArch64TTIImpl> { | |
| return isLegalMaskedLoadStore(DataType, Alignment); | ||
| } | ||
|
|
||
| bool isElementTypeLegalForCompressStore(Type *Ty) const { | ||
| if (Ty->isFloatTy() || Ty->isDoubleTy()) | ||
| return true; | ||
|
|
||
| if (Ty->isIntegerTy(8) || Ty->isIntegerTy(16) || Ty->isIntegerTy(32) || | ||
| Ty->isIntegerTy(64)) | ||
| return true; | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| bool isLegalMaskedCompressStore(Type *DataType, | ||
| Align Alignment) const override { | ||
| ElementCount EC = cast<VectorType>(DataType)->getElementCount(); | ||
| if (EC.getKnownMinValue() != 2 && EC.getKnownMinValue() != 4) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That disqualifies compress stores for larger vectors with |
||
| return false; | ||
|
|
||
| if (!isElementTypeLegalForCompressStore(DataType->getScalarType())) | ||
| return false; | ||
|
|
||
| return isLegalMaskedLoadStore(DataType, Alignment); | ||
| } | ||
|
|
||
| bool isLegalMaskedGatherScatter(Type *DataType) const { | ||
| if (!ST->isSVEAvailable()) | ||
| return false; | ||
|
|
||
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,141 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6 | ||
| ; RUN: llc -mtriple=aarch64 -mattr=+sve < %s | FileCheck %s | ||
|
|
||
| ;; Full SVE vectors (supported with +sve) | ||
|
|
||
| define void @test_compressstore_nxv4i32(ptr %p, <vscale x 4 x i32> %vec, <vscale x 4 x i1> %mask) { | ||
| ; CHECK-LABEL: test_compressstore_nxv4i32: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: ptrue p1.s | ||
| ; CHECK-NEXT: compact z0.s, p0, z0.s | ||
| ; CHECK-NEXT: cntp x8, p1, p0.s | ||
| ; CHECK-NEXT: whilelo p0.s, xzr, x8 | ||
| ; CHECK-NEXT: st1w { z0.s }, p0, [x0] | ||
| ; CHECK-NEXT: ret | ||
| tail call void @llvm.masked.compressstore.nxv4i32(<vscale x 4 x i32> %vec, ptr align 4 %p, <vscale x 4 x i1> %mask) | ||
| ret void | ||
| } | ||
|
|
||
| define void @test_compressstore_nxv2i64(ptr %p, <vscale x 2 x i64> %vec, <vscale x 2 x i1> %mask) { | ||
| ; CHECK-LABEL: test_compressstore_nxv2i64: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: ptrue p1.d | ||
| ; CHECK-NEXT: compact z0.d, p0, z0.d | ||
| ; CHECK-NEXT: cntp x8, p1, p0.d | ||
| ; CHECK-NEXT: whilelo p0.d, xzr, x8 | ||
| ; CHECK-NEXT: st1d { z0.d }, p0, [x0] | ||
| ; CHECK-NEXT: ret | ||
| tail call void @llvm.masked.compressstore.nxv2i64(<vscale x 2 x i64> %vec, ptr align 8 %p, <vscale x 2 x i1> %mask) | ||
| ret void | ||
| } | ||
|
|
||
| define void @test_compressstore_nxv4f32(ptr %p, <vscale x 4 x float> %vec, <vscale x 4 x i1> %mask) { | ||
| ; CHECK-LABEL: test_compressstore_nxv4f32: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: ptrue p1.s | ||
| ; CHECK-NEXT: compact z0.s, p0, z0.s | ||
| ; CHECK-NEXT: cntp x8, p1, p0.s | ||
| ; CHECK-NEXT: whilelo p0.s, xzr, x8 | ||
| ; CHECK-NEXT: st1w { z0.s }, p0, [x0] | ||
| ; CHECK-NEXT: ret | ||
| tail call void @llvm.masked.compressstore.nxv4f32(<vscale x 4 x float> %vec, ptr align 4 %p, <vscale x 4 x i1> %mask) | ||
| ret void | ||
| } | ||
|
|
||
| ; TODO: Legal and nonstreaming check | ||
| define void @test_compressstore_nxv2f64(ptr %p, <vscale x 2 x double> %vec, <vscale x 2 x i1> %mask) { | ||
| ; CHECK-LABEL: test_compressstore_nxv2f64: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: ptrue p1.d | ||
| ; CHECK-NEXT: compact z0.d, p0, z0.d | ||
| ; CHECK-NEXT: cntp x8, p1, p0.d | ||
| ; CHECK-NEXT: whilelo p0.d, xzr, x8 | ||
| ; CHECK-NEXT: st1d { z0.d }, p0, [x0] | ||
| ; CHECK-NEXT: ret | ||
| tail call void @llvm.masked.compressstore.nxv2f64(<vscale x 2 x double> %vec, ptr align 8 %p, <vscale x 2 x i1> %mask) | ||
| ret void | ||
| } | ||
|
|
||
| ;; SVE vector types promoted to 32/64-bit (non-exhaustive) | ||
|
|
||
| define void @test_compressstore_nxv2i8(ptr %p, <vscale x 2 x i8> %vec, <vscale x 2 x i1> %mask) { | ||
| ; CHECK-LABEL: test_compressstore_nxv2i8: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: ptrue p1.d | ||
| ; CHECK-NEXT: compact z0.d, p0, z0.d | ||
| ; CHECK-NEXT: cntp x8, p1, p0.d | ||
| ; CHECK-NEXT: whilelo p0.d, xzr, x8 | ||
| ; CHECK-NEXT: st1b { z0.d }, p0, [x0] | ||
| ; CHECK-NEXT: ret | ||
| tail call void @llvm.masked.compressstore.nxv2i8(<vscale x 2 x i8> %vec, ptr align 1 %p, <vscale x 2 x i1> %mask) | ||
| ret void | ||
| } | ||
|
|
||
| define void @test_compressstore_nxv4i16(ptr %p, <vscale x 4 x i16> %vec, <vscale x 4 x i1> %mask) { | ||
| ; CHECK-LABEL: test_compressstore_nxv4i16: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: ptrue p1.s | ||
| ; CHECK-NEXT: compact z0.s, p0, z0.s | ||
| ; CHECK-NEXT: cntp x8, p1, p0.s | ||
| ; CHECK-NEXT: whilelo p0.s, xzr, x8 | ||
| ; CHECK-NEXT: st1h { z0.s }, p0, [x0] | ||
| ; CHECK-NEXT: ret | ||
| tail call void @llvm.masked.compressstore.nxv4i16(<vscale x 4 x i16> %vec, ptr align 2 %p, <vscale x 4 x i1> %mask) | ||
| ret void | ||
| } | ||
|
|
||
| ;; NEON vector types (promoted to SVE) | ||
|
|
||
| define void @test_compressstore_v2f32(ptr %p, <2 x double> %vec, <2 x i1> %mask) { | ||
| ; CHECK-LABEL: test_compressstore_v2f32: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: ushll v1.2d, v1.2s, #0 | ||
| ; CHECK-NEXT: ptrue p0.d, vl2 | ||
| ; CHECK-NEXT: // kill: def $q0 killed $q0 def $z0 | ||
| ; CHECK-NEXT: ptrue p1.d | ||
| ; CHECK-NEXT: shl v1.2d, v1.2d, #63 | ||
| ; CHECK-NEXT: cmpne p0.d, p0/z, z1.d, #0 | ||
| ; CHECK-NEXT: cntp x8, p1, p0.d | ||
| ; CHECK-NEXT: compact z0.d, p0, z0.d | ||
| ; CHECK-NEXT: whilelo p0.d, xzr, x8 | ||
| ; CHECK-NEXT: st1d { z0.d }, p0, [x0] | ||
| ; CHECK-NEXT: ret | ||
| tail call void @llvm.masked.compressstore.v2f64(<2 x double> %vec, ptr align 8 %p, <2 x i1> %mask) | ||
| ret void | ||
| } | ||
|
|
||
| define void @test_compressstore_v4i32(ptr %p, <4 x i32> %vec, <4 x i1> %mask) { | ||
| ; CHECK-LABEL: test_compressstore_v4i32: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: ushll v1.4s, v1.4h, #0 | ||
| ; CHECK-NEXT: ptrue p0.s, vl4 | ||
| ; CHECK-NEXT: // kill: def $q0 killed $q0 def $z0 | ||
| ; CHECK-NEXT: ptrue p1.s | ||
| ; CHECK-NEXT: shl v1.4s, v1.4s, #31 | ||
| ; CHECK-NEXT: cmpne p0.s, p0/z, z1.s, #0 | ||
| ; CHECK-NEXT: cntp x8, p1, p0.s | ||
| ; CHECK-NEXT: compact z0.s, p0, z0.s | ||
| ; CHECK-NEXT: whilelo p0.s, xzr, x8 | ||
| ; CHECK-NEXT: st1w { z0.s }, p0, [x0] | ||
| ; CHECK-NEXT: ret | ||
| tail call void @llvm.masked.compressstore.v4i32(<4 x i32> %vec, ptr align 4 %p, <4 x i1> %mask) | ||
| ret void | ||
| } | ||
|
|
||
| define void @test_compressstore_v2i64(ptr %p, <2 x i64> %vec, <2 x i1> %mask) { | ||
| ; CHECK-LABEL: test_compressstore_v2i64: | ||
| ; CHECK: // %bb.0: | ||
| ; CHECK-NEXT: ushll v1.2d, v1.2s, #0 | ||
| ; CHECK-NEXT: ptrue p0.d, vl2 | ||
| ; CHECK-NEXT: // kill: def $q0 killed $q0 def $z0 | ||
| ; CHECK-NEXT: ptrue p1.d | ||
| ; CHECK-NEXT: shl v1.2d, v1.2d, #63 | ||
| ; CHECK-NEXT: cmpne p0.d, p0/z, z1.d, #0 | ||
| ; CHECK-NEXT: cntp x8, p1, p0.d | ||
| ; CHECK-NEXT: compact z0.d, p0, z0.d | ||
| ; CHECK-NEXT: whilelo p0.d, xzr, x8 | ||
| ; CHECK-NEXT: st1d { z0.d }, p0, [x0] | ||
| ; CHECK-NEXT: ret | ||
| tail call void @llvm.masked.compressstore.v2i64(<2 x i64> %vec, ptr align 8 %p, <2 x i1> %mask) | ||
| ret void | ||
| } |
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.
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.
While
ISD::VECREDUCE_ADDsupports a larger result type than its operand's element type, the extra bits are undefined. In this case that means only the bottom bit of the result can be relied upon, with the operation likely converted to anISD::VECREDUCE_XOR. Perhaps this is another use case thatISD::PARTIAL_REDUCE_#MLAcan solve? with its implicit operand extension.Fixing the above might make this request impossible but can this be done as target agnostic expansion?
Uh oh!
There was an error while loading. Please reload this page.
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.
I'm not sure about using
ISD::PARTIAL_REDUCE_#MLA, but the following works:If we also define that the demanded bits for
aarch64_sve_cntpis a most 9 (max value 256, AFAIK), which allows theZERO_EXTENDto fold away.(This actually improves code gen as the
ptrueis folded into thecntp)