Skip to content

Commit 4913eea

Browse files
committed
fixes
1 parent 0d00d2b commit 4913eea

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,12 @@ static bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq) {
890890
LD->getExtensionType() != ISD::NON_EXTLOAD)
891891
return false;
892892

893+
// If the load's outgoing chain has more than one use, we can't (currently)
894+
// move the load since we'd most likely create a loop. TODO: Maybe it could
895+
// work if moveBelowOrigChain() updated *all* the chain users.
896+
if (!Callee.getValue(1).hasOneUse())
897+
return false;
898+
893899
// Now let's find the callseq_start.
894900
while (HasCallSeq && Chain.getOpcode() != ISD::CALLSEQ_START) {
895901
if (!Chain.hasOneUse())
@@ -913,11 +919,13 @@ static bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq) {
913919
Callee.getValue(1).hasOneUse())
914920
return true;
915921

916-
// Look past CopyToReg's.
917-
if (Chain.getOperand(0).getOpcode() == ISD::CopyToReg) {
922+
// Look past CopyToRegs. We only walk one path, so the chain mustn't branch.
923+
if (Chain.getOperand(0).getOpcode() == ISD::CopyToReg &&
924+
Chain.getOperand(0).getValue(0).hasOneUse()) {
918925
Chain = Chain.getOperand(0);
919926
continue;
920927
}
928+
921929
return false;
922930
}
923931
}
@@ -1362,6 +1370,22 @@ void X86DAGToDAGISel::PreprocessISelDAG() {
13621370
(N->getOpcode() == X86ISD::TC_RETURN &&
13631371
(Subtarget->is64Bit() ||
13641372
!getTargetMachine().isPositionIndependent())))) {
1373+
1374+
if (N->getOpcode() == X86ISD::TC_RETURN) {
1375+
// There needs to be enough non-callee-saved GPRs available to compute
1376+
// the load address if folded into the tailcall. See how the
1377+
// X86tcret_6regs and X86tcret_1reg classes are used and defined.
1378+
unsigned NumRegs = 0;
1379+
for (unsigned I = 3, E = N->getNumOperands(); I != E; ++I) {
1380+
if (isa<RegisterSDNode>(N->getOperand(I)))
1381+
++NumRegs;
1382+
}
1383+
if (!Subtarget->is64Bit() && NumRegs > 1)
1384+
continue;
1385+
if (NumRegs > 6)
1386+
continue;
1387+
}
1388+
13651389
/// Also try moving call address load from outside callseq_start to just
13661390
/// before the call to allow it to be folded.
13671391
///
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
; RUN: llc < %s | FileCheck %s
2-
3-
target triple = "x86_64-unknown-linux-gnu"
1+
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s
42

53
; The callee address computation should get folded into the call.
64
; CHECK-LABEL: f:
75
; CHECK-NOT: mov
86
; CHECK: jmpq *(%rdi,%rsi,8)
9-
10-
define void @f(ptr %table, i64 %idx) {
7+
define void @f(ptr %table, i64 %idx, i64 %aux1, i64 %aux2, i64 %aux3) {
118
entry:
129
%arrayidx = getelementptr inbounds ptr, ptr %table, i64 %idx
1310
%funcptr = load ptr, ptr %arrayidx, align 8
14-
tail call void %funcptr(ptr %table, i64 %idx)
11+
tail call void %funcptr(ptr %table, i64 %idx, i64 %aux1, i64 %aux2, i64 %aux3)
1512
ret void
1613
}

0 commit comments

Comments
 (0)