Skip to content

Commit 2dccf11

Browse files
authored
[RISCV] Remove gp and tp from callee saved register lists. (llvm#76483)
This appears to match gcc behavior. Resolves https://discourse.llvm.org/t/risc-v-calling-convention-implementation-in-clang-tp-and-gp-registers/75757
1 parent e499ae5 commit 2dccf11

File tree

3 files changed

+42
-114
lines changed

3 files changed

+42
-114
lines changed

llvm/lib/Target/RISCV/RISCVCallingConv.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// RISCVISelLowering.cpp (CC_RISCV).
1515

1616
def CSR_ILP32_LP64
17-
: CalleeSavedRegs<(add X1, X3, X4, X8, X9, (sequence "X%u", 18, 27))>;
17+
: CalleeSavedRegs<(add X1, X8, X9, (sequence "X%u", 18, 27))>;
1818

1919
def CSR_ILP32F_LP64F
2020
: CalleeSavedRegs<(add CSR_ILP32_LP64,
@@ -29,7 +29,7 @@ def CSR_NoRegs : CalleeSavedRegs<(add)>;
2929

3030
// Interrupt handler needs to save/restore all registers that are used,
3131
// both Caller and Callee saved registers.
32-
def CSR_Interrupt : CalleeSavedRegs<(add X1, (sequence "X%u", 3, 31))>;
32+
def CSR_Interrupt : CalleeSavedRegs<(add X1, (sequence "X%u", 5, 31))>;
3333

3434
// Same as CSR_Interrupt, but including all 32-bit FP registers.
3535
def CSR_XLEN_F32_Interrupt: CalleeSavedRegs<(add CSR_Interrupt,

llvm/test/CodeGen/RISCV/inline-asm-abi-names.ll

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,18 @@ define i32 @explicit_register_sp(i32 %a) nounwind {
156156
define i32 @explicit_register_x3(i32 %a) nounwind {
157157
; RV32I-LABEL: explicit_register_x3:
158158
; RV32I: # %bb.0:
159-
; RV32I-NEXT: addi sp, sp, -16
160-
; RV32I-NEXT: sw gp, 12(sp) # 4-byte Folded Spill
161159
; RV32I-NEXT: mv gp, a0
162160
; RV32I-NEXT: #APP
163161
; RV32I-NEXT: addi a0, gp, 0
164162
; RV32I-NEXT: #NO_APP
165-
; RV32I-NEXT: lw gp, 12(sp) # 4-byte Folded Reload
166-
; RV32I-NEXT: addi sp, sp, 16
167163
; RV32I-NEXT: ret
168164
;
169165
; RV64I-LABEL: explicit_register_x3:
170166
; RV64I: # %bb.0:
171-
; RV64I-NEXT: addi sp, sp, -16
172-
; RV64I-NEXT: sd gp, 8(sp) # 8-byte Folded Spill
173167
; RV64I-NEXT: mv gp, a0
174168
; RV64I-NEXT: #APP
175169
; RV64I-NEXT: addi a0, gp, 0
176170
; RV64I-NEXT: #NO_APP
177-
; RV64I-NEXT: ld gp, 8(sp) # 8-byte Folded Reload
178-
; RV64I-NEXT: addi sp, sp, 16
179171
; RV64I-NEXT: ret
180172
%1 = tail call i32 asm "addi $0, $1, 0", "=r,{x3}"(i32 %a)
181173
ret i32 %1
@@ -185,26 +177,18 @@ define i32 @explicit_register_x3(i32 %a) nounwind {
185177
define i32 @explicit_register_gp(i32 %a) nounwind {
186178
; RV32I-LABEL: explicit_register_gp:
187179
; RV32I: # %bb.0:
188-
; RV32I-NEXT: addi sp, sp, -16
189-
; RV32I-NEXT: sw gp, 12(sp) # 4-byte Folded Spill
190180
; RV32I-NEXT: mv gp, a0
191181
; RV32I-NEXT: #APP
192182
; RV32I-NEXT: addi a0, gp, 0
193183
; RV32I-NEXT: #NO_APP
194-
; RV32I-NEXT: lw gp, 12(sp) # 4-byte Folded Reload
195-
; RV32I-NEXT: addi sp, sp, 16
196184
; RV32I-NEXT: ret
197185
;
198186
; RV64I-LABEL: explicit_register_gp:
199187
; RV64I: # %bb.0:
200-
; RV64I-NEXT: addi sp, sp, -16
201-
; RV64I-NEXT: sd gp, 8(sp) # 8-byte Folded Spill
202188
; RV64I-NEXT: mv gp, a0
203189
; RV64I-NEXT: #APP
204190
; RV64I-NEXT: addi a0, gp, 0
205191
; RV64I-NEXT: #NO_APP
206-
; RV64I-NEXT: ld gp, 8(sp) # 8-byte Folded Reload
207-
; RV64I-NEXT: addi sp, sp, 16
208192
; RV64I-NEXT: ret
209193
%1 = tail call i32 asm "addi $0, $1, 0", "=r,{gp}"(i32 %a)
210194
ret i32 %1
@@ -214,26 +198,18 @@ define i32 @explicit_register_gp(i32 %a) nounwind {
214198
define i32 @explicit_register_x4(i32 %a) nounwind {
215199
; RV32I-LABEL: explicit_register_x4:
216200
; RV32I: # %bb.0:
217-
; RV32I-NEXT: addi sp, sp, -16
218-
; RV32I-NEXT: sw tp, 12(sp) # 4-byte Folded Spill
219201
; RV32I-NEXT: mv tp, a0
220202
; RV32I-NEXT: #APP
221203
; RV32I-NEXT: addi a0, tp, 0
222204
; RV32I-NEXT: #NO_APP
223-
; RV32I-NEXT: lw tp, 12(sp) # 4-byte Folded Reload
224-
; RV32I-NEXT: addi sp, sp, 16
225205
; RV32I-NEXT: ret
226206
;
227207
; RV64I-LABEL: explicit_register_x4:
228208
; RV64I: # %bb.0:
229-
; RV64I-NEXT: addi sp, sp, -16
230-
; RV64I-NEXT: sd tp, 8(sp) # 8-byte Folded Spill
231209
; RV64I-NEXT: mv tp, a0
232210
; RV64I-NEXT: #APP
233211
; RV64I-NEXT: addi a0, tp, 0
234212
; RV64I-NEXT: #NO_APP
235-
; RV64I-NEXT: ld tp, 8(sp) # 8-byte Folded Reload
236-
; RV64I-NEXT: addi sp, sp, 16
237213
; RV64I-NEXT: ret
238214
%1 = tail call i32 asm "addi $0, $1, 0", "=r,{x4}"(i32 %a)
239215
ret i32 %1
@@ -243,26 +219,18 @@ define i32 @explicit_register_x4(i32 %a) nounwind {
243219
define i32 @explicit_register_tp(i32 %a) nounwind {
244220
; RV32I-LABEL: explicit_register_tp:
245221
; RV32I: # %bb.0:
246-
; RV32I-NEXT: addi sp, sp, -16
247-
; RV32I-NEXT: sw tp, 12(sp) # 4-byte Folded Spill
248222
; RV32I-NEXT: mv tp, a0
249223
; RV32I-NEXT: #APP
250224
; RV32I-NEXT: addi a0, tp, 0
251225
; RV32I-NEXT: #NO_APP
252-
; RV32I-NEXT: lw tp, 12(sp) # 4-byte Folded Reload
253-
; RV32I-NEXT: addi sp, sp, 16
254226
; RV32I-NEXT: ret
255227
;
256228
; RV64I-LABEL: explicit_register_tp:
257229
; RV64I: # %bb.0:
258-
; RV64I-NEXT: addi sp, sp, -16
259-
; RV64I-NEXT: sd tp, 8(sp) # 8-byte Folded Spill
260230
; RV64I-NEXT: mv tp, a0
261231
; RV64I-NEXT: #APP
262232
; RV64I-NEXT: addi a0, tp, 0
263233
; RV64I-NEXT: #NO_APP
264-
; RV64I-NEXT: ld tp, 8(sp) # 8-byte Folded Reload
265-
; RV64I-NEXT: addi sp, sp, 16
266234
; RV64I-NEXT: ret
267235
%1 = tail call i32 asm "addi $0, $1, 0", "=r,{tp}"(i32 %a)
268236
ret i32 %1

0 commit comments

Comments
 (0)