Skip to content

Commit fa3a685

Browse files
authored
[MachineLICM] Clear subregister kill flags (#67240)
When hosting a loop invariant instruction the resulting register must be live in all the basic blocks of the loop body and the killed flags of the register must be cleared. Before this patch killed flags of subregister to a hoisted superregister was not cleared in the loop body. This was found in an out of tree target, but the testcase mlicm-stack-write-check.mir was modified to trigger the case.
1 parent c75e3ea commit fa3a685

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

llvm/lib/CodeGen/MachineLICM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ void MachineLICMBase::AddToLiveIns(MCRegister Reg, MachineLoop *CurLoop) {
601601
for (MachineOperand &MO : MI.all_uses()) {
602602
if (!MO.getReg())
603603
continue;
604-
if (TRI->isSuperRegisterEq(Reg, MO.getReg()))
604+
if (TRI->regsOverlap(Reg, MO.getReg()))
605605
MO.setIsKill(false);
606606
}
607607
}

llvm/test/CodeGen/AArch64/mlicm-stack-write-check.mir

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,44 @@ body: |
1717
bb.1:
1818
; CHECK-LABEL: bb.1:
1919
; CHECK-NOT: $x2 = LDRXui %stack.0, 0
20+
; CHECK: $x0 = ADDXrr $x0, $x2
2021
liveins: $x0
2122
DBG_VALUE %stack.0, 0
2223
$x2 = LDRXui %stack.0, 0 :: (load (s64) from %stack.0)
23-
$x0 = ADDXrr $x0, $x2
24-
$xzr = SUBSXri $x0, 1, 0, implicit-def $nzcv
24+
$x0 = ADDXrr $x0, killed $x2
25+
$xzr = SUBSXri killed $x0, 1, 0, implicit-def $nzcv
26+
Bcc 11, %bb.1, implicit $nzcv
27+
B %bb.2
28+
29+
bb.2:
30+
liveins: $x0
31+
%0 = COPY $x0
32+
%0 = COPY $x0 ; Force isSSA = false.
33+
...
34+
---
35+
name: test2
36+
tracksRegLiveness: true
37+
registers:
38+
- { id: 0, class: gpr64 }
39+
stack:
40+
- { id: 0, size: 8, type: spill-slot }
41+
body: |
42+
bb.0:
43+
; CHECK-LABEL: name: test2
44+
; CHECK-LABEL: bb.0:
45+
; CHECK: $x2 = LDRXui %stack.0, 0
46+
liveins: $x0, $x1, $x2
47+
B %bb.1
48+
49+
bb.1:
50+
; CHECK-LABEL: bb.1:
51+
; CHECK-NOT: $x2 = LDRXui %stack.0, 0
52+
; CHECK: $w0 = ADDWrr $w0, $w2
53+
liveins: $x0
54+
DBG_VALUE %stack.0, 0
55+
$x2 = LDRXui %stack.0, 0 :: (load (s64) from %stack.0)
56+
$w0 = ADDWrr $w0, killed $w2
57+
$wzr = SUBSWri killed $w0, 1, 0, implicit-def $nzcv
2558
Bcc 11, %bb.1, implicit $nzcv
2659
B %bb.2
2760

0 commit comments

Comments
 (0)