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] Implemented VLDB.UNPACK combine #299

Open
wants to merge 1 commit into
base: aie-public
Choose a base branch
from

Conversation

katerynamuts
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@mludevid mludevid left a comment

Choose a reason for hiding this comment

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

Everything else seems good. The test files need to be checked again once they have been updated.

llvm/lib/Target/AIE/AIE2InstructionSelector.cpp Outdated Show resolved Hide resolved
llvm/lib/Target/AIE/aie2p/AIE2PInstructionSelector.cpp Outdated Show resolved Hide resolved
llvm/lib/Target/AIE/aie2p/AIE2PInstructionSelector.cpp Outdated Show resolved Hide resolved
Comment on lines 2869 to 2997
// Erasing the load instruction breaks later on in the selection code. That is
// because we keep an iterator on erased instructions. This breaks while
// trying to eliminate a trivially dead instruction which requires access to
// its memory operands which have been erased, thus leading to a seg fault. To
// remedy this, we keep the load to be removed by the trivial dead code
// elimination and we make sure to assign a new virtual register definition to
// its live operands to respect SSA.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I think at this point, we no longer need this comment, we use makeDeadMI in multiple instruction selection methods.

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 would rather keep it because if someone reads exactly this function then the comment helps to understand why we do it.

Copy link
Collaborator

@martien-de-jong martien-de-jong Jan 28, 2025

Choose a reason for hiding this comment

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

I think explaining it once at the definition of makeDeadMI would suffice. It's just one vscode click away. I also think that the comment is overly woolly. 'We can not erase this since it would invalidate active iterators' says it all.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Similarly to #292, the offsets in the tests need to be updated, because the immediate ranges have changed from AIE2 to AIE2P. Please also fix them in the post-increment test file.

@katerynamuts katerynamuts force-pushed the kmuts.vldb-unpack branch 2 times, most recently from d7580ff to 0e71576 Compare January 24, 2025 08:15
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update the year in the file header.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please update the year in the file header.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you also use AIEBaseInstructionSelector::setCtrlRegister in selectSetControlRegister?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As in AIE2InstructionSelector.cpp: Could you also use AIEBaseInstructionSelector::setCtrlRegister in selectSetControlRegister?

@@ -1268,7 +1273,7 @@ bool AIE2PInstructionSelector::selectG_AIE_LOAD_UPS(MachineInstr &UPSI,

// First use is the G_INTRINSIC_W_SIDE_EFFECTS ID
Register LoadResult = (std::next(UPSI.uses().begin()))->getReg();
MachineInstr *LoadOp = MRI.getUniqueVRegDef(LoadResult);
MachineInstr *LoadOp = getDefIgnoringCopiesAndBitcasts(LoadResult, MRI);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a test for this change?

@@ -2672,7 +2677,7 @@ bool AIE2PInstructionSelector::selectG_AIE_STORE_CONV(
// differ.

Register ConvResult = (StoreI.uses().begin())->getReg();
MachineInstr *ConvOp = MRI.getUniqueVRegDef(ConvResult);
MachineInstr *ConvOp = getDefIgnoringCopiesAndBitcasts(ConvResult, MRI);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same thing as above: Could you add a test for this change?

llvm/lib/Target/AIE/aie2p/AIE2PInstructionSelector.cpp Outdated Show resolved Hide resolved
Comment on lines 40 to 43
%8:modregbank(s20) = G_CONSTANT i20 0
%9:modregbank(s20) = G_CONSTANT i20 -256
%10:modregbank(s20) = G_CONSTANT i20 224
%11:modregbank(s20) = G_CONSTANT i20 256
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason you skipped the offset test with half a step size?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, I think I just missed it, I added it to the test.

CombOpInstID == Intrinsic::aie2p_unpack_I1024_I8_I4))) &&
"Unexpected VLDB.UNPACK size");

unsigned ISelOpcode;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would declare a local version where and when it is needed. Otherwise, please initialize it to 'the illegal opcode'

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 cannot create local versions in this case, I would need to give all of them different names, so I initialized it with UINT_MAX.

? AIE2P::VLDB_UNPACK_dmw_ldb_unpack_idx_imm_unpackSign1
: AIE2P::VLDB_UNPACK_dmw_ldb_unpack_idx_unpackSign1;
return LoadStoreOpcodes{ISelOpcode, FitsImmediateRange, {}};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know the default case doesn't occur, but could we at least put a break between the cases of the outer switch? (if only to help the poor C++ compiler.)

return false;

const std::optional<APInt> NoImmediate = {};
bool IsSigned = false;
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 bool IsSigned = false;

bool AIE2PInstructionSelector::canCombineUNPACKLoad(MachineInstr &MemOp,
MachineInstr &CombOp,
MachineRegisterInfo &MRI) {
Register LoadResult = (std::next(CombOp.uses().begin()))->getReg();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand this. AFAICS, MemOp is the Load. Why isn't LoadResult the register of its first def?

const bool AlwaysFitsImmediateRange = true;
const bool NoImmediate = false;
bool FitsImmediateRange = false;
if (IsSigned) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

AFAICS, the else branch differs only in selecting a different opcode. I would arrange for that with a small function unsigned selectSignedness(int Opcode, IsSigned)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is a good idea and I think it makes sense to do it for all combines but for now I would leave it as it is and implement these functions for all combines in a follow-up PR.

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.

4 participants