diff --git a/llvm/lib/CodeGen/TargetRegisterInfo.cpp b/llvm/lib/CodeGen/TargetRegisterInfo.cpp index 77a4c74f1b38b..e735c904e1b60 100644 --- a/llvm/lib/CodeGen/TargetRegisterInfo.cpp +++ b/llvm/lib/CodeGen/TargetRegisterInfo.cpp @@ -420,7 +420,10 @@ static bool shareSameRegisterFile(const TargetRegisterInfo &TRI, const TargetRegisterClass *SrcRC, unsigned SrcSubReg) { // Same register class. - if (DefRC == SrcRC) + // + // When processing uncoalescable copies / bitcasts, it is possible we reach + // here with the same register class, but mismatched subregister indices. + if (DefRC == SrcRC && DefSubReg == SrcSubReg) return true; // Both operands are sub registers. Check if they share a register class. diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp index 4faf8bca4f9e0..af1060519ae5c 100644 --- a/llvm/lib/Target/X86/X86RegisterInfo.cpp +++ b/llvm/lib/Target/X86/X86RegisterInfo.cpp @@ -224,21 +224,6 @@ X86RegisterInfo::getPointerRegClass(const MachineFunction &MF, } } -bool X86RegisterInfo::shouldRewriteCopySrc(const TargetRegisterClass *DefRC, - unsigned DefSubReg, - const TargetRegisterClass *SrcRC, - unsigned SrcSubReg) const { - // Prevent rewriting a copy where the destination size is larger than the - // input size. See PR41619. - // FIXME: Should this be factored into the base implementation somehow. - if (DefRC->hasSuperClassEq(&X86::GR64RegClass) && DefSubReg == 0 && - SrcRC->hasSuperClassEq(&X86::GR64RegClass) && SrcSubReg == X86::sub_32bit) - return false; - - return TargetRegisterInfo::shouldRewriteCopySrc(DefRC, DefSubReg, - SrcRC, SrcSubReg); -} - const TargetRegisterClass * X86RegisterInfo::getGPRsForTailCall(const MachineFunction &MF) const { const Function &F = MF.getFunction(); diff --git a/llvm/lib/Target/X86/X86RegisterInfo.h b/llvm/lib/Target/X86/X86RegisterInfo.h index 68ee372f27b14..009d2a8c7ac3a 100644 --- a/llvm/lib/Target/X86/X86RegisterInfo.h +++ b/llvm/lib/Target/X86/X86RegisterInfo.h @@ -70,11 +70,6 @@ class X86RegisterInfo final : public X86GenRegisterInfo { getLargestLegalSuperClass(const TargetRegisterClass *RC, const MachineFunction &MF) const override; - bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC, - unsigned DefSubReg, - const TargetRegisterClass *SrcRC, - unsigned SrcSubReg) const override; - /// getPointerRegClass - Returns a TargetRegisterClass used for pointer /// values. const TargetRegisterClass * diff --git a/llvm/test/CodeGen/X86/pr41619_reduced.mir b/llvm/test/CodeGen/X86/pr41619_reduced.mir new file mode 100644 index 0000000000000..5dc2eb60e8141 --- /dev/null +++ b/llvm/test/CodeGen/X86/pr41619_reduced.mir @@ -0,0 +1,27 @@ +# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5 +# RUN: llc -mtriple=x86_64-- -mattr=+avx2 -run-pass=peephole-opt -o - %s | FileCheck %s + +# When trying to coalesce the operand of VMOVSDto64rr, a query would +# be made with the same register class but the source has a +# subregister and the result does not. +--- +name: uncoalescable_copy_queries_same_regclass_with_only_one_subreg +tracksRegLiveness: true +isSSA: true +body: | + bb.0: + liveins: $rax + + ; CHECK-LABEL: name: uncoalescable_copy_queries_same_regclass_with_only_one_subreg + ; CHECK: liveins: $rax + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr64 = COPY $rax + ; CHECK-NEXT: [[COPY1:%[0-9]+]]:vr128 = COPY [[COPY]].sub_32bit + ; CHECK-NEXT: [[VMOVSDto64rr:%[0-9]+]]:gr64 = VMOVSDto64rr [[COPY1]] + ; CHECK-NEXT: RET 0, implicit [[VMOVSDto64rr]] + %0:gr64 = COPY $rax + %1:vr128 = COPY %0.sub_32bit + %2:gr64 = VMOVSDto64rr %1 + RET 0, implicit %2 + +...