Skip to content

Commit a4834ad

Browse files
committed
RegisterCoalescer: Shrink main range after shrinking subranges
If the subregister uses were dead, this would leave the main range segment pointing to a deleted instruction. Not sure if this should try to avoid shrinking if we know we don't have dead components.
1 parent b259027 commit a4834ad

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

llvm/lib/CodeGen/RegisterCoalescer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,7 @@ bool RegisterCoalescer::joinCopy(MachineInstr *CopyMI, bool &Again) {
21032103
LLVM_DEBUG(dbgs() << "Shrink LaneUses (Lane " << PrintLaneMask(S.LaneMask)
21042104
<< ")\n");
21052105
LIS->shrinkToUses(S, LI.reg());
2106+
ShrinkMainRange = true;
21062107
}
21072108
LI.removeEmptySubRanges();
21082109
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-coalescing -run-pass=simple-register-coalescing -o - %s | FileCheck %s
3+
4+
# Check that there's no "Live segment doesn't end at a valid
5+
# instruction" failure after coalescing %0 into %2, which is
6+
# ultimately a pair of dead copies.
7+
8+
---
9+
name: coalesce_into_dead_subreg_copy
10+
tracksRegLiveness: true
11+
machineFunctionInfo:
12+
isEntryFunction: true
13+
scratchRSrcReg: '$sgpr0_sgpr1_sgpr2_sgpr3'
14+
stackPtrOffsetReg: '$sgpr32'
15+
occupancy: 8
16+
body: |
17+
; CHECK-LABEL: name: coalesce_into_dead_subreg_copy
18+
; CHECK: bb.0:
19+
; CHECK-NEXT: successors: %bb.1(0x80000000)
20+
; CHECK-NEXT: {{ $}}
21+
; CHECK-NEXT: dead %2:sreg_64_xexec = S_LOAD_DWORDX2_IMM undef %1:sgpr_64, 24, 0 :: (dereferenceable invariant load (s64), addrspace 4)
22+
; CHECK-NEXT: S_BRANCH %bb.1
23+
; CHECK-NEXT: {{ $}}
24+
; CHECK-NEXT: bb.1:
25+
bb.0:
26+
%0:sreg_64_xexec = S_LOAD_DWORDX2_IMM undef %1:sgpr_64, 24, 0 :: (dereferenceable invariant load (s64), addrspace 4)
27+
undef %2.sub0:sreg_64 = COPY %0.sub0:sreg_64_xexec
28+
%2.sub1:sreg_64 = COPY killed %0.sub1:sreg_64_xexec
29+
S_BRANCH %bb.1
30+
31+
bb.1:
32+
33+
...

llvm/test/CodeGen/AMDGPU/loop-live-out-copy-undef-subrange.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define <3 x float> @liveout_undef_subrange(<3 x float> %arg) {
1010
; CHECK: ; %bb.0: ; %bb
1111
; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
1212
; CHECK-NEXT: v_add_f32_e32 v3, v2, v2
13-
; CHECK-NEXT: v_add_f32_e32 v1, v1, v1
13+
; CHECK-NEXT: ; kill: killed $vgpr1
1414
; CHECK-NEXT: v_add_f32_e32 v0, v0, v0
1515
; CHECK-NEXT: .LBB0_1: ; %bb1
1616
; CHECK-NEXT: ; =>This Loop Header: Depth=1

0 commit comments

Comments
 (0)