-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
7ef0b48
to
8df98bb
Compare
@@ -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 && |
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.
Could you add a comment to explain which cases this handles? (for both the existing and new case)
8df98bb
to
a2d74e1
Compare
@@ -231,6 +231,57 @@ bool AIELegalizerHelper::legalizeG_BUILD_VECTOR(LegalizerHelper &Helper, | |||
return true; | |||
} | |||
|
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 we have a description of the input->output of this custom legalization rule?
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.
llvm/lib/Target/AIE/AIEInstrGISel.td
Outdated
|
||
// Concatenate the src1 and src2 vectors, shift right | ||
// and extract the resulting lower 512-bit vector | ||
def G_AIE_VSHIFT : AIEGenericInstruction { |
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 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.
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
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(); |
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: maybe DstRegLow
and DstRegHigh
to improve readability.
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
MIRBuilder.buildInstr(TargetOpcode::G_IMPLICIT_DEF, {SrcTy}, {}) | ||
.getReg(0); | ||
|
||
const LLT Vec512 = |
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 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 = |
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 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 = |
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: auto ImplicitDef512 = MIRBuilder.buildUndef(Vec512);
a2d74e1
to
fa09112
Compare
fa09112
to
9f4905e
Compare
// to | ||
// %1:_(<4 x s32>) = G_AIE_UNPAD_VECTOR %0(<8 x s32>) | ||
// %3:_(s32) = G_CONSTANT i32 16 | ||
// %4:_(<16 x s32>) = G_CONCAT_VECTORS %0(<8 x s32>), %0(<8 x s32>) |
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 that %0
is G_IMPLICIT_DEF
, right?
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, that was not important. That`s why I left it.
const LLT Vec512 = SrcTy.multiplyElements(2); | ||
|
||
// Create the first 512-bit vector input | ||
auto MergeValue = |
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.
If you don't mind, I think ConcatValue
sounds better 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.
Sure.
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!
const Register DstRegLow = MI.getOperand(0).getReg(); | ||
const Register DstRegHigh = MI.getOperand(1).getReg(); | ||
const LLT SrcTy = MRI.getType(SrcReg); | ||
|
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 can assert that SrcTy
is a vector type to avoid misuse.
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.
Added assert for destination register, it ensure src to be vector as well.
83a1eff
to
ea7999a
Compare
@@ -68,6 +68,7 @@ class AIELegalizerHelper { | |||
Register SourceReg) const; | |||
bool unpack32BitVector(LegalizerHelper &Helper, MachineInstr &MI, | |||
Register SourceReg) const; | |||
bool legalize_unmerge_128bit(LegalizerHelper &Helper, MachineInstr &MI) 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: what about the standard naming convention legalizeUnmergeTo128bit
.
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.
Makes 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.
Hmm, other function names in the file follow this, legalizeG_SEXT_INREG
, legalizeG_VASTART
...
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.
So, legalizeG_UNMERGE...
would fit in this case.
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
ea7999a
to
c86cb0a
Compare
const Register DstRegHigh = MI.getOperand(1).getReg(); | ||
const LLT SrcTy = MRI.getType(SrcReg); | ||
|
||
assert(MRI.getType(DstRegLow).isVector() && "Expected vector restor"); |
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: restor is register?
@@ -241,6 +299,11 @@ bool AIELegalizerHelper::legalizeG_UNMERGE_VALUES(LegalizerHelper &Helper, | |||
const Register LastReg = MI.getOperand(MI.getNumOperands() - 1).getReg(); | |||
const LLT FirstTy = MRI.getType(FirstReg); | |||
const LLT LastTy = MRI.getType(LastReg); | |||
|
|||
if (ST.isAIE2P() && FirstTy.getSizeInBits() == 128 && |
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 check for vector types here?
c86cb0a
to
d6e46e6
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.
This PR introduces
G_AIE_VSHIFT_RIGHT
gMIR opcode which is selected tovshift
instruction. And this is utilized to legalize G_UNMERGE_VALUES 256-bit vector to 2 128-bit vector.