-
Notifications
You must be signed in to change notification settings - Fork 12
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
Support for allowing direct VEXTRACT to 20-bit registers #233
base: aie-public
Are you sure you want to change the base?
Conversation
llvm/test/CodeGen/AIE/aie2/GlobalISel/prelegalizercombiner-s20-narrowing.mir
Outdated
Show resolved
Hide resolved
llvm/test/CodeGen/AIE/aie2/GlobalISel/prelegalizercombiner-s20-narrowing.mir
Outdated
Show resolved
Hide resolved
Given that you mentioned there are no QoR gain, I would recommend you to re look at the instruction that consume S20 type reg. |
650d8a9
to
d5d7cf0
Compare
d5d7cf0
to
f12f1a4
Compare
f12f1a4
to
ba49cf1
Compare
ccbdb07
to
6138a60
Compare
6138a60
to
11cd993
Compare
11cd993
to
35027af
Compare
@@ -2465,6 +2465,20 @@ bool CombinerHelper::matchCombineZextTrunc(MachineInstr &MI, Register &Reg) { | |||
return false; | |||
} | |||
|
|||
bool CombinerHelper::matchCombineSextTrunc(MachineInstr &MI, Register &Reg) { |
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
everywhere:
bool CombinerHelper::matchCombineSextTrunc(MachineInstr &MI, Register &Reg) {
assert(MI.getOpcode() == TargetOpcode::G_SEXT && "Expected a G_SEXT");
- Register DstReg = MI.getOperand(0).getReg();
- Register SrcReg = MI.getOperand(1).getReg();
- LLT DstTy = MRI.getType(DstReg);
+ const Register DstReg = MI.getOperand(0).getReg();
+ const Register SrcReg = MI.getOperand(1).getReg();
+ const LLT DstTy = MRI.getType(DstReg);
if (mi_match(SrcReg, MRI,
m_GTrunc(m_all_of(m_Reg(Reg), m_SpecificType(DstTy))))) {
- unsigned DstSize = DstTy.getScalarSizeInBits();
- unsigned SrcSize = MRI.getType(SrcReg).getScalarSizeInBits();
+ const unsigned DstSize = DstTy.getScalarSizeInBits();
+ const unsigned SrcSize = MRI.getType(SrcReg).getScalarSizeInBits();
return KB->computeNumSignBits(Reg) >= (DstSize - SrcSize + 1);
}
return false;
MIRBuilder.buildAssertInstr(AssertExtOpcode, ExtReg20Bit, DstReg20Bit, | ||
SrcEltSize); | ||
MIRBuilder.buildInstr(ExtOpcode, {DstReg}, {ExtReg20Bit}); | ||
MI.eraseFromParent(); |
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.
Now we are safe ;-)
Register DstReg, bool SignVal, unsigned SrcEltSize) const { | ||
// Returns the single non-debug use of a register with a specific opcode | ||
// and destination size. | ||
auto GetOneUseWithOpCode = |
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: GetOneUseWithOpcode
const unsigned ExtOpcode = | ||
SignVal ? TargetOpcode::G_SEXT : TargetOpcode::G_ZEXT; | ||
const Register UseDstReg = TruncMI->getOperand(0).getReg(); | ||
if (auto Ext = GetOneUseWithOpCode(UseDstReg, ExtOpcode, 20)) { |
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: we can use:
if (GetOneUseWithOpcode(UseDstReg, ExtOpcode, 20)) {
return true;
}
Because there is no further use for auto Ext
.
Or even:
bool AIE2PreLegalizerCombinerImpl::canCombineVExtractElt(
Register DstReg, bool SignVal, unsigned SrcEltSize) const {
// Returns the single non-debug use of a register with a specific opcode
// and destination size.
auto GetOneUseWithOpcode =
[&](const Register Reg, const unsigned OpcodeToCheck,
const unsigned DstSize) -> std::optional<MachineInstr *> {
if (MRI.hasOneNonDBGUser(Reg)) {
MachineInstr &Use = *MRI.use_nodbg_instructions(Reg).begin();
if (Use.getOpcode() == OpcodeToCheck) {
const LLT DstRegTy = MRI.getType(Use.getOperand(0).getReg());
if (DstRegTy.getSizeInBits() == DstSize)
return &Use;
}
}
return std::nullopt;
};
auto Trunc = GetOneUseWithOpcode(DstReg, TargetOpcode::G_TRUNC, SrcEltSize);
if (!Trunc)
return false;
const MachineInstr *TruncMI = *Trunc;
const unsigned ExtOpcode =
SignVal ? TargetOpcode::G_SEXT : TargetOpcode::G_ZEXT;
const Register UseDstReg = TruncMI->getOperand(0).getReg();
return GetOneUseWithOpcode(UseDstReg, ExtOpcode, 20).has_value();
}
MachineVerifier
has been updated to allowG_AIE_SEXT_EXTRACT_VECTOR_ELT
andG_AIE_ZEXT_EXTRACT_VECTOR_ELT
to accept 20-bit outputs.