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] Combine G_SHUFFLE_VECTOR into Extract+Broadcast #284

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

Conversation

katerynamuts
Copy link
Collaborator

No description provided.

@@ -1768,3 +1773,44 @@ bool llvm::matchShuffleToBroadcast(MachineInstr &MI, MachineRegisterInfo &MRI,
MatchInfo = std::make_pair(DstReg, Src1Reg);
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.

nit: include some gMIR example that shows the pattern to be matched.


const Register Src1VecReg = MI.getOperand(1).getReg();
const LLT ElemTy = MRI.getType(Src1VecReg).getElementType();
if (ElemTy.getSizeInBits() == 64)
Copy link
Collaborator

@andcarminati andcarminati Jan 20, 2025

Choose a reason for hiding this comment

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

Do we have a reason to block this size here? For example, we are legalizing bigger types here: #283

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree, I removed it.

(defs root:$root, build_fn_matchinfo:$matchinfo),
(match (wip_match_opcode G_SHUFFLE_VECTOR): $root,
[{ return matchShuffleToExtractBroadcast(*${root}, MRI, (const AIEBaseInstrInfo &)B.getTII(), ${matchinfo}); }]),
(apply [{ Helper.applyBuildFn(*${root}, ${matchinfo}); }])>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice implementation using std::function.

; CHECK-NEXT: PseudoRET implicit $lr, implicit [[AIE_UNPAD_VECTOR]](<8 x s32>)
%0:_(<8 x s32>) = COPY $wl0
%1:_(<8 x s32>) = COPY $wl1
%2:_(<8 x s32>) = G_SHUFFLE_VECTOR %0(<8 x s32>), %1(<8 x s32>), shufflemask(2, 2, 2, 2, 2, 2, 2, 2)
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 include a negative test case?

@katerynamuts katerynamuts force-pushed the kmuts.extbcst-1 branch 2 times, most recently from 15def52 to 296dd59 Compare January 20, 2025 13:17
for (unsigned I = 0; I < NumElems; I++) {
int Idx = Mask[I];
if (Idx < 0)
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that legal to have a negative index?

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, it means that the value is undef.

return false;
}
}
assert(UniqOpIdx >= 0 && "Couldn't find a unique operand to extract!");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: To make this function more concise, I'd suggest creating a helper like: std::optional<int> getUniqueIndex(ArrayRef<int> Mask);.

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