Skip to content

Commit b0f11df

Browse files
authored
[RISCV] Add call preserved regmask to tail calls. (#122181)
Every call should have regmask operand to indicate what registers are preserved or clobbered by the call. VirtRegRewriter uses this to tell MachineRegisterInfo what registers are clobbered by a function. If the mask isn't present the registers potentially clobbered by a tail called function aren't counted. I have checked ARM, AArch64, and X86 and they all have a regmask operand on their tail calls. I believe this fixes an issue I'm seeing with IPRA.
1 parent b48b99f commit b0f11df

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20273,13 +20273,11 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI,
2027320273
for (auto &Reg : RegsToPass)
2027420274
Ops.push_back(DAG.getRegister(Reg.first, Reg.second.getValueType()));
2027520275

20276-
if (!IsTailCall) {
20277-
// Add a register mask operand representing the call-preserved registers.
20278-
const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
20279-
const uint32_t *Mask = TRI->getCallPreservedMask(MF, CallConv);
20280-
assert(Mask && "Missing call preserved mask for calling convention");
20281-
Ops.push_back(DAG.getRegisterMask(Mask));
20282-
}
20276+
// Add a register mask operand representing the call-preserved registers.
20277+
const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
20278+
const uint32_t *Mask = TRI->getCallPreservedMask(MF, CallConv);
20279+
assert(Mask && "Missing call preserved mask for calling convention");
20280+
Ops.push_back(DAG.getRegisterMask(Mask));
2028320281

2028420282
// Glue the call to the argument copies, if any.
2028520283
if (Glue.getNode())

llvm/test/CodeGen/RISCV/kcfi-isel-mir.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define void @f2(ptr noundef %x) #0 {
2020
; CHECK-NEXT: liveins: $x10
2121
; CHECK-NEXT: {{ $}}
2222
; CHECK-NEXT: [[COPY:%[0-9]+]]:gprtc = COPY $x10
23-
; CHECK-NEXT: PseudoTAILIndirect [[COPY]], implicit $x2, cfi-type 12345678
23+
; CHECK-NEXT: PseudoTAILIndirect [[COPY]], csr_ilp32_lp64, implicit $x2, cfi-type 12345678
2424
tail call void %x() [ "kcfi"(i32 12345678) ]
2525
ret void
2626
}

llvm/test/CodeGen/RISCV/kcfi-mir.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ define void @f2(ptr noundef %x) #0 {
3030
; CHECK-NEXT: {{ $}}
3131
; CHECK-NEXT: BUNDLE implicit-def $x6, implicit-def $x6_w, implicit-def $x6_h, implicit-def $x7, implicit-def $x7_w, implicit-def $x7_h, implicit-def $x28, implicit-def $x28_w, implicit-def $x28_h, implicit-def $x29, implicit-def $x29_w, implicit-def $x29_h, implicit-def $x30, implicit-def $x30_w, implicit-def $x30_h, implicit-def $x31, implicit-def $x31_w, implicit-def $x31_h, implicit killed $x10, implicit $x2 {
3232
; CHECK-NEXT: KCFI_CHECK $x10, 12345678, implicit-def $x6, implicit-def $x7, implicit-def $x28, implicit-def $x29, implicit-def $x30, implicit-def $x31
33-
; CHECK-NEXT: PseudoTAILIndirect killed $x10, implicit $x2
33+
; CHECK-NEXT: PseudoTAILIndirect killed $x10, csr_ilp32_lp64, implicit $x2
3434
; CHECK-NEXT: }
3535
tail call void %x() [ "kcfi"(i32 12345678) ]
3636
ret void

0 commit comments

Comments
 (0)