Skip to content

Commit 2570e4b

Browse files
committed
Merging r360099:
------------------------------------------------------------------------ r360099 | efriedma | 2019-05-06 16:21:59 -0700 (Mon, 06 May 2019) | 26 lines [ARM] Glue register copies to tail calls. This generally follows what other targets do. I don't completely understand why the special case for tail calls existed in the first place; even when the code was committed in r105413, call lowering didn't work in the way described in the comments. Stack protector lowering breaks if the register copies are not glued to a tail call: we have to insert the stack protector check before the tail call, and we choose the location based on the assumption that all physical register dependencies of a tail call are adjacent to the tail call. (See FindSplitPointForStackProtector.) This is sort of fragile, but I don't see any reason to break that assumption. I'm guessing nobody has seen this before just because it's hard to convince the scheduler to actually schedule the code in a way that breaks; even without the glue, the only computation that could actually be scheduled after the register copies is the computation of the call address, and the scheduler usually prefers to schedule that before the copies anyway. Fixes https://bugs.llvm.org/show_bug.cgi?id=41417 Differential Revision: https://reviews.llvm.org/D60427 ------------------------------------------------------------------------ llvm-svn: 360793
1 parent 3f38b9e commit 2570e4b

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,32 +1984,10 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI,
19841984
// Build a sequence of copy-to-reg nodes chained together with token chain
19851985
// and flag operands which copy the outgoing args into the appropriate regs.
19861986
SDValue InFlag;
1987-
// Tail call byval lowering might overwrite argument registers so in case of
1988-
// tail call optimization the copies to registers are lowered later.
1989-
if (!isTailCall)
1990-
for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
1991-
Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
1992-
RegsToPass[i].second, InFlag);
1993-
InFlag = Chain.getValue(1);
1994-
}
1995-
1996-
// For tail calls lower the arguments to the 'real' stack slot.
1997-
if (isTailCall) {
1998-
// Force all the incoming stack arguments to be loaded from the stack
1999-
// before any new outgoing arguments are stored to the stack, because the
2000-
// outgoing stack slots may alias the incoming argument stack slots, and
2001-
// the alias isn't otherwise explicit. This is slightly more conservative
2002-
// than necessary, because it means that each store effectively depends
2003-
// on every argument instead of just those arguments it would clobber.
2004-
2005-
// Do not flag preceding copytoreg stuff together with the following stuff.
2006-
InFlag = SDValue();
2007-
for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
2008-
Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
2009-
RegsToPass[i].second, InFlag);
2010-
InFlag = Chain.getValue(1);
2011-
}
2012-
InFlag = SDValue();
1987+
for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
1988+
Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
1989+
RegsToPass[i].second, InFlag);
1990+
InFlag = Chain.getValue(1);
20131991
}
20141992

20151993
// If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: llc < %s | FileCheck %s
2+
target triple = "armv6kz-unknown-unknown-gnueabihf"
3+
4+
; Make sure this doesn't crash, and we actually emit a tail call.
5+
; Unfortunately, this test is sort of fragile... the original issue only
6+
; shows up if scheduling happens in a very specific order. But including
7+
; it anyway just to demonstrate the issue.
8+
; CHECK: pop {r4, lr}
9+
10+
@e = external local_unnamed_addr constant [0 x i32 (i32, i32)*], align 4
11+
12+
; Function Attrs: nounwind sspstrong
13+
define i32 @AVI_ChunkRead_p_chk(i32 %g) nounwind sspstrong "target-cpu"="arm1176jzf-s" {
14+
entry:
15+
%b = alloca i8, align 1
16+
%tobool = icmp eq i32 %g, 0
17+
br i1 %tobool, label %if.end, label %if.then
18+
19+
if.then: ; preds = %entry
20+
%add = add nsw i32 %g, 1
21+
%arrayidx = getelementptr inbounds [0 x i32 (i32, i32)*], [0 x i32 (i32, i32)*]* @e, i32 0, i32 %add
22+
%0 = load i32 (i32, i32)*, i32 (i32, i32)** %arrayidx, align 4
23+
%call = tail call i32 %0(i32 0, i32 0) #3
24+
br label %return
25+
26+
if.end: ; preds = %entry
27+
call void @c(i8* nonnull %b)
28+
br label %return
29+
30+
return: ; preds = %if.end, %if.then
31+
%retval.0 = phi i32 [ %call, %if.then ], [ 0, %if.end ]
32+
ret i32 %retval.0
33+
}
34+
35+
declare void @c(i8*)

0 commit comments

Comments
 (0)