Skip to content
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

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

abnikant
Copy link
Collaborator

  1. Enable combine_load_store_increment, combine_offset_load_store_ptradd and combine_offset_load_store_share_ptradd
  2. Support wide vector POSTINC, POSTINC_2D, POSTINC_3D load and store.
  3. Fixup , offset opcode.
  4. Enable fifo combined load/store incr and offset load/store for 512-bits.
  5. 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
Copy link
Collaborator

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: const

Copy link
Collaborator Author

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();
Copy link
Collaborator

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
Copy link
Collaborator

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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: ...or FifoRegBank

Copy link
Collaborator Author

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: isGenericMemOffsetOpcode

Copy link
Collaborator Author

@abnikant abnikant Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the name.

@abnikant abnikant force-pushed the aie2p.wide.ld.st.incr.offset branch 2 times, most recently from 9d70b1d to a9baa70 Compare January 31, 2025 11:36
MachineFunction &MF = *MemI.getMF();
const bool isAIE2 = MF.getTarget().getTargetTriple().isAIE2();
if (isAIE2 &&
MRI.getType(MemI.getOperand(0).getReg()).getSizeInBits() >= 1024)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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));
Copy link
Collaborator

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 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@abnikant abnikant force-pushed the aie2p.wide.ld.st.incr.offset branch from a9baa70 to 48a5ce8 Compare January 31, 2025 14:46
; CHECK-NEXT: vst lfl0, [p1, #0] // Delay Slot 4
; CHECK-NEXT: vst lfh0, [p1, #64] // Delay Slot 3
; CHECK-NEXT: nop
; CHECK-NEXT: nop
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

@abnikant abnikant force-pushed the aie2p.wide.ld.st.incr.offset branch from 48a5ce8 to c82ccd3 Compare January 31, 2025 16:21
; 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
Copy link
Collaborator

@andcarminati andcarminati Jan 31, 2025

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.

Copy link
Collaborator Author

@abnikant abnikant Jan 31, 2025

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.

Copy link
Collaborator Author

@abnikant abnikant Feb 3, 2025

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

@abnikant abnikant force-pushed the aie2p.wide.ld.st.incr.offset branch from c82ccd3 to 81c7263 Compare February 3, 2025 06:36
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))
Copy link
Collaborator

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.

Copy link
Collaborator Author

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)?

Copy link
Collaborator

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 ;-)

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

@abnikant abnikant force-pushed the aie2p.wide.ld.st.incr.offset branch 3 times, most recently from 488b7c5 to d415c8c Compare February 10, 2025 05:25
@@ -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!");
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: outdated comment.

Copy link
Collaborator

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?

Copy link
Collaborator Author

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe isAIEOffsetMemOpcode?

Copy link
Collaborator Author

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) ?

; 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
Copy link
Collaborator

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.

Copy link
Collaborator Author

@abnikant abnikant Feb 11, 2025

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.

Copy link
Collaborator

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!

@abnikant abnikant force-pushed the aie2p.wide.ld.st.incr.offset branch 2 times, most recently from 99756e3 to 49ab730 Compare February 11, 2025 11:33
andcarminati
andcarminati previously approved these changes Feb 11, 2025
Copy link
Collaborator

@andcarminati andcarminati left a 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
@abnikant
Copy link
Collaborator Author

LGTM. Nice work! Thank you for addressing the comments.

Thanks @andcarminati for looking into this. I just rebased this PR to resolve conflicts in fifo-loads.ll test. Can you please check ?

@abnikant abnikant merged commit 333cd37 into aie-public Feb 11, 2025
8 checks passed
@SagarMaheshwari99 SagarMaheshwari99 deleted the aie2p.wide.ld.st.incr.offset branch February 12, 2025 13:01
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}};
Copy link
Collaborator

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?

Copy link
Collaborator Author

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the same observation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants