Skip to content

Commit

Permalink
RenameIndependentSubregs: Fix handling of undef tied operands
Browse files Browse the repository at this point in the history
Ensure that, if updating a tied operand pair, to only update
that pair.

Differential Revision: https://reviews.llvm.org/D49052

Change-Id: Iac2cd6ba2bad8891ba6b621b69b0f99f84de1e96
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336593 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
searlmc1 authored and kzhuravl committed Sep 18, 2018
1 parent a2f9d18 commit 9adaebf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/CodeGen/RenameIndependentSubregs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ void RenameIndependentSubregs::rewriteOperands(const IntEqClasses &Classes,
if (!MO.isDef() && !MO.readsReg())
continue;

SlotIndex Pos = LIS->getInstructionIndex(*MO.getParent());
auto *MI = MO.getParent();
SlotIndex Pos = LIS->getInstructionIndex(*MI);
Pos = MO.isDef() ? Pos.getRegSlot(MO.isEarlyClobber())
: Pos.getBaseIndex();
unsigned SubRegIdx = MO.getSubReg();
Expand All @@ -245,11 +246,14 @@ void RenameIndependentSubregs::rewriteOperands(const IntEqClasses &Classes,
MO.setReg(VReg);

if (MO.isTied() && Reg != VReg) {
/// Undef use operands are not tracked in the equivalence class but need
/// to be update if they are tied.
MO.getParent()->substituteRegister(Reg, VReg, 0, TRI);

// substituteRegister breaks the iterator, so restart.
/// Undef use operands are not tracked in the equivalence class,
/// but need to be updated if they are tied; take care to only
/// update the tied operand.
unsigned OperandNo = MI->getOperandNo(&MO);
unsigned TiedIdx = MI->findTiedOperandIdx(OperandNo);
MI->getOperand(TiedIdx).setReg(VReg);

// above substitution breaks the iterator, so restart.
I = MRI->reg_nodbg_begin(Reg);
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/CodeGen/AMDGPU/rename-independent-subregs.mir
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
--- |
define amdgpu_kernel void @test0() { ret void }
define amdgpu_kernel void @test1() { ret void }
define amdgpu_kernel void @test2() { ret void }
...
---
# In the test below we have two independent def+use pairs of subregister1 which
Expand Down Expand Up @@ -67,3 +68,20 @@ body: |
S_NOP 0, implicit %0.sub2
...
# In this test, there are two pairs of tied operands
# within the inline asm statement:
# (1) %0.sub0 + %0.sub0 and (2) %0.sub1 + %0.sub1
# Check that renaming (2) does not inadvertently rename (1).
# CHECK-LABEL: name: test2
# CHECK: INLINEASM &"", 32, 327690, def undef %0.sub0, 327690, def dead %1.sub1, 2147483657, undef %0.sub0(tied-def 3), 2147549193, %1.sub1(tied-def 5)
name: test2
body: |
bb.0:
undef %0.sub0:vreg_64 = IMPLICIT_DEF
bb.1:
undef %0.sub1:vreg_64 = V_ALIGNBIT_B32 %0.sub0:vreg_64, %0.sub0:vreg_64, 16, implicit $exec
INLINEASM &"", 32, 327690, def undef %0.sub0:vreg_64, 327690, def %0.sub1:vreg_64, 2147483657, undef %0.sub0:vreg_64(tied-def 3), 2147549193, %0.sub1:vreg_64(tied-def 5)
S_BRANCH %bb.1
...

0 comments on commit 9adaebf

Please sign in to comment.