Skip to content

Commit d6703bb

Browse files
authored
[GISel][AArch64] Create emitCMP instead of cloning a virtual register (NFC) (#155262)
CMN also has a function like this, we should do the same with CMP.
1 parent 0acdbd5 commit d6703bb

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ class AArch64InstructionSelector : public InstructionSelector {
310310
MachineIRBuilder &MIRBuilder) const;
311311
MachineInstr *emitSBCS(Register Dst, MachineOperand &LHS, MachineOperand &RHS,
312312
MachineIRBuilder &MIRBuilder) const;
313+
MachineInstr *emitCMP(MachineOperand &LHS, MachineOperand &RHS,
314+
MachineIRBuilder &MIRBuilder) const;
313315
MachineInstr *emitCMN(MachineOperand &LHS, MachineOperand &RHS,
314316
MachineIRBuilder &MIRBuilder) const;
315317
MachineInstr *emitTST(MachineOperand &LHS, MachineOperand &RHS,
@@ -4412,6 +4414,15 @@ AArch64InstructionSelector::emitSBCS(Register Dst, MachineOperand &LHS,
44124414
return emitInstr(OpcTable[Is32Bit], {Dst}, {LHS, RHS}, MIRBuilder);
44134415
}
44144416

4417+
MachineInstr *
4418+
AArch64InstructionSelector::emitCMP(MachineOperand &LHS, MachineOperand &RHS,
4419+
MachineIRBuilder &MIRBuilder) const {
4420+
MachineRegisterInfo &MRI = MIRBuilder.getMF().getRegInfo();
4421+
bool Is32Bit = MRI.getType(LHS.getReg()).getSizeInBits() == 32;
4422+
auto RC = Is32Bit ? &AArch64::GPR32RegClass : &AArch64::GPR64RegClass;
4423+
return emitSUBS(MRI.createVirtualRegister(RC), LHS, RHS, MIRBuilder);
4424+
}
4425+
44154426
MachineInstr *
44164427
AArch64InstructionSelector::emitCMN(MachineOperand &LHS, MachineOperand &RHS,
44174428
MachineIRBuilder &MIRBuilder) const {
@@ -4464,8 +4475,7 @@ MachineInstr *AArch64InstructionSelector::emitIntegerCompare(
44644475
// Fold the compare into a cmn or tst if possible.
44654476
if (auto FoldCmp = tryFoldIntegerCompare(LHS, RHS, Predicate, MIRBuilder))
44664477
return FoldCmp;
4467-
auto Dst = MRI.cloneVirtualRegister(LHS.getReg());
4468-
return emitSUBS(Dst, LHS, RHS, MIRBuilder);
4478+
return emitCMP(LHS, RHS, MIRBuilder);
44694479
}
44704480

44714481
MachineInstr *AArch64InstructionSelector::emitCSetForFCmp(
@@ -4870,9 +4880,8 @@ MachineInstr *AArch64InstructionSelector::emitConjunctionRec(
48704880

48714881
// Produce a normal comparison if we are first in the chain
48724882
if (!CCOp) {
4873-
auto Dst = MRI.cloneVirtualRegister(LHS);
48744883
if (isa<GICmp>(Cmp))
4875-
return emitSUBS(Dst, Cmp->getOperand(2), Cmp->getOperand(3), MIB);
4884+
return emitCMP(Cmp->getOperand(2), Cmp->getOperand(3), MIB);
48764885
return emitFPCompare(Cmp->getOperand(2).getReg(),
48774886
Cmp->getOperand(3).getReg(), MIB);
48784887
}

0 commit comments

Comments
 (0)