Skip to content

X86: Remove hack in shouldRewriteCopySrc for subregister handling #125224

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

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/lib/CodeGen/TargetRegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 0 additions & 15 deletions llvm/lib/Target/X86/X86RegisterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions llvm/lib/Target/X86/X86RegisterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
27 changes: 27 additions & 0 deletions llvm/test/CodeGen/X86/pr41619_reduced.mir
Original file line number Diff line number Diff line change
@@ -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

...