summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2017-10-16 22:28:40 +0000
committerQuentin Colombet <qcolombet@apple.com>2017-10-16 22:28:40 +0000
commit364dbc593b0d9275c891a735006adc6d68cab6b4 (patch)
treebbeb61da9fb6fde7e6b7daae353ac7f56734e9b0
parente4ffbabdc0c427086b7046ba13e1e7450689b9cc (diff)
Re-apply [AArch64][RegisterBankInfo] Use the statically computed mappings for COPY
This reverts commit r315823, thus re-applying r315781. Also make sure we don't use G_BITCAST mapping for non-generic registers. Non-generic registers don't have a type but do have a reg bank. Something the COPY mapping now how to deal with but the G_BITCAST mapping don't. -- Original Commit Message -- We use to resort on the generic implementation to get the mappings for COPYs. The generic implementation resorts on table lookup and dynamically allocated objects to get the valid mappings. Given we already know how to map G_BITCAST and have the static mappings for them, use that code path for COPY as well. This is much more efficient. Improve the compile time of RegBankSelect by up to 20%. Note: When we eventually generate all the mappings via TableGen, we wouldn't have to do that dance to shave compile time. The intent of this change was to make sure that moving to static structure really pays off. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315947 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/AArch64/AArch64RegisterBankInfo.cpp39
-rw-r--r--test/CodeGen/AArch64/GlobalISel/arm64-regbankselect.mir65
2 files changed, 100 insertions, 4 deletions
diff --git a/lib/Target/AArch64/AArch64RegisterBankInfo.cpp b/lib/Target/AArch64/AArch64RegisterBankInfo.cpp
index 04306d63581..508d3a6f24f 100644
--- a/lib/Target/AArch64/AArch64RegisterBankInfo.cpp
+++ b/lib/Target/AArch64/AArch64RegisterBankInfo.cpp
@@ -415,12 +415,10 @@ AArch64RegisterBankInfo::getSameKindOfOperandsMapping(
const RegisterBankInfo::InstructionMapping &
AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
const unsigned Opc = MI.getOpcode();
- const MachineFunction &MF = *MI.getParent()->getParent();
- const MachineRegisterInfo &MRI = MF.getRegInfo();
// Try the default logic for non-generic instructions that are either copies
// or already have some operands assigned to banks.
- if (!isPreISelGenericOpcode(Opc) ||
+ if ((Opc != TargetOpcode::COPY && !isPreISelGenericOpcode(Opc)) ||
Opc == TargetOpcode::G_PHI) {
const RegisterBankInfo::InstructionMapping &Mapping =
getInstrMappingImpl(MI);
@@ -428,6 +426,11 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
return Mapping;
}
+ const MachineFunction &MF = *MI.getParent()->getParent();
+ const MachineRegisterInfo &MRI = MF.getRegInfo();
+ const TargetSubtargetInfo &STI = MF.getSubtarget();
+ const TargetRegisterInfo &TRI = *STI.getRegisterInfo();
+
switch (Opc) {
// G_{F|S|U}REM are not listed because they are not legal.
// Arithmetic ops.
@@ -451,6 +454,33 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
case TargetOpcode::G_FMUL:
case TargetOpcode::G_FDIV:
return getSameKindOfOperandsMapping(MI);
+ case TargetOpcode::COPY: {
+ unsigned DstReg = MI.getOperand(0).getReg();
+ unsigned SrcReg = MI.getOperand(1).getReg();
+ // Check if one of the register is not a generic register.
+ if ((TargetRegisterInfo::isPhysicalRegister(DstReg) ||
+ !MRI.getType(DstReg).isValid()) ||
+ (TargetRegisterInfo::isPhysicalRegister(SrcReg) ||
+ !MRI.getType(SrcReg).isValid())) {
+ const RegisterBank *DstRB = getRegBank(DstReg, MRI, TRI);
+ const RegisterBank *SrcRB = getRegBank(SrcReg, MRI, TRI);
+ if (!DstRB)
+ DstRB = SrcRB;
+ else if (!SrcRB)
+ SrcRB = DstRB;
+ // If both RB are null that means both registers are generic.
+ // We shouldn't be here.
+ assert(DstRB && SrcRB && "Both RegBank were nullptr");
+ unsigned Size = getSizeInBits(DstReg, MRI, TRI);
+ return getInstructionMapping(
+ DefaultMappingID, copyCost(*DstRB, *SrcRB, Size),
+ getCopyMapping(DstRB->getID(), SrcRB->getID(), Size),
+ // We only care about the mapping of the destination.
+ /*NumOperands*/ 1);
+ }
+ // Both registers are generic, use G_BITCAST.
+ LLVM_FALLTHROUGH;
+ }
case TargetOpcode::G_BITCAST: {
LLT DstTy = MRI.getType(MI.getOperand(0).getReg());
LLT SrcTy = MRI.getType(MI.getOperand(1).getReg());
@@ -464,7 +494,8 @@ AArch64RegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
return getInstructionMapping(
DefaultMappingID, copyCost(DstRB, SrcRB, Size),
getCopyMapping(DstRB.getID(), SrcRB.getID(), Size),
- /*NumOperands*/ 2);
+ // We only care about the mapping of the destination for COPY.
+ /*NumOperands*/ Opc == TargetOpcode::G_BITCAST ? 2 : 1);
}
default:
break;
diff --git a/test/CodeGen/AArch64/GlobalISel/arm64-regbankselect.mir b/test/CodeGen/AArch64/GlobalISel/arm64-regbankselect.mir
index 1d4781a9d98..03861b19a77 100644
--- a/test/CodeGen/AArch64/GlobalISel/arm64-regbankselect.mir
+++ b/test/CodeGen/AArch64/GlobalISel/arm64-regbankselect.mir
@@ -67,6 +67,8 @@
define void @bitcast_s64_gpr_fpr() { ret void }
define void @bitcast_s64_fpr_gpr() { ret void }
define void @bitcast_s128() { ret void }
+ define void @copy_s128() { ret void }
+ define void @copy_s128_from_load() { ret void }
define i64 @greedyWithChainOfComputation(i64 %arg1, <2 x i32>* %addr) {
%varg1 = bitcast i64 %arg1 to <2 x i32>
@@ -643,6 +645,69 @@ body: |
...
---
+# CHECK-LABEL: name: copy_s128
+# This test checks that we issue the proper mapping
+# for copy of size > 64.
+# The mapping should be the same as G_BITCAST.
+name: copy_s128
+legalized: true
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: _}
+ - { id: 1, class: _}
+ - { id: 2, class: _}
+ - { id: 3, class: _}
+ - { id: 4, class: _}
+# CHECK: registers:
+# CHECK: - { id: 2, class: fpr, preferred-register: '' }
+# CHECK: - { id: 3, class: fpr, preferred-register: '' }
+# CHECK: - { id: 4, class: fpr, preferred-register: '' }
+# CHECK: %4(s128) = COPY %3(s128)
+# CHECK-NEXT: %2(<2 x s64>) = G_BITCAST %4(s128)
+body: |
+ bb.1:
+ liveins: %x0, %x1
+ %0(s64) = COPY %x0
+ %1(s64) = COPY %x1
+ %3(s128) = G_MERGE_VALUES %0(s64), %1(s64)
+ %4(s128) = COPY %3(s128)
+ %2(<2 x s64>) = G_BITCAST %4(s128)
+ %q0 = COPY %2(<2 x s64>)
+ RET_ReallyLR implicit %q0
+
+...
+
+---
+# CHECK-LABEL: name: copy_s128_from_load
+# This test checks that we issue the proper mapping
+# for copy of size > 64 when the input is neither
+# a physcal register nor a generic register.
+# This used to crash when we moved to the statically
+# computed mapping, because we were assuming non-physregs
+# were generic registers and thus have a type, whereas
+# it is not necessarily the case.
+name: copy_s128_from_load
+legalized: true
+tracksRegLiveness: true
+registers:
+ - { id: 0, class: fpr128}
+ - { id: 1, class: _}
+# CHECK: registers:
+# CHECK: - { id: 0, class: fpr128, preferred-register: '' }
+# CHECK: - { id: 1, class: fpr, preferred-register: '' }
+# CHECK: %1(s128) = COPY %0
+body: |
+ bb.1:
+ liveins: %x0
+ %0 = LDRQui killed %x0, 0
+ %1(s128) = COPY %0
+ %q0 = COPY %1(s128)
+ RET_ReallyLR implicit %q0
+
+...
+
+
+---
# Make sure the greedy mode is able to take advantage of the
# alternative mappings of G_LOAD to coalesce the whole chain
# of computation on GPR.