Skip to content

Commit 153e4b0

Browse files
committedMar 3, 2016
[X86] Enable forwarding bool arguments in tail calls (PR26305)
The code was previously not able to track a boolean argument at a call site back to the formal argument of the caller. Differential Revision: http://reviews.llvm.org/D17786 llvm-svn: 262575
1 parent 3178b80 commit 153e4b0

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
 

‎llvm/lib/Target/X86/X86ISelLowering.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -3645,6 +3645,26 @@ bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags,
36453645
MachineFrameInfo *MFI, const MachineRegisterInfo *MRI,
36463646
const X86InstrInfo *TII, const CCValAssign &VA) {
36473647
unsigned Bytes = Arg.getValueType().getSizeInBits() / 8;
3648+
3649+
for (;;) {
3650+
// Look through nodes that don't alter the bits of the incoming value.
3651+
unsigned Op = Arg.getOpcode();
3652+
if (Op == ISD::ZERO_EXTEND || Op == ISD::ANY_EXTEND || Op == ISD::BITCAST) {
3653+
Arg = Arg.getOperand(0);
3654+
continue;
3655+
}
3656+
if (Op == ISD::TRUNCATE) {
3657+
const SDValue &TruncInput = Arg.getOperand(0);
3658+
if (TruncInput.getOpcode() == ISD::AssertZext &&
3659+
cast<VTSDNode>(TruncInput.getOperand(1))->getVT() ==
3660+
Arg.getValueType()) {
3661+
Arg = TruncInput.getOperand(0);
3662+
continue;
3663+
}
3664+
}
3665+
break;
3666+
}
3667+
36483668
int FI = INT_MAX;
36493669
if (Arg.getOpcode() == ISD::CopyFromReg) {
36503670
unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg();
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: llc -mtriple=i686-unknown-linux-gnu -o - %s | FileCheck %s
2+
3+
declare void @g_bool(i1 zeroext)
4+
define void @f_bool(i1 zeroext %x) {
5+
entry:
6+
tail call void @g_bool(i1 zeroext %x)
7+
ret void
8+
9+
; Forwarding a bool in a tail call works.
10+
; CHECK-LABEL: f_bool:
11+
; CHECK-NOT: movz
12+
; CHECK: jmp g_bool
13+
}
14+
15+
16+
declare void @g_float(float)
17+
define void @f_i32(i32 %x) {
18+
entry:
19+
%0 = bitcast i32 %x to float
20+
tail call void @g_float(float %0)
21+
ret void
22+
23+
; Forwarding a bitcasted value works too.
24+
; CHECK-LABEL: f_i32
25+
; CHECK-NOT: mov
26+
; CHECK: jmp g_float
27+
}

0 commit comments

Comments
 (0)
Please sign in to comment.