Skip to content

Commit dff3454

Browse files
committed
[TwoAddressInstruction] Tweak constraining of tied operands
In collectTiedOperands, when handling an undef use that is tied to a def, constrain the dst reg with the actual register class of the src reg, instead of with the register class from the instructions's MCInstrDesc. This makes a difference in some AMDGPU test cases like this, before: %16:sgpr_96 = INSERT_SUBREG undef %15:sgpr_96_with_sub0_sub1(tied-def 0), killed %11:sreg_64_xexec, %subreg.sub0_sub1 After, without this patch: undef %16.sub0_sub1:sgpr_96 = COPY killed %11:sreg_64_xexec This fails machine verification if you force it to run after TwoAddressInstruction (currently it is disabled) with: *** Bad machine code: Invalid register class for subregister index *** - function: s_load_constant_v3i32_align4 - basic block: %bb.0 (0xa011a88) - instruction: undef %16.sub0_sub1:sgpr_96 = COPY killed %11:sreg_64_xexec - operand 0: undef %16.sub0_sub1:sgpr_96 Register class SGPR_96 does not fully support subreg index 4 After, with this patch: undef %16.sub0_sub1:sgpr_96_with_sub0_sub1 = COPY killed %11:sreg_64_xexec See also svn r159120 which introduced the code to handle tied undef uses. Differential Revision: https://reviews.llvm.org/D110944
1 parent 61ecfc6 commit dff3454

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

llvm/lib/CodeGen/TwoAddressInstructionPass.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,6 @@ tryInstructionTransform(MachineBasicBlock::iterator &mi,
13351335
// Return true if any tied operands where found, including the trivial ones.
13361336
bool TwoAddressInstructionPass::
13371337
collectTiedOperands(MachineInstr *MI, TiedOperandMap &TiedOperands) {
1338-
const MCInstrDesc &MCID = MI->getDesc();
13391338
bool AnyOps = false;
13401339
unsigned NumOps = MI->getNumOperands();
13411340

@@ -1357,10 +1356,10 @@ collectTiedOperands(MachineInstr *MI, TiedOperandMap &TiedOperands) {
13571356
// Deal with undef uses immediately - simply rewrite the src operand.
13581357
if (SrcMO.isUndef() && !DstMO.getSubReg()) {
13591358
// Constrain the DstReg register class if required.
1360-
if (DstReg.isVirtual())
1361-
if (const TargetRegisterClass *RC = TII->getRegClass(MCID, SrcIdx,
1362-
TRI, *MF))
1363-
MRI->constrainRegClass(DstReg, RC);
1359+
if (DstReg.isVirtual()) {
1360+
const TargetRegisterClass *RC = MRI->getRegClass(SrcReg);
1361+
MRI->constrainRegClass(DstReg, RC);
1362+
}
13641363
SrcMO.setReg(DstReg);
13651364
SrcMO.setSubReg(0);
13661365
LLVM_DEBUG(dbgs() << "\t\trewrite undef:\t" << *MI);

llvm/test/CodeGen/AMDGPU/twoaddr-constrain.ll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
22
; RUN: llc -global-isel -march=amdgcn -mcpu=gfx900 -verify-machineinstrs -stop-after twoaddressinstruction < %s | FileCheck %s
33

4-
; FIXME: the operand "undef %16.sub0_sub1:sgpr_96" will fail machine
5-
; verification because sgpr_96 does not fully support sub0_sub1.
4+
; Check that %16 gets constrained to register class sgpr_96_with_sub0_sub1.
65
define amdgpu_ps <3 x i32> @s_load_constant_v3i32_align4(<3 x i32> addrspace(4)* inreg %ptr) {
76
; CHECK-LABEL: name: s_load_constant_v3i32_align4
87
; CHECK: bb.0 (%ir-block.0):
@@ -14,9 +13,9 @@ define amdgpu_ps <3 x i32> @s_load_constant_v3i32_align4(<3 x i32> addrspace(4)*
1413
; CHECK-NEXT: %0.sub1:sreg_64 = COPY killed [[COPY1]]
1514
; CHECK-NEXT: [[S_LOAD_DWORDX2_IMM:%[0-9]+]]:sreg_64_xexec = S_LOAD_DWORDX2_IMM %0, 0, 0 :: (load (<2 x s32>) from %ir.ptr, align 4, addrspace 4)
1615
; CHECK-NEXT: [[S_LOAD_DWORD_IMM:%[0-9]+]]:sreg_32_xm0_xexec = S_LOAD_DWORD_IMM killed %0, 8, 0 :: (load (s32) from %ir.ptr + 8, addrspace 4)
17-
; CHECK-NEXT: undef %16.sub0_sub1:sgpr_96 = COPY killed [[S_LOAD_DWORDX2_IMM]]
18-
; CHECK-NEXT: [[COPY2:%[0-9]+]]:sgpr_96 = COPY killed %16
19-
; CHECK-NEXT: [[COPY2]].sub2:sgpr_96 = COPY undef [[S_LOAD_DWORD_IMM]]
16+
; CHECK-NEXT: undef %16.sub0_sub1:sgpr_96_with_sub0_sub1 = COPY killed [[S_LOAD_DWORDX2_IMM]]
17+
; CHECK-NEXT: [[COPY2:%[0-9]+]]:sgpr_96_with_sub0_sub1 = COPY killed %16
18+
; CHECK-NEXT: [[COPY2]].sub2:sgpr_96_with_sub0_sub1 = COPY undef [[S_LOAD_DWORD_IMM]]
2019
; CHECK-NEXT: [[COPY3:%[0-9]+]]:sreg_32 = COPY [[COPY2]].sub0
2120
; CHECK-NEXT: $sgpr0 = COPY killed [[COPY3]]
2221
; CHECK-NEXT: [[COPY4:%[0-9]+]]:sreg_32 = COPY killed [[COPY2]].sub1

0 commit comments

Comments
 (0)