-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[GISel][AArch64] Create emitCMP instead of cloning a virtual register (NFC) #155262
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
Conversation
|
@llvm/pr-subscribers-backend-aarch64 Author: AZero13 (AZero13) ChangesCMN also has a function like this, we should do the same with CMP. Full diff: https://github.com/llvm/llvm-project/pull/155262.diff 1 Files Affected:
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
index 0bceb322726d1..edec7ac5ae47e 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
@@ -310,6 +310,8 @@ class AArch64InstructionSelector : public InstructionSelector {
MachineIRBuilder &MIRBuilder) const;
MachineInstr *emitSBCS(Register Dst, MachineOperand &LHS, MachineOperand &RHS,
MachineIRBuilder &MIRBuilder) const;
+ MachineInstr *emitCMP(MachineOperand &LHS, MachineOperand &RHS,
+ MachineIRBuilder &MIRBuilder) const;
MachineInstr *emitCMN(MachineOperand &LHS, MachineOperand &RHS,
MachineIRBuilder &MIRBuilder) const;
MachineInstr *emitTST(MachineOperand &LHS, MachineOperand &RHS,
@@ -4414,6 +4416,15 @@ AArch64InstructionSelector::emitSBCS(Register Dst, MachineOperand &LHS,
return emitInstr(OpcTable[Is32Bit], {Dst}, {LHS, RHS}, MIRBuilder);
}
+MachineInstr *
+AArch64InstructionSelector::emitCMP(MachineOperand &LHS, MachineOperand &RHS,
+ MachineIRBuilder &MIRBuilder) const {
+ MachineRegisterInfo &MRI = MIRBuilder.getMF().getRegInfo();
+ bool Is32Bit = (MRI.getType(LHS.getReg()).getSizeInBits() == 32);
+ auto RC = Is32Bit ? &AArch64::GPR32RegClass : &AArch64::GPR64RegClass;
+ return emitSUBS(MRI.createVirtualRegister(RC), LHS, RHS, MIRBuilder);
+}
+
MachineInstr *
AArch64InstructionSelector::emitCMN(MachineOperand &LHS, MachineOperand &RHS,
MachineIRBuilder &MIRBuilder) const {
@@ -4466,8 +4477,7 @@ MachineInstr *AArch64InstructionSelector::emitIntegerCompare(
// Fold the compare into a cmn or tst if possible.
if (auto FoldCmp = tryFoldIntegerCompare(LHS, RHS, Predicate, MIRBuilder))
return FoldCmp;
- auto Dst = MRI.cloneVirtualRegister(LHS.getReg());
- return emitSUBS(Dst, LHS, RHS, MIRBuilder);
+ return emitCMP(LHS, RHS, MIRBuilder);
}
MachineInstr *AArch64InstructionSelector::emitCSetForFCmp(
@@ -4874,9 +4884,8 @@ MachineInstr *AArch64InstructionSelector::emitConjunctionRec(
if (!CCOp) {
auto Dst = MRI.cloneVirtualRegister(LHS);
if (isa<GICmp>(Cmp))
- return emitSUBS(Dst, Cmp->getOperand(2), Cmp->getOperand(3), MIB);
- return emitFPCompare(Cmp->getOperand(2).getReg(),
- Cmp->getOperand(3).getReg(), MIB);
+ return emitCMP(Cmp->getOperand(2), Cmp->getOperand(3), MIB);
+ return emitFPCompare(LHS, RHS, MIB, CC);
}
// Otherwise produce a ccmp.
return emitConditionalComparison(LHS, RHS, CC, Predicate, OutCC, MIB);
|
… every time (NFC) CMN also has a function like this, we should do the same with CMP.
|
@MacDue Thoughts? |
|
@davemgreen Done! |
davemgreen
left a 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.
Thanks. You could do it in these other emit.. functions too if you wanted.
LGTM.
Thank you. Can you please merge? |
|
This is failing tests but a local rerun went OK. |
CMN also has a function like this, we should do the same with CMP.