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] Legalize G_UNMERGE_VALUES 256-bit vector to 2 128-bit vectors #282

Open
wants to merge 2 commits into
base: aie-public
Choose a base branch
from

Conversation

niwinanto
Copy link
Collaborator

This PR introduces G_AIE_VSHIFT gMIR opcode which is selected to vshift instruction. And this is utilized to legalize G_UNMERGE_VALUES 256-bit vector to 2 128-bit vector.

@niwinanto niwinanto force-pushed the niwin.vshift.unmerge branch from 7ef0b48 to 8df98bb Compare January 17, 2025 17:15
@@ -551,8 +551,10 @@ AIE2PLegalizerInfo::AIE2PLegalizerInfo(const AIE2PSubtarget &ST)
const LLT &DstTy = Query.Types[0];
const LLT &SrcTy = Query.Types[1];

return SrcTy.isVector() && DstTy.isScalar() &&
DstTy == SrcTy.getElementType();
return (DstTy.isVector() && SrcTy.getSizeInBits() == 256 &&
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 add a comment to explain which cases this handles? (for both the existing and new case)

@niwinanto niwinanto force-pushed the niwin.vshift.unmerge branch from 8df98bb to a2d74e1 Compare January 20, 2025 08:37
@@ -231,6 +231,57 @@ bool AIELegalizerHelper::legalizeG_BUILD_VECTOR(LegalizerHelper &Helper,
return true;
}

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 have a description of the input->output of this custom legalization rule?


// Concatenate the src1 and src2 vectors, shift right
// and extract the resulting lower 512-bit vector
def G_AIE_VSHIFT : AIEGenericInstruction {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was expecting "right" to be visible in the opcode itself. If I see this opcode there is no way to discover that it does right shift without looking to the comment.

const AIEBaseInstrInfo *II = ST.getInstrInfo();
const unsigned UnpadOpc = II->getGenericUnpadVectorOpcode();
const Register SrcReg = MI.getOperand(MI.getNumOperands() - 1).getReg();
const Register Dst1Reg = MI.getOperand(0).getReg();
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: maybe DstRegLow and DstRegHigh to improve readability.

MIRBuilder.buildInstr(TargetOpcode::G_IMPLICIT_DEF, {SrcTy}, {})
.getReg(0);

const LLT Vec512 =
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 LLT Vec512 = SrcTy.multiplyElements(2);


// VSHIFT operates on 512-bit inputs. We need to pad the 256-bit source
// operand to 512-bit
const Register ImplicitDef256 =
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 Register ImplicitDef256 = MIRBuilder.buildUndef(SrcTy).getReg(0);

MIRBuilder.buildConcatVectors({Vec512}, {SrcReg, ImplicitDef256});

// The second input will be ignored. Just create a dummy input
auto ImplicitDef512 =
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: auto ImplicitDef512 = MIRBuilder.buildUndef(Vec512);

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.

3 participants