Skip to content

Commit 585406f

Browse files
author
Yuanke Luo
committed
[RegAlloc] Fix register's live range for early-clobber
When rematerialize a virtual register the register may be early clobbered. However rematerializeAt(...) just return the slot index of Slot_Register which cause mis-calculating live range for the register
1 parent 1dac302 commit 585406f

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

llvm/lib/CodeGen/LiveRangeEdit.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,12 @@ SlotIndex LiveRangeEdit::rematerializeAt(MachineBasicBlock &MBB,
190190
Rematted.insert(RM.ParentVNI);
191191
++NumReMaterialization;
192192

193+
bool EarlyClobber = MI->getOperand(0).isEarlyClobber();
193194
if (ReplaceIndexMI)
194-
return LIS.ReplaceMachineInstrInMaps(*ReplaceIndexMI, *MI).getRegSlot();
195-
return LIS.getSlotIndexes()->insertMachineInstrInMaps(*MI, Late).getRegSlot();
195+
return LIS.ReplaceMachineInstrInMaps(*ReplaceIndexMI, *MI)
196+
.getRegSlot(EearlyClobber);
197+
return LIS.getSlotIndexes()->insertMachineInstrInMaps(*MI, Late).getRegSlot(
198+
EarlyClobber);
196199
}
197200

198201
void LiveRangeEdit::eraseVirtReg(Register Reg) {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# RUN: llc -mtriple=i386-unknown-linux-gnu -start-before=twoaddressinstruction -verify-machineinstrs -o - %s
2+
3+
# Test register live range that is split from rematerializing. The live range should
4+
# start with Slot_EarlyClobber instead of Slot_Register. Machineverifer can check it.
5+
6+
--- |
7+
target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128"
8+
target triple = "i386-unknown-linux-gnu"
9+
10+
@g = external constant [2 x i32], align 4
11+
12+
; Function Attrs: nounwind
13+
define i32 @test(i32 noundef %a) #0 {
14+
entry:
15+
%0 = xor i32 %a, %a
16+
tail call void asm sideeffect "", "~{ebp},~{eax},~{ebx},~{ecx},~{edx},~{esi},~{edi},~{dirflag},~{fpsr},~{flags}"()
17+
br i1 undef, label %if, label %else
18+
19+
if: ; preds = %entry
20+
%add = add i32 %0, 1
21+
br label %exit
22+
23+
else: ; preds = %entry
24+
%shl = shl i32 %0, 1
25+
br label %exit
26+
27+
exit: ; preds = %else, %if
28+
%phi = phi i32 [ %add, %if ], [ %shl, %else ]
29+
ret i32 %phi
30+
}
31+
32+
attributes #0 = { nounwind }
33+
34+
...
35+
---
36+
name: test
37+
alignment: 16
38+
tracksRegLiveness: true
39+
registers:
40+
- { id: 0, class: gr32_abcd }
41+
- { id: 1, class: gr32 }
42+
- { id: 2, class: gr32 }
43+
- { id: 3, class: gr32 }
44+
- { id: 4, class: gr8 }
45+
- { id: 5, class: gr32 }
46+
frameInfo:
47+
maxAlignment: 4
48+
fixedStack:
49+
- { id: 0, size: 4, alignment: 16, isImmutable: true }
50+
machineFunctionInfo: {}
51+
body: |
52+
bb.0.entry:
53+
successors: %bb.1, %bb.2
54+
55+
early-clobber %0:gr32_abcd = MOV32r0 implicit-def dead $eflags
56+
INLINEASM &"", 1 /* sideeffect attdialect */, 12 /* clobber */, implicit-def dead early-clobber $ebp, 12 /* clobber */, implicit-def dead early-clobber $eax, 12 /* clobber */, implicit-def dead early-clobber $ebx, 12 /* clobber */, implicit-def dead early-clobber $ecx, 12 /* clobber */, implicit-def dead early-clobber $edx, 12 /* clobber */, implicit-def dead early-clobber $esi, 12 /* clobber */, implicit-def dead early-clobber $edi, 12 /* clobber */, implicit-def dead early-clobber $df, 12 /* clobber */, implicit-def early-clobber $fpsw, 12 /* clobber */, implicit-def dead early-clobber $eflags
57+
%4:gr8 = COPY %0.sub_8bit
58+
TEST8rr killed %4, %4, implicit-def $eflags
59+
JCC_1 %bb.2, 5, implicit killed $eflags
60+
JMP_1 %bb.1
61+
62+
bb.1.if:
63+
%1:gr32 = MOV32ri 1
64+
%5:gr32 = COPY killed %1
65+
JMP_1 %bb.3
66+
67+
bb.2.else:
68+
%5:gr32 = COPY killed %0
69+
70+
bb.3.exit:
71+
%3:gr32 = COPY killed %5
72+
$eax = COPY killed %3
73+
RET 0, killed $eax
74+
75+
...

0 commit comments

Comments
 (0)