Skip to content

Commit e3f42b0

Browse files
authored
[RISCV] Expand PseudoTAIL with t2 instead of t1 for Zicfilp. (#89014)
PseudoTail should be a software guarded branch in Ziciflp, since its branch target is known in link time. JALR/C.JR/C.JALR with rs1 as t2 is termed a software guarded branch. Such branches do not need to land on a lpad instruction. ABI Change PR: riscv-non-isa/riscv-asm-manual#93
1 parent b86e099 commit e3f42b0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ void RISCVMCCodeEmitter::expandFunctionCall(const MCInst &MI,
126126
if (MI.getOpcode() == RISCV::PseudoTAIL) {
127127
Func = MI.getOperand(0);
128128
Ra = RISCV::X6;
129+
// For Zicfilp, PseudoTAIL should be expanded to a software guarded branch.
130+
// It means to use t2(x7) as rs1 of JALR to expand PseudoTAIL.
131+
if (STI.hasFeature(RISCV::FeatureStdExtZicfilp))
132+
Ra = RISCV::X7;
129133
} else if (MI.getOpcode() == RISCV::PseudoCALLReg) {
130134
Func = MI.getOperand(1);
131135
Ra = MI.getOperand(0).getReg();

llvm/test/MC/RISCV/tail-call.s

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,36 @@
1212
# RUN: llvm-mc -triple riscv64 < %s -show-encoding \
1313
# RUN: | FileCheck -check-prefix=FIXUP %s
1414

15+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-zicfilp < %s \
16+
# RUN: | llvm-objdump -d - | FileCheck --check-prefix=INSTR-ZICFILP %s
17+
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-zicfilp < %s \
18+
# RUN: | llvm-readobj -r - | FileCheck -check-prefix=RELOC %s
19+
# RUN: llvm-mc -triple riscv32 -mattr=+experimental-zicfilp < %s -show-encoding \
20+
# RUN: | FileCheck -check-prefix=FIXUP %s
21+
22+
# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zicfilp < %s \
23+
# RUN: | llvm-objdump -d - | FileCheck --check-prefix=INSTR-ZICFILP %s
24+
# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zicfilp < %s \
25+
# RUN: | llvm-readobj -r - | FileCheck -check-prefix=RELOC %s
26+
# RUN: llvm-mc -triple riscv64 -mattr=+experimental-zicfilp < %s -show-encoding \
27+
# RUN: | FileCheck -check-prefix=FIXUP %s
28+
1529
.long foo
1630

1731
tail foo
1832
# RELOC: R_RISCV_CALL_PLT foo 0x0
1933
# INSTR: auipc t1, 0
2034
# INSTR: jr t1
35+
# INSTR-ZICFILP: auipc t2, 0
36+
# INSTR-ZICFILP: jr t2
2137
# FIXUP: fixup A - offset: 0, value: foo, kind:
38+
2239
tail bar
2340
# RELOC: R_RISCV_CALL_PLT bar 0x0
2441
# INSTR: auipc t1, 0
2542
# INSTR: jr t1
43+
# INSTR-ZICFILP: auipc t2, 0
44+
# INSTR-ZICFILP: jr t2
2645
# FIXUP: fixup A - offset: 0, value: bar, kind:
2746

2847
# Ensure that tail calls to functions whose names coincide with register names
@@ -32,22 +51,30 @@ tail zero
3251
# RELOC: R_RISCV_CALL_PLT zero 0x0
3352
# INSTR: auipc t1, 0
3453
# INSTR: jr t1
54+
# INSTR-ZICFILP: auipc t2, 0
55+
# INSTR-ZICFILP: jr t2
3556
# FIXUP: fixup A - offset: 0, value: zero, kind:
3657

3758
tail f1
3859
# RELOC: R_RISCV_CALL_PLT f1 0x0
3960
# INSTR: auipc t1, 0
4061
# INSTR: jr t1
62+
# INSTR-ZICFILP: auipc t2, 0
63+
# INSTR-ZICFILP: jr t2
4164
# FIXUP: fixup A - offset: 0, value: f1, kind:
4265

4366
tail ra
4467
# RELOC: R_RISCV_CALL_PLT ra 0x0
4568
# INSTR: auipc t1, 0
4669
# INSTR: jr t1
70+
# INSTR-ZICFILP: auipc t2, 0
71+
# INSTR-ZICFILP: jr t2
4772
# FIXUP: fixup A - offset: 0, value: ra, kind:
4873

4974
tail foo@plt
5075
# RELOC: R_RISCV_CALL_PLT foo 0x0
5176
# INSTR: auipc t1, 0
5277
# INSTR: jr t1
78+
# INSTR-ZICFILP: auipc t2, 0
79+
# INSTR-ZICFILP: jr t2
5380
# FIXUP: fixup A - offset: 0, value: foo, kind: fixup_riscv_call_plt

0 commit comments

Comments
 (0)