-
Notifications
You must be signed in to change notification settings - Fork 26
Handle Vector types in G_FADD using G_FPEXT #557
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
Sameeranjoshi
wants to merge
12
commits into
Xilinx:aie-public
Choose a base branch
from
Sameeranjoshi:sam-fpadd-fpext
base: aie-public
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
12 commits
Select commit
Hold shift + click to select a range
b0add75
fpext, customFor way
Sameeranjoshi a097383
Instruction selection method
Sameeranjoshi 19925db
G_FPEXT passes legalizer for bf16->f32 vector types.
Sameeranjoshi c584c63
CustomIf condition checks
Sameeranjoshi 67942ea
More tests and non-powers of 2, less < 256 bits
Sameeranjoshi 0c980a0
tests
Sameeranjoshi 7c3257c
Clang-format, fix failing tests
Sameeranjoshi d6f97ee
[AIE2P] Support vector reduction in G_FADD to support bf16 types
Sameeranjoshi 019b723
[AIE2p] Handle failing <64xbf16> test case.
Sameeranjoshi 5d78388
Clang format
Sameeranjoshi b966462
[AIE2P] Add test to validate vector of bf16 with 16,32,64 shape.
Sameeranjoshi 543ca14
[AIE2P] Fix bf16 and f32 crash
Sameeranjoshi 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
56 changes: 56 additions & 0 deletions
56
llvm/test/CodeGen/AIE/aie2p/GlobalIsel/legalize-vector-fadd.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,56 @@ | ||
; RUN: llc -mtriple=aie2p -O0 -stop-after=legalizer %s -o - 2>&1 | FileCheck %s | ||
; This test is a carved out test for sending patch upstream from | ||
; iree-amd-aie/compiler/plugins/target/AMD-AIE/iree-amd-aie/Transforms/test/multi_reduction_to_reduction_sizes_types.mlirUntitled-1.mlir | ||
|
||
; Ideally reduction should be as follows(with minor changes for each shape): | ||
; Input1: <32xbf16> and Input2: <32xbf16> | ||
; Extended1<32xf32> = fpext <32xbf16> | ||
; Extended2<32xf32> = fpext <32xbf16> | ||
; Zero<32xf32> = zeroinitializer | ||
; Out1<64xf32> = Concat zero, <Extended1<32xf32>> | ||
; Out2<64xf32> = Concat zero, <Extended2<32xf32>> | ||
; Result<64xf32> = fadd <Out1<64xf32>>, <Out2<64xf32>> | ||
; R1<32xf32>, R2<32xf32> = unmerge <Result<64xf32>> | ||
; R2 is all 0s | ||
; R1<32xbf16> = trunc <R1<32xf32>> | ||
|
||
; check the vadd.f | ||
; pad checks | ||
; checks similar to <32xbf16> | ||
; unpad checks | ||
define bfloat @multi_reduction_1d_16_bf16(<16 x bfloat> %0, bfloat %1) { | ||
%3 = call reassoc bfloat @llvm.vector.reduce.fadd.v16bf16(bfloat %1, <16 x bfloat> %0) | ||
ret bfloat %3 | ||
} | ||
|
||
|
||
|
||
; CHECK-LABEL: name: multi_reduction_1d_32_bf16 | ||
; CHECK: G_CONSTANT i32 0 | ||
; CHECK: G_AIE_BROADCAST_VECTOR %{{[0-9]+}}(s32) | ||
; CHECK: G_CONSTANT i32 2 | ||
; CHECK: G_CONSTANT i32 3 | ||
; CHECK: G_AIE_SHUFFLE_VECTOR %{{[0-9]+}}, %{{[0-9]+}}, %{{[0-9]+}}(s32) | ||
; CHECK: G_AIE_SHUFFLE_VECTOR %{{[0-9]+}}, %{{[0-9]+}}, %{{[0-9]+}}(s32) | ||
; CHECK: G_BITCAST %{{[0-9]+}}(<32 x s16>) | ||
; CHECK: G_BITCAST %{{[0-9]+}}(<32 x s16>) | ||
; CHECK: G_CONCAT_VECTORS %{{[0-9]+}}(<16 x s32>), %{{[0-9]+}}(<16 x s32>) | ||
; CHECK: G_IMPLICIT_DEF | ||
; CHECK: G_CONCAT_VECTORS %{{[0-9]+}}(<32 x s32>), %{{[0-9]+}}(<32 x s32>) | ||
; CHECK: G_FADD %{{[0-9]+}}, %{{[0-9]+}} | ||
; CHECK: G_UNMERGE_VALUES %{{[0-9]+}}(<64 x s32>) | ||
; CHECK: G_INTRINSIC_W_SIDE_EFFECTS intrinsic(@llvm.aie2p.v32accfloat.to.v32bf16), %{{[0-9]+}}(<32 x s32>) | ||
define bfloat @multi_reduction_1d_32_bf16(<32 x bfloat> %0, bfloat %1) { | ||
%3 = call reassoc bfloat @llvm.vector.reduce.fadd.v32bf16(bfloat %1, <32 x bfloat> %0) | ||
ret bfloat %3 | ||
} | ||
|
||
; ; Converted to chunks of <32 x bf16> | ||
; Check if the input is split into 2 chunks of <32 x bf16> | ||
; Check for each chunk similar to <32xbf16> case | ||
; Check if both inputs get concatenated to <64xbf16> | ||
|
||
define bfloat @multi_reduction_1d_64_bf16(<64 x bfloat> %0, bfloat %1) { | ||
%3 = call reassoc bfloat @llvm.vector.reduce.fadd.v64bf16(bfloat %1, <64 x bfloat> %0) | ||
ret bfloat %3 | ||
} |
73 changes: 73 additions & 0 deletions
73
llvm/test/CodeGen/AIE/aie2p/GlobalIsel/legalize-vector-fpext.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,73 @@ | ||
; RUN: llc -mtriple=aie2p -O0 -stop-after=legalizer %s -o - 2>&1 | FileCheck %s | ||
|
||
|
||
; Validates bfloat -> float legalization. | ||
; CHECK-LABEL: name: extend | ||
; CHECK: [[COPY:%[0-9]+]]:_(<32 x s16>) = COPY $x0 | ||
; CHECK-NOT: G_SHL | ||
; CHECK-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2 | ||
; CHECK-NEXT: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 3 | ||
; CHECK-NEXT: [[C0:%[0-9]+]]:_(s32) = G_CONSTANT i32 0 | ||
; CHECK-NEXT: [[BCAST:%[0-9]+]]:_(<32 x s16>) = G_AIE_BROADCAST_VECTOR [[C0]](s32) | ||
; CHECK-NEXT: [[SHUF1:%[0-9]+]]:_(<32 x s16>) = G_AIE_SHUFFLE_VECTOR [[BCAST]], [[COPY]], [[C2]](s32) | ||
; CHECK-NEXT: [[SHUF2:%[0-9]+]]:_(<32 x s16>) = G_AIE_SHUFFLE_VECTOR [[BCAST]], [[COPY]], [[C3]](s32) | ||
; CHECK-NEXT: [[BIT1:%[0-9]+]]:_(<16 x s32>) = G_BITCAST [[SHUF1]](<32 x s16>) | ||
; CHECK-NEXT: [[BIT2:%[0-9]+]]:_(<16 x s32>) = G_BITCAST [[SHUF2]](<32 x s16>) | ||
; CHECK-NEXT: [[CONCAT:%[0-9]+]]:_(<32 x s32>) = G_CONCAT_VECTORS [[BIT1]](<16 x s32>), [[BIT2]](<16 x s32>) | ||
|
||
define <32 x float> @extend(bfloat %o, <32 x bfloat> %in) nounwind { | ||
%X = fpext <32 x bfloat> %in to <32 x float> | ||
ret <32 x float> %X | ||
} | ||
|
||
; Pads the 17 valid values with undefined values to form a 32 size vector. | ||
|
||
; CHECK-LABEL: name: extend_non_power_of_2 | ||
; CHECK: [[COPY:%[0-9]+]]:_(<32 x s16>) = COPY $x0 | ||
; CHECK-COUNT-17: G_AIE_SEXT_EXTRACT_VECTOR_ELT | ||
; CHECK-COUNT-32: G_AIE_ADD_VECTOR_ELT_HI | ||
; CHECK-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 2 | ||
; CHECK-NEXT: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 3 | ||
; CHECK-NEXT: [[C0:%[0-9]+]]:_(s32) = G_CONSTANT i32 0 | ||
; CHECK-NEXT: [[BCAST:%[0-9]+]]:_(<32 x s16>) = G_AIE_BROADCAST_VECTOR [[C0]](s32) | ||
; CHECK-NEXT: [[SHUF1:%[0-9]+]]:_(<32 x s16>) = G_AIE_SHUFFLE_VECTOR [[BCAST]], %{{[0-9]+}}, [[C2]](s32) | ||
; CHECK-NEXT: [[SHUF2:%[0-9]+]]:_(<32 x s16>) = G_AIE_SHUFFLE_VECTOR [[BCAST]], %{{[0-9]+}}, [[C3]](s32) | ||
; CHECK-NEXT: [[BIT1:%[0-9]+]]:_(<16 x s32>) = G_BITCAST [[SHUF1]](<32 x s16>) | ||
; CHECK-NEXT: [[BIT2:%[0-9]+]]:_(<16 x s32>) = G_BITCAST [[SHUF2]](<32 x s16>) | ||
; CHECK-COUNT-17: G_AIE_SEXT_EXTRACT_VECTOR_ELT | ||
; CHECK-COUNT-32: G_AIE_ADD_VECTOR_ELT_HI | ||
; CHECK-NEXT: [[CONCAT:%[0-9]+]]:_(<32 x s32>) = G_CONCAT_VECTORS %{{[0-9]+}}(<16 x s32>), %{{[0-9]+}}(<16 x s32>) | ||
define <17 x float> @extend_non_power_of_2(<17 x bfloat> %in) nounwind { | ||
%X = fpext <17 x bfloat> %in to <17 x float> | ||
ret <17 x float> %X | ||
} | ||
|
||
; Validates if vector size < 256 bits | ||
|
||
; CHECK-LABEL: name: fpext_bf16_to_f32 | ||
; CHECK: bb.1 | ||
; CHECK: [[VEC_CONCAT:%[0-9]+]]:_(<32 x s16>) = G_CONCAT_VECTORS | ||
; CHECK: G_AIE_SEXT_EXTRACT_VECTOR_ELT [[VEC_CONCAT]] | ||
; CHECK: G_AIE_ADD_VECTOR_ELT_HI | ||
; CHECK: [[SHUFFLE_VEC:%[0-9]+]]:_(<32 x s16>) = G_AIE_SHUFFLE_VECTOR | ||
; CHECK-NOT: G_AIE_SHUFFLE_VECTOR | ||
; CHECK: [[BITCAST:%[0-9]+]]:_(<16 x s32>) = G_BITCAST [[SHUFFLE_VEC]] | ||
; CHECK: $x0 = COPY [[BITCAST]] | ||
define <16 x float> @fpext_bf16_to_f32(<16 x bfloat> %in) nounwind { | ||
%X = fpext <16 x bfloat> %in to <16 x float> | ||
ret <16 x float> %X | ||
} | ||
|
||
; Validates scalar path | ||
; CHECK-LABEL: name: fpext_scalar_bf16_to_f32 | ||
; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $r1 | ||
; CHECK-NEXT: [[C16:%[0-9]+]]:_(s32) = G_CONSTANT i32 16 | ||
; CHECK-NEXT: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[COPY]], [[C16]](s32) | ||
; CHECK-NOT: G_AIE_SHUFFLE_VECTOR | ||
; CHECK-NEXT: $r0 = COPY [[SHL]](s32) | ||
; CHECK-NEXT: PseudoRET implicit $lr, implicit $r0 | ||
|
||
define float @fpext_scalar_bf16_to_f32(bfloat %in) nounwind { | ||
%X = fpext bfloat %in to float | ||
ret float %X | ||
} |
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.
For the tests, it is better to run just the pass of interest. For example, you can create an MIR test including just the ilegal type operation and run llc with
-run-pass=legalizer
. In this way we can easily spot the specific legalization change in action.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 good part is that you can use
llvm/utils/update_mir_test_checks.py
to update the tests.