Skip to content

Commit 6076b07

Browse files
authored
X86: Use LiveRegUnits in findDeadCallerSavedReg (#156817)
1 parent 9893dab commit 6076b07

File tree

5 files changed

+21
-27
lines changed

5 files changed

+21
-27
lines changed

llvm/lib/Target/X86/X86RegisterInfo.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,6 @@ unsigned X86RegisterInfo::findDeadCallerSavedReg(
10021002
if (MF->callsEHReturn())
10031003
return 0;
10041004

1005-
const TargetRegisterClass &AvailableRegs = *getGPRsForTailCall(*MF);
1006-
10071005
if (MBBI == MBB.end())
10081006
return 0;
10091007

@@ -1025,20 +1023,16 @@ unsigned X86RegisterInfo::findDeadCallerSavedReg(
10251023
case X86::TCRETURNmi64:
10261024
case X86::EH_RETURN:
10271025
case X86::EH_RETURN64: {
1028-
SmallSet<uint16_t, 8> Uses;
1029-
for (MachineOperand &MO : MBBI->operands()) {
1030-
if (!MO.isReg() || MO.isDef())
1031-
continue;
1032-
Register Reg = MO.getReg();
1033-
if (!Reg)
1034-
continue;
1035-
for (MCRegAliasIterator AI(Reg, this, true); AI.isValid(); ++AI)
1036-
Uses.insert(*AI);
1026+
LiveRegUnits LRU(*this);
1027+
LRU.addLiveOuts(MBB);
1028+
LRU.stepBackward(*MBBI);
1029+
1030+
const TargetRegisterClass &RC =
1031+
Is64Bit ? X86::GR64_NOSPRegClass : X86::GR32_NOSPRegClass;
1032+
for (MCRegister Reg : RC) {
1033+
if (LRU.available(Reg))
1034+
return Reg;
10371035
}
1038-
1039-
for (auto CS : AvailableRegs)
1040-
if (!Uses.count(CS) && CS != X86::RIP && CS != X86::RSP && CS != X86::ESP)
1041-
return CS;
10421036
}
10431037
}
10441038

llvm/test/CodeGen/X86/apx/push2-pop2-cfi-seh.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ define i32 @csr6_alloc16(ptr %argv) {
8181
; LIN-NEXT: .cfi_def_cfa_offset 32
8282
; LIN-NEXT: pop2 %rbp, %r15
8383
; LIN-NEXT: .cfi_def_cfa_offset 16
84-
; LIN-NEXT: popq %rcx
84+
; LIN-NEXT: popq %rax
8585
; LIN-NEXT: .cfi_def_cfa_offset 8
8686
; LIN-NEXT: retq
8787
;
@@ -116,7 +116,7 @@ define i32 @csr6_alloc16(ptr %argv) {
116116
; LIN-PPX-NEXT: .cfi_def_cfa_offset 32
117117
; LIN-PPX-NEXT: pop2p %rbp, %r15
118118
; LIN-PPX-NEXT: .cfi_def_cfa_offset 16
119-
; LIN-PPX-NEXT: popq %rcx
119+
; LIN-PPX-NEXT: popq %rax
120120
; LIN-PPX-NEXT: .cfi_def_cfa_offset 8
121121
; LIN-PPX-NEXT: retq
122122
;
@@ -180,7 +180,7 @@ define i32 @csr6_alloc16(ptr %argv) {
180180
; WIN-NEXT: pop2 %rbp, %rbx
181181
; WIN-NEXT: pop2 %r13, %r12
182182
; WIN-NEXT: pop2 %r15, %r14
183-
; WIN-NEXT: popq %rcx
183+
; WIN-NEXT: popq %rax
184184
; WIN-NEXT: .seh_endepilogue
185185
; WIN-NEXT: retq
186186
; WIN-NEXT: .seh_endproc
@@ -211,7 +211,7 @@ define i32 @csr6_alloc16(ptr %argv) {
211211
; WIN-PPX-NEXT: pop2p %rbp, %rbx
212212
; WIN-PPX-NEXT: pop2p %r13, %r12
213213
; WIN-PPX-NEXT: pop2p %r15, %r14
214-
; WIN-PPX-NEXT: popq %rcx
214+
; WIN-PPX-NEXT: popq %rax
215215
; WIN-PPX-NEXT: .seh_endepilogue
216216
; WIN-PPX-NEXT: retq
217217
; WIN-PPX-NEXT: .seh_endproc

llvm/test/CodeGen/X86/lvi-hardening-ret.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ entry:
4141
%add = add nsw i32 %0, %1
4242
ret i32 %add
4343
; CHECK-NOT: retq
44-
; CHECK: popq %rcx
44+
; CHECK: popq %rsi
4545
; CHECK-NEXT: lfence
46-
; CHECK-NEXT: jmpq *%rcx
46+
; CHECK-NEXT: jmpq *%rsi
4747
}
4848

4949
; Function Attrs: noinline nounwind optnone uwtable
@@ -52,9 +52,9 @@ define dso_local preserve_mostcc void @preserve_most() #0 {
5252
entry:
5353
ret void
5454
; CHECK-NOT: retq
55-
; CHECK: popq %rax
55+
; CHECK: popq %r11
5656
; CHECK-NEXT: lfence
57-
; CHECK-NEXT: jmpq *%rax
57+
; CHECK-NEXT: jmpq *%r11
5858
}
5959

6060
; Function Attrs: noinline nounwind optnone uwtable
@@ -63,9 +63,9 @@ define dso_local preserve_allcc void @preserve_all() #0 {
6363
entry:
6464
ret void
6565
; CHECK-NOT: retq
66-
; CHECK: popq %rax
66+
; CHECK: popq %r11
6767
; CHECK-NEXT: lfence
68-
; CHECK-NEXT: jmpq *%rax
68+
; CHECK-NEXT: jmpq *%r11
6969
}
7070

7171
define { i64, i128 } @ret_i64_i128() #0 {

llvm/test/CodeGen/X86/pr40289-64bit.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ define cc 92 < 9 x i64 > @clobber() {
66
ret < 9 x i64 > undef
77
; CHECK-LABEL: clobber:
88
; CHECK-NOT: popq %rsp
9-
; CHECK: addq $8, %rsp
9+
; CHECK: popq %rax
1010
}

llvm/test/CodeGen/X86/pr40289.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ define < 3 x i32 > @clobber() {
66
ret < 3 x i32 > undef
77
; CHECK-LABEL: clobber:
88
; CHECK-NOT: popl %esp
9-
; CHECK: addl $4, %esp
9+
; CHECK: popl %eax
1010
}

0 commit comments

Comments
 (0)