Skip to content

Commit 4b99eb2

Browse files
authored
[Sparc] Remove bogus stack adjustment for LD/GD TLS (llvm#149890)
This argument is the number of bytes to adjust the stack by for the duration of the call. In most cases, PEI is able to eliminate the corresponding call frame pseudos, folding them into the initial stack frame allocation (rounded up to stack alignment), where it just ends up allocating more space than needed. However, in the rare case where this cannot be done, e.g. due to the use of a dynamic alloca, the 1 byte stack adjustment persists and results in a misaligned stack for the duration of the call. This has been the case ever since TLS support was added in cb1dca6 ("[Sparc] Add support for TLS in sparc."), and I can only assume that 1 was used erroneously thinking that it is the number of arguments (as there is 1 register argument for the call), not the number of bytes for on-stack arguments. Fixes: llvm#149808
1 parent dd36a69 commit 4b99eb2

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

llvm/lib/Target/Sparc/SparcISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,7 +2201,7 @@ SDValue SparcTargetLowering::LowerGlobalTLSAddress(SDValue Op,
22012201
SDValue Chain = DAG.getEntryNode();
22022202
SDValue InGlue;
22032203

2204-
Chain = DAG.getCALLSEQ_START(Chain, 1, 0, DL);
2204+
Chain = DAG.getCALLSEQ_START(Chain, 0, 0, DL);
22052205
Chain = DAG.getCopyToReg(Chain, DL, SP::O0, Argument, InGlue);
22062206
InGlue = Chain.getValue(1);
22072207
SDValue Callee = DAG.getTargetExternalSymbol("__tls_get_addr", PtrVT);
@@ -2219,7 +2219,7 @@ SDValue SparcTargetLowering::LowerGlobalTLSAddress(SDValue Op,
22192219
InGlue};
22202220
Chain = DAG.getNode(SPISD::TLS_CALL, DL, NodeTys, Ops);
22212221
InGlue = Chain.getValue(1);
2222-
Chain = DAG.getCALLSEQ_END(Chain, 1, 0, InGlue, DL);
2222+
Chain = DAG.getCALLSEQ_END(Chain, 0, 0, InGlue, DL);
22232223
InGlue = Chain.getValue(1);
22242224
SDValue Ret = DAG.getCopyFromReg(Chain, DL, SP::O0, PtrVT, InGlue);
22252225

llvm/test/CodeGen/SPARC/tls-sp.ll

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
; RUN: llc -mtriple=sparc -relocation-model=pic < %s | FileCheck --check-prefix=SPARC %s
33
; RUN: llc -mtriple=sparc64 -relocation-model=pic < %s | FileCheck --check-prefix=SPARC64 %s
44

5-
;; TODO: Fix the code generation for these functions.
6-
75
@x = external thread_local global i8
86

97
;; Test that we don't over-allocate stack space when calling __tls_get_addr
@@ -29,7 +27,7 @@ define ptr @no_alloca() nounwind {
2927
;
3028
; SPARC64-LABEL: no_alloca:
3129
; SPARC64: ! %bb.0: ! %entry
32-
; SPARC64-NEXT: save %sp, -144, %sp
30+
; SPARC64-NEXT: save %sp, -128, %sp
3331
; SPARC64-NEXT: .Ltmp0:
3432
; SPARC64-NEXT: rd %pc, %o7
3533
; SPARC64-NEXT: .Ltmp2:
@@ -62,13 +60,11 @@ define ptr @dynamic_alloca(i64 %n) nounwind {
6260
; SPARC-NEXT: .Ltmp4:
6361
; SPARC-NEXT: or %i0, %lo(_GLOBAL_OFFSET_TABLE_+(.Ltmp4-.Ltmp3)), %i0
6462
; SPARC-NEXT: add %i0, %o7, %i0
65-
; SPARC-NEXT: add %sp, -1, %sp
6663
; SPARC-NEXT: sethi %tgd_hi22(x), %i2
6764
; SPARC-NEXT: add %i2, %tgd_lo10(x), %i2
6865
; SPARC-NEXT: add %i0, %i2, %o0, %tgd_add(x)
6966
; SPARC-NEXT: call __tls_get_addr, %tgd_call(x)
7067
; SPARC-NEXT: nop
71-
; SPARC-NEXT: add %sp, 1, %sp
7268
; SPARC-NEXT: add %i1, 7, %i0
7369
; SPARC-NEXT: and %i0, -8, %i0
7470
; SPARC-NEXT: sub %sp, %i0, %i0
@@ -88,13 +84,11 @@ define ptr @dynamic_alloca(i64 %n) nounwind {
8884
; SPARC64-NEXT: .Ltmp4:
8985
; SPARC64-NEXT: or %i1, %lo(_GLOBAL_OFFSET_TABLE_+(.Ltmp4-.Ltmp3)), %i1
9086
; SPARC64-NEXT: add %i1, %o7, %i1
91-
; SPARC64-NEXT: add %sp, -1, %sp
9287
; SPARC64-NEXT: sethi %tgd_hi22(x), %i2
9388
; SPARC64-NEXT: add %i2, %tgd_lo10(x), %i2
9489
; SPARC64-NEXT: add %i1, %i2, %o0, %tgd_add(x)
9590
; SPARC64-NEXT: call __tls_get_addr, %tgd_call(x)
9691
; SPARC64-NEXT: nop
97-
; SPARC64-NEXT: add %sp, 1, %sp
9892
; SPARC64-NEXT: add %i0, 15, %i0
9993
; SPARC64-NEXT: and %i0, -16, %i0
10094
; SPARC64-NEXT: sub %sp, %i0, %i0

0 commit comments

Comments
 (0)