xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/tail-call-legality.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=x86 -o - < %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; This used to be classified as a tail call because of a mismatch in the
4*9880d681SAndroid Build Coastguard Worker; arguments seen by Analysis.cpp and ISelLowering. As seen by ISelLowering, they
5*9880d681SAndroid Build Coastguard Worker; both return {i32, i32, i32} (since i64 is illegal) which is fine for a tail
6*9880d681SAndroid Build Coastguard Worker; call.
7*9880d681SAndroid Build Coastguard Worker
8*9880d681SAndroid Build Coastguard Worker; As seen by Analysis.cpp: i64 -> i32 is a valid trunc, second i32 passes
9*9880d681SAndroid Build Coastguard Worker; straight through and the third is undef, also OK for a tail call.
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker; Analysis.cpp was wrong.
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Worker; FIXME: in principle we *could* support some tail calls involving truncations
14*9880d681SAndroid Build Coastguard Worker; of illegal types: a single "trunc i64 %whatever to i32" is probably valid
15*9880d681SAndroid Build Coastguard Worker; because of how the extra registers are laid out.
16*9880d681SAndroid Build Coastguard Worker
17*9880d681SAndroid Build Coastguard Workerdeclare {i64, i32} @test()
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Workerdefine {i32, i32, i32} @test_pair_notail(i64 %in) {
20*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test_pair_notail
21*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: jmp
22*9880d681SAndroid Build Coastguard Worker
23*9880d681SAndroid Build Coastguard Worker  %whole = tail call {i64, i32} @test()
24*9880d681SAndroid Build Coastguard Worker  %first = extractvalue {i64, i32} %whole, 0
25*9880d681SAndroid Build Coastguard Worker  %first.trunc = trunc i64 %first to i32
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Worker  %second = extractvalue {i64, i32} %whole, 1
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker  %tmp = insertvalue {i32, i32, i32} undef, i32 %first.trunc, 0
30*9880d681SAndroid Build Coastguard Worker  %res = insertvalue {i32, i32, i32} %tmp, i32 %second, 1
31*9880d681SAndroid Build Coastguard Worker  ret {i32, i32, i32} %res
32*9880d681SAndroid Build Coastguard Worker}
33