Skip to content

Commit d9beff0

Browse files
committed
[RegisterCoalescer] Fix IMPLICIT_DEF init removal for a register on joining
This patch removes redundant IMPLICIT_DEF for subregs which was leading to incorrect register initialization on joining in some cases. Reviewed by: qcolombet Differential revision: https://reviews.llvm.org/D82258
1 parent c05cf1c commit d9beff0

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

llvm/lib/CodeGen/RegisterCoalescer.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,14 +2686,8 @@ JoinVals::analyzeValue(unsigned ValNo, JoinVals &Other) {
26862686
return CR_Replace;
26872687

26882688
// Check for simple erasable conflicts.
2689-
if (DefMI->isImplicitDef()) {
2690-
// We need the def for the subregister if there is nothing else live at the
2691-
// subrange at this point.
2692-
if (TrackSubRegLiveness
2693-
&& (V.WriteLanes & (OtherV.ValidLanes | OtherV.WriteLanes)).none())
2694-
return CR_Replace;
2689+
if (DefMI->isImplicitDef())
26952690
return CR_Erase;
2696-
}
26972691

26982692
// Include the non-conflict where DefMI is a coalescable copy that kills
26992693
// OtherVNI. We still want the copy erased and value numbers merged.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -march=amdgcn -mcpu=gfx803 -run-pass simple-register-coalescing -verify-machineinstrs -o - %s | FileCheck %s
3+
4+
# Register coalescer is going to eliminate %2:sgpr_32 = COPY %1.sub0 from bb.1
5+
# by joining %2 and %1.sub0 into %0.sub0 register. Check that when this happen
6+
# the implicit intialization of %0.sub0 in the bb.2 have undef flag
7+
# for the MIR to be valid.
8+
9+
---
10+
name: coalescing_makes_lane_undefined
11+
tracksRegLiveness: true
12+
body: |
13+
; CHECK-LABEL: name: coalescing_makes_lane_undefined
14+
; CHECK: bb.0:
15+
; CHECK: successors: %bb.1(0x40000000), %bb.2(0x40000000)
16+
; CHECK: S_CBRANCH_SCC0 %bb.2, implicit undef $scc
17+
; CHECK: bb.1:
18+
; CHECK: successors: %bb.3(0x80000000)
19+
; CHECK: undef %0.sub0:sgpr_64 = S_MOV_B32 1
20+
; CHECK: %0.sub1:sgpr_64 = S_MOV_B32 2
21+
; CHECK: S_BRANCH %bb.3
22+
; CHECK: bb.2:
23+
; CHECK: successors: %bb.3(0x80000000)
24+
; CHECK: undef %0.sub0:sgpr_64 = IMPLICIT_DEF
25+
; CHECK: bb.3:
26+
; CHECK: S_NOP 0, implicit %0.sub0
27+
; CHECK: S_NOP 0, implicit %0
28+
bb.0:
29+
successors: %bb.1, %bb.2
30+
S_CBRANCH_SCC0 %bb.2, implicit undef $scc
31+
32+
bb.1:
33+
successors: %bb.3
34+
undef %1.sub0:sgpr_64 = S_MOV_B32 1
35+
%1.sub1:sgpr_64 = S_MOV_B32 2
36+
%2:sgpr_32 = COPY %1.sub0 ; copy to be joined
37+
S_BRANCH %bb.3
38+
39+
bb.2:
40+
successors: %bb.3
41+
%2:sgpr_32 = IMPLICIT_DEF
42+
undef %1.sub0:sgpr_64 = IMPLICIT_DEF
43+
%1.sub1:sgpr_64 = IMPLICIT_DEF
44+
45+
bb.3:
46+
S_NOP 0, implicit killed %2
47+
S_NOP 0, implicit killed %1
48+
49+
...

0 commit comments

Comments
 (0)