diff --git a/llvm/lib/CodeGen/MachineRegisterInfo.cpp b/llvm/lib/CodeGen/MachineRegisterInfo.cpp index 937f63f6c5e00..93f4235cc7e97 100644 --- a/llvm/lib/CodeGen/MachineRegisterInfo.cpp +++ b/llvm/lib/CodeGen/MachineRegisterInfo.cpp @@ -448,9 +448,21 @@ void MachineRegisterInfo::clearKillFlags(Register Reg) const { } bool MachineRegisterInfo::isLiveIn(Register Reg) const { - for (const std::pair &LI : liveins()) + for (const std::pair &LI : liveins()) { if ((Register)LI.first == Reg || LI.second == Reg) return true; + + // Check if Reg is a subreg of live-in register + MCRegister PhysReg = LI.first; + if (!PhysReg.isValid() || !Reg.isPhysical()) + continue; + + const TargetRegisterInfo *TRI = getTargetRegisterInfo(); + if (all_of(TRI->regunits(Reg), [&](const MCRegUnit RegUnit) { + return llvm::is_contained(TRI->regunits(PhysReg), RegUnit); + })) + return true; + } return false; } diff --git a/llvm/test/CodeGen/AMDGPU/spill-partial-csr-sgpr-live-ins.mir b/llvm/test/CodeGen/AMDGPU/spill-partial-csr-sgpr-live-ins.mir index ab960a7084528..834ae2f94538b 100644 --- a/llvm/test/CodeGen/AMDGPU/spill-partial-csr-sgpr-live-ins.mir +++ b/llvm/test/CodeGen/AMDGPU/spill-partial-csr-sgpr-live-ins.mir @@ -1,25 +1,6 @@ # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py -# RUN: not --crash llc -mtriple=amdgcn-amd-amdhsa -verify-machineinstrs -run-pass=si-lower-sgpr-spills %s -o /dev/null 2>&1 | FileCheck -check-prefix=VERIFIER %s +# RUN: llc -mtriple=amdgcn-amd-amdhsa -verify-machineinstrs -run-pass=si-lower-sgpr-spills -o - %s| FileCheck %s -# FIXME : Currently, MRI's liveIn check for registers does not take the corresponding live-in's sub-registers into account. As a result -# in SILowerSGPRSpills, the SubReg spill gets marked KILLED even though its SuperReg is in the function Live-ins. This causes machine -# verifier to now fail at direct usage of that SubReg, which intially should not be any problem before adding spill. - -# VERIFIER: After SI lower SGPR spill instructions - -# VERIFIER: *** Bad machine code: Using an undefined physical register *** -# VERIFIER: - instruction: S_NOP 0, implicit $sgpr50 -# VERIFIER-NEXT: - operand 1: implicit $sgpr50 - -# VERIFIER: *** Bad machine code: Using an undefined physical register *** -# VERIFIER: - instruction: S_NOP 0, implicit $sgpr52 -# VERIFIER-NEXT: - operand 1: implicit $sgpr52 - -# VERIFIER: *** Bad machine code: Using an undefined physical register *** -# VERIFIER: - instruction: S_NOP 0, implicit $sgpr55 -# VERIFIER-NEXT: - operand 1: implicit $sgpr55 - -# VERIFIER: LLVM ERROR: Found 3 machine code errors. --- name: spill_partial_live_csr_sgpr_test tracksRegLiveness: true @@ -30,7 +11,22 @@ liveins: body: | bb.0: liveins: $sgpr50_sgpr51, $sgpr52_sgpr53, $sgpr54_sgpr55 - + ; CHECK-LABEL: name: spill_partial_live_csr_sgpr_test + ; CHECK: liveins: $sgpr50, $sgpr52, $sgpr53, $sgpr54, $sgpr55, $sgpr56, $vgpr63, $sgpr50_sgpr51, $sgpr52_sgpr53, $sgpr54_sgpr55 + ; CHECK-NEXT: {{ $}} + ; CHECK-NEXT: $vgpr63 = SI_SPILL_S32_TO_VGPR $sgpr50, 0, $vgpr63 + ; CHECK-NEXT: $vgpr63 = SI_SPILL_S32_TO_VGPR $sgpr52, 1, $vgpr63 + ; CHECK-NEXT: $vgpr63 = SI_SPILL_S32_TO_VGPR $sgpr53, 2, $vgpr63 + ; CHECK-NEXT: $vgpr63 = SI_SPILL_S32_TO_VGPR $sgpr54, 3, $vgpr63 + ; CHECK-NEXT: $vgpr63 = SI_SPILL_S32_TO_VGPR $sgpr55, 4, $vgpr63 + ; CHECK-NEXT: $vgpr63 = SI_SPILL_S32_TO_VGPR killed $sgpr56, 5, $vgpr63 + ; CHECK-NEXT: S_NOP 0, implicit $sgpr50 + ; CHECK-NEXT: $sgpr50 = S_MOV_B32 0 + ; CHECK-NEXT: S_NOP 0, implicit $sgpr52 + ; CHECK-NEXT: $sgpr52_sgpr53 = S_MOV_B64 0 + ; CHECK-NEXT: S_NOP 0, implicit $sgpr55 + ; CHECK-NEXT: $sgpr54_sgpr55 = S_MOV_B64 0 + ; CHECK-NEXT: $sgpr56 = S_MOV_B32 0 S_NOP 0, implicit $sgpr50 $sgpr50 = S_MOV_B32 0 S_NOP 0, implicit $sgpr52