-
Notifications
You must be signed in to change notification settings - Fork 15
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
[AIE2P] Support wide vector postinc 2D/3D, and offset load/store #323
Conversation
abnikant
commented
Jan 31, 2025
- Enable combine_load_store_increment, combine_offset_load_store_ptradd and combine_offset_load_store_share_ptradd
- Support wide vector POSTINC, POSTINC_2D, POSTINC_3D load and store.
- Fixup , offset opcode.
- Enable fifo combined load/store incr and offset load/store for 512-bits.
- Add tests for combining and load/store.
# See https://llvm.org/LICENSE.txt for license information. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
# | ||
# (c) Copyright 2023-2024 Advanced Micro Devices, Inc. or its affiliates |
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.
nit: 2025
@@ -58,7 +58,10 @@ MachineInstr *findPreIncMatch(MachineInstr &MemI, MachineRegisterInfo &MRI, | |||
const AIEBaseInstrInfo &TII) { | |||
// This is currently done with patterns in instruction selection. | |||
// No need to do it here. | |||
if (MRI.getType(MemI.getOperand(0).getReg()).getSizeInBits() >= 1024) | |||
MachineFunction &MF = *MemI.getMF(); | |||
bool isAIE2 = MF.getTarget().getTargetTriple().isAIE2(); |
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.
nit: const
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.
done
@@ -320,9 +323,11 @@ MachineInstr *findPostIncMatch(MachineInstr &MemI, MachineRegisterInfo &MRI, | |||
const AIEBaseInstrInfo &TII) { | |||
if (!EnablePostIncCombine) | |||
return nullptr; | |||
if (MRI.getType(MemI.getOperand(0).getReg()).getSizeInBits() >= 1024) | |||
MachineFunction &MF = *MemI.getMF(); | |||
bool isAIE2 = MF.getTarget().getTargetTriple().isAIE2(); |
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.
nit: const
; CHECK-NEXT: bb.1: | ||
; CHECK-NEXT: successors: %bb.1(0x80000000) | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[PHI:%[0-9]+]]:_(p0) = G_PHI [[COPY]](p0), %bb.0, %2(p0), %bb.1 |
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.
Interesting, here we have just %2
instead of the regex.
: AIE2P::VLDA_dmx_lda_fifohl_idx; | ||
return {ISelOpcode, FitsImmediateRange, | ||
/*OffsetOpcode=*/AIE2P::VLDA_dmx_lda_fifohl_idx_imm}; | ||
} | ||
llvm_unreachable("512-bit vector type must be in AccRegBank or VRegBank"); |
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.
Nit: ...or FifoRegBank
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.
done.
@@ -252,6 +252,11 @@ unsigned AIE2PInstrInfo::getOffsetMemOpcode(unsigned BaseMemOpcode) const { | |||
llvm_unreachable("not a generic load/store"); | |||
} | |||
|
|||
bool AIE2PInstrInfo::isOffsetMemOpcode(unsigned Opcode) const { |
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.
Nit: isGenericMemOffsetOpcode
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.
updated the name.
9d70b1d
to
a9baa70
Compare
MachineFunction &MF = *MemI.getMF(); | ||
const bool isAIE2 = MF.getTarget().getTargetTriple().isAIE2(); | ||
if (isAIE2 && | ||
MRI.getType(MemI.getOperand(0).getReg()).getSizeInBits() >= 1024) |
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.
Shouldn't there be a corresponding size check for AIE2P?
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.
yes, I have added a check but I don't expect the vector size to be greater that 2048-bits.
@@ -253,6 +253,11 @@ unsigned AIE2PInstrInfo::getOffsetMemOpcode(unsigned BaseMemOpcode) const { | |||
llvm_unreachable("not a generic load/store"); | |||
} | |||
|
|||
bool AIE2PInstrInfo::isGenericOffsetMemOpcode(unsigned Opcode) const { | |||
return ((Opcode == AIE2P::G_AIE_OFFSET_STORE) || | |||
(Opcode == AIE2P::G_AIE_OFFSET_LOAD)); |
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.
What about G_AIE_OFFSET_SEXTLOAD / G_AIE_OFFSET_ZEXTLOAD ?
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.
done
a9baa70
to
48a5ce8
Compare
; CHECK-NEXT: vst lfl0, [p1, #0] // Delay Slot 4 | ||
; CHECK-NEXT: vst lfh0, [p1, #64] // Delay Slot 3 | ||
; CHECK-NEXT: nop | ||
; CHECK-NEXT: nop |
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.
why can the vst not work on the fifo registers as before?
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.
not sure I understood the question but if your question is why the test is updated ? since MIR is updated after the load/store combiner is enabled, it uses G_AIE_POSTINC_STORE.
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.
do we have a vst post increment that works on fifo regs? Because that would be preferable in this situation
48a5ce8
to
c82ccd3
Compare
; CHECK-NEXT: vst sfl, [p1, #0] // Delay Slot 4 | ||
; CHECK-NEXT: vst sfh, [p1, #64] // Delay Slot 3 | ||
; CHECK-NEXT: nop | ||
; CHECK-NEXT: vmov x1, sfh |
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 guess @F-Stuckmann is referring to this case. Now we are storing using vector registers.
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.
we do have the post-increment for fifo-regs , refer to the test case inst-select-vector-pre-post-increment.mir. The problem with the above case is register bank assignment not assigning fiforegbank.
%7:ptrregbank(p0), %8:fiforegbank(<32 x s32>), %9:gprregbank(s32) = G_INTRINSIC_W_SIDE_EFFECTS intrinsic(@llvm.aie2p.fifo.ld.fill), %4(p0), %5(<32 x s32>), %6(s32)
%10:vregbank(<32 x s32>) = COPY %8(<32 x s32>)
%3:ptrregbank(p0) = G_AIE_POSTINC_STORE %10(<32 x s32>), %1, %2(s20) :: (store (<32 x s32>) into %ir.s)
if I use %8 in G_AIE_POSTINC_STORE , then it generates post-inc with fifo. We are missing G_AIE_POSTINC_STORE opcode in regbank-select.
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.
After handling G_AIE_POSTINC_STORE in RegisterBank assignment, both of these tests ldst-fifo-stores.ll and fifo-loads.ll are working as expected. I will have a separate commit for this.
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.
Hi @abnikant, I suspected that we were missing this proper register bank assignment. Thank you for the explanation.
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.
@andcarminati I will open a separate PR for RegisterBank assignment, adding a commit in this PR does not make much sense.
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.
Agree! This PR has complexity enough.
c82ccd3
to
81c7263
Compare
const Triple &TT = MF.getTarget().getTargetTriple(); | ||
const unsigned VecSize = | ||
MRI.getType(MemI.getOperand(0).getReg()).getSizeInBits(); | ||
if ((TT.isAIE2() && VecSize >= 1024) || (TT.isAIE2P() && VecSize > 2048)) |
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.
nit: can we refactor this check? Future targets can just extend it.
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 can refactor, and probably add a target hook to check for maximum supported size for a sub-target. But here we still need to add check for VecSize == 1024 for AIE2 since we don't have instruction selection support for 1024-bit combined load/store (postinc/offset)?
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.
Sure, any refactoring is welcome here ;-)
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.
@andcarminati - Could you please review the refactored code? I had to merge two commits to prevent test failures during instruction selection after enabling combines, as support for instruction selection was introduced in the subsequent commit.
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.
Hi @abnikant, I had a second round or review, I included some suggestions to try to simplify some parts. The implementation looks correct to me.
488b7c5
to
d415c8c
Compare
d415c8c
to
b247267
Compare
@@ -567,6 +569,11 @@ struct AIEBaseInstrInfo : public TargetInstrInfo { | |||
llvm_unreachable("Target didn't implement getVecRegSize!"); | |||
} | |||
|
|||
/// Return the maximum supported vector size for this target. | |||
virtual unsigned getMaxVectorBitSize() const { | |||
llvm_unreachable("Target didn't implement getMaxVectorSize!"); |
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.
nit getMaxVectorBitSize
.
const unsigned VecSize = | ||
MRI.getType(MemI.getOperand(0).getReg()).getSizeInBits(); | ||
const unsigned MaxVecSize = TII.getMaxVectorBitSize(); | ||
// TODO: Remove the following check once 1024-bit load/store |
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.
nit: outdated comment.
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 feel that we could have a common logic here, based on TII. Can we harmonize this asymmetric difference in some way? What do you think?
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.
Can't skip this check if we use getMaxVectorBitSize , I have added another target hook getMaxSupportedLdStIncSize(), is this okay?
@@ -259,6 +259,13 @@ unsigned AIE2PInstrInfo::getOffsetMemOpcode(unsigned BaseMemOpcode) const { | |||
llvm_unreachable("not a generic load/store"); | |||
} | |||
|
|||
bool AIE2PInstrInfo::isGenericOffsetMemOpcode(unsigned Opcode) const { |
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.
Maybe isAIEOffsetMemOpcode
?
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 am not in favor of selectively updating the name, Generic keyword is used in few other places for AIE opcodes, I think updating all other names along with this will make more sense , what do you think (using a separate small PR) ?
llvm/test/CodeGen/AIE/aie2p/GlobalIsel/inst-select-vector-indexed-load-store.mir
Show resolved
Hide resolved
; CHECK-NEXT: st r26, [p1, dj0] // Delay Slot 5 | ||
; CHECK-NEXT: vst sfl, [p1, #0] // Delay Slot 4 | ||
; CHECK-NEXT: vst sfh, [p1, #64] // Delay Slot 3 | ||
; CHECK-NEXT: nop |
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.
Maybe we could prioritize merging your RegBank PR first, as it represents an early compilation step. In this cases we will have this tests in the final shape. But it is just one idea.
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.
That makes sense, but we need to merge this PR first; otherwise, ld-fifo.ll
will break. After the Regbank PR, the regbank assignment for one of the operands in the load/store combine instruction is updated to fiforegbank
, which isn't supported for instruction selection until this PR is merged.
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.
In this case, it makes sense!
99756e3
to
49ab730
Compare
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.
LGTM. Nice work! Thank you for addressing the comments.
2) [AIE2P] Support postinc 2D/3D, and offset load/store
49ab730
to
1b8f97b
Compare
Thanks @andcarminati for looking into this. I just rebased this PR to resolve conflicts in fifo-loads.ll test. Can you please check ? |
if (RBID == AIE2P::VRegBankID) | ||
return {/*ISelOpcode=*/AIE2P::VLDA_2D_dmx_lda_x, NoImmediate, | ||
/*OffsetOpcode=*/{}}; | ||
llvm_unreachable("512-bit vector type must be in AccRegBank or VRegBank"); | ||
/*OffsetOpcode=*/{AIE2P::VLDA_dmw_lda_w_idx_imm}}; |
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.
Late observation: is this VLDA_dmw_lda_w_idx_imm
correct for size >= 512?
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.
oh!, yes. This is wrong opcode and will result in wrong Copy. It should be VLDA_dmx_lda_x_idx_imm, I see it is used at two places. I will open a fixup PR shortly. Thanks for catching this.
; CHECK-NEXT: [[MOV_PD_imm11_pseudo3:%[0-9]+]]:edc = MOV_PD_imm11_pseudo 4 | ||
; CHECK-NEXT: [[REG_SEQUENCE:%[0-9]+]]:ed = REG_SEQUENCE [[MOV_PD_imm11_pseudo]], %subreg.sub_mod, [[MOV_PD_imm11_pseudo2]], %subreg.sub_dim_size, [[MOV_PD_imm11_pseudo1]], %subreg.sub_dim_stride, [[MOV_PD_imm11_pseudo3]], %subreg.sub_dim_count | ||
; CHECK-NEXT: [[VLDA_2D_dmx_lda_x:%[0-9]+]]:vec512, [[VLDA_2D_dmx_lda_x1:%[0-9]+]]:ep, [[VLDA_2D_dmx_lda_x2:%[0-9]+]]:edc = VLDA_2D_dmx_lda_x [[COPY]], [[REG_SEQUENCE]] :: (load (<16 x s32>), align 128) | ||
; CHECK-NEXT: [[VLDA_dmw_lda_w_idx_imm:%[0-9]+]]:mwa = VLDA_dmw_lda_w_idx_imm [[COPY]], 64 :: (load (<16 x s32>) from unknown-address + 64) |
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.
Here the same observation.